crane4j
crane4j copied to clipboard
提供 `@AssembleDB` 注解,支持基于自定义 SQL 的数据源容器
提供 Jdbc 扩展,支持基于自定义 SQL 的数据源容器,比如:
public class Foo {
@AssembleQuery(
selects = {"user_name", "user_age"}, where = "id", from = "user", // 可以构建查询 SQL,直接基于 PrepareStatement 查询
datasource = "default_ds", // 可以选择数据源
props = {
@Mapping(src = "user_name", ref = "name"),
@Mapping(src = "user_age", ref = "age")
}
)
private Integer id;
private String name;
private String age;
}
上述配置等同于 select user_name, user_age where id in ?
,查询后总是返回一个 List<Map<String, Object>>
集合。
最好也可以直接支持一下参数化 SQL,比如:
public class Foo {
@AssembleQuery(
sql = "select user_name, user_age where id in :keys", // keys 是默认的键字段值,即 id 集合
props = {
@Mapping(src = "user_name", ref = "name"),
@Mapping(src = "user_age", ref = "age")
}
)
private Integer id;
private String name;
private String age;
}