tkmybatis 文档
https://www.javadoc.io/static/tk.mybatis/mapper/3.4.1-beta/index.html?tk/mybatis/mapper/entity/Example.html
https://blog.csdn.net/sinat_38419207/article/details/82907387 常用
1.排序/去重/排除字段/选择字段
Example example = new Example(HySysTLogConfig.class);
example.orderBy(“modelName”);
example.setDistinct(true);
example.excludeProperties(“logId”,”operType”,”flag”,”ts”);
example.selectProperties(“a”,”b”,”c”);
example.createCriteria().andEqualTo(“modelName”,logQueryModel.getModelName());
return hySysTLogConfigDao.selectByExample(example);
/*
@author whm
@date 2021/12/23
/
public class SmWhServiceImpl
@Autowired<br /> private BaseDao<T> currentDao;
@Override<br /> public PageInfo<T> findLxPage(LxQueryModel queryModel, Class<T> modelClass) {<br /> //查询条件<br /> Example example = new Example(modelClass);<br /> Example.Criteria criteria = example.createCriteria();<br /> if(!StringUtil.isEmpty(queryModel.getLxCd())){<br /> criteria.andLike("lxCd", "%" + queryModel.getLxCd() + "%");<br /> }<br /> if(!StringUtil.isEmpty(queryModel.getLxNm())){<br /> criteria.andLike("lxNm", "%" + queryModel.getLxNm() + "%");<br /> }
//分页信息<br /> int pageNumber = 1;<br /> if (!StringUtil.isEmpty(queryModel.getPage())) {<br /> pageNumber = queryModel.getPage();<br /> }<br /> int pageSize = 10;<br /> if (!StringUtil.isEmpty(queryModel.getLimit())) {<br /> pageSize = queryModel.getLimit();<br /> }
//排序<br /> if(!StringUtil.isEmpty(queryModel.getOrderPart())){<br /> example.setOrderByClause(queryModel.getOrderPart());<br /> }else{<br /> example.setOrderByClause("id asc");<br /> }
//查询返回<br /> PageHelper.startPage(pageNumber, pageSize);<br /> List<T> list = currentDao.selectByExample(example);<br /> return new PageInfo<T>(list);<br /> }
@Override<br /> public PageInfo<T> findInfoPage(InfoQueryModel queryModel, Class<T> modelClass) {<br /> //查询条件<br /> Example example = new Example(modelClass);<br /> Example.Criteria criteria = example.createCriteria();<br /> if(!StringUtil.isEmpty(queryModel.getSbCd())){<br /> criteria.andLike("sbCd", "%" + queryModel.getSbCd() + "%");<br /> }<br /> if(!StringUtil.isEmpty(queryModel.getSbNm())){<br /> criteria.andLike("sbNm", "%" + queryModel.getSbNm() + "%");<br /> }<br />
//分页信息<br /> int pageNumber = 1;<br /> if (!StringUtil.isEmpty(queryModel.getPage())) {<br /> pageNumber = queryModel.getPage();<br /> }<br /> int pageSize = 10;<br /> if (!StringUtil.isEmpty(queryModel.getLimit())) {<br /> pageSize = queryModel.getLimit();<br /> }
//排序<br /> if(!StringUtil.isEmpty(queryModel.getOrderPart())){<br /> example.setOrderByClause(queryModel.getOrderPart());<br /> }else{<br /> example.setOrderByClause("id asc");<br /> }
//查询返回<br /> PageHelper.startPage(pageNumber, pageSize);<br /> List<T> list = currentDao.selectByExample(example);<br /> return new PageInfo<T>(list);<br /> }
}
3.getByPrimaryKey,检索字段太多 existsWithPrimaryKey 好一点