外观
查询数据
查询一条数据
根据主键查询一条数据
java
Optional<User> user = Db.table(User.class)
.searcher()
.oneById(1);
根据条件查询一条数据
java
Optional<User> user = Db.table(User.class)
.searcher()
.select(sys_user.user_name, sys_user.name)
.where(sys_user.id.eq(1))
.one();
查询多条数据
根据主键查询多条数据
java
List<User> userList = Db.table(User.class)
.searcher()
.listByIds(1, 2, 3);
根据条件查询多条数据
java
List<User> userList = Db.table(User.class)
.searcher()
.select(sys_user.user_name, sys_user.age)
.where(sys_user.age.ge(18))
.orderBy(sys_user.age.asc())
.list();
查询单列数据
查询单条或列表
java
Optional<Object> userName = Db.table(User.class)
.searcher()
.select(sys_user.user_name)
.where(sys_user.id.eq(18))
.obj();
List<Object> userNameList = Db.table(User.class)
.searcher()
.select(sys_user.user_name)
.objList();
映射查询的数据
java
Optional<String> userName = Db.table(User.class)
.searcher()
.select(sys_user.user_name)
.where(sys_user.id.eq(18))
.obj(String.class);
List<String> userNameList = Db.table(User.class)
.searcher()
.select(sys_user.user_name)
.objList(String.class);
查询分页数据
java
Page<User> page = Db.table(User.class)
.searcher()
.select(sys_user.user_name, sys_user.age)
.where(sys_user.age.gt(18))
.orderBy(sys_user.age.desc())
.page(Page.of(1, 10)); // 第 1 页,每页 10 条数据
查询数据数量
java
// 根据条件查询数据数量
long count = Db.table(User.class)
.searcher()
.where(sys_user.age.gt(18))
.count();
// 根据条件查询数据是否存在
boolean exists = Db.table(User.class)
.searcher()
.where(sys_user.id.eq(1))
.exists();