共计 701 个字符,预计需要花费 2 分钟才能阅读完成。
- 需求: 查询全部记录, 并按
original_order
字段倒序排列
Java 代码:
@Test
public void selectAllTest() {dao = (TApprovalDAO) applicationContext.getBean("TApprovalDAO");
TApprovalExample example = new TApprovalExample();
// 按 `original_order` 字段倒序排列
example.setOrderByClause("original_order desc");
// 是否去重, 假为不去重, 真为去重
example.setDistinct(false);
// 构造自定义查询准则,Criteria: 准则, 原则, 标准
Criteria criteria = example.createCriteria();
// 主键非空
criteria.andIdIsNotNull();
List<TApproval> list = dao.selectByExample(example);
for (TApproval tApproval : list) {System.err.println(tApproval);
}
}
无报错, 输出全部记录列表.
看看 log4j 在控制台打印的 SQL 语句:
Preparing: select id, department_number, approvals_time, reply_opinion, original_order, auditor, approve_operates from t_approval WHERE (id is not null) order by original_order desc
正文完
发表至: java
2019-11-03