跳到主要内容

v6.0.4 (2025-05-29)

<dependency>
<groupId>net.hasor</groupId>
<artifactId>dbvisitor</artifactId>
<version>6.0.4</version>
</dependency>

影响范围

  • 使用条件构造器执行查询

更新内容

  • [修复] 当映射中通过 selectTemplate 配置了语句模版并且使用条件构造器生成查询语句时没有指定 select 列的情况下,查询语句没有正确生成带有 selectTemplate 语句模版的 SQL。
  • [修复] OracleDialect 方言,支持 DuplicateKeyStrategy.Update,感谢 ooknight 的贡献。
  • [优化] 当使用条件构造器生成查询语句时使用了 group by 但未指定 select 时不在自动追加 group by 的语句,而是使用 * 号替代,虽然生成的语句可能无法用于数据库的执行,但可以在开发期间发现并解决它。这可以避免框架层面每次判断进而提升执行效率。

案例:

@Data
@Table("t_sample")
public class Sample {
@Column(name = "id", primary = true)
private Long id;
@Column(selectTemplate = "AsText(point)", // 会生成 select AsText(point) as point
insertTemplate = "GeomFromText(?)", // 会生成 insert ... values (GeomFromText(?))
setValueTemplate = "GeomFromText(?)",// 会生成 update ... set point = GeomFromText(?)
whereColTemplate = "AsText(point)" // 会生成 ... where AsText(point) = ?
)
private String point;
}
---
lambdaQuery.and(qb -> qb.eq(Sample::getPoint, "point(11,11)"))
.queryForList();
---
使用下列语句执行查询
SELECT id , AsText(point) point FROM point_table WHERE ( AsText(point) = ? )

延伸介绍

selectTemplate 是 dbVisitor 的一个特色功能,用于对象映射在操作数据库时的 SQL 语句生成, 例如,对带有 point 类型的 MySQL 表进行读写操作时可以利用语句模版特性在生成的语句中使用数据库 PointFromText、AsText 函数。 详细介绍可以查阅文档 语句模版