JEECG minidao如何封装自己的 多表联合查询 分页查询
JEECG确实是一款实实在在的促进生产力的工具好处我想看到此文章的人应该都有所体会了
言归正传 JEECG框架自带的查询确实很省事,但是多表联合查询 分页查询 是我们开发业务系统当中不可避免的这时框架显得有点不太靠得住了 那我们就自己动手丰衣足食
使用minidao封装自己得查询sql吧
Controller
MiniDaoPage<PersonEntity> rlt = this.personService.getpersonInfo(personModel, dataGrid);
ServiceImpl.java
@Override public MiniDaoPage<PersonEntity> getPersonInfo(PersonEntity personModel, DataGrid dataGrid) throws Exception { int page = 0; int queryPage = (dataGrid.getPage() - 1) * dataGrid.getRows(); int rows = dataGrid.getRows(); MiniDaoPage<PersonEntity> rlt = new MiniDaoPage<PersonEntity>(); rlt.setPage(dataGrid.getPage()); rlt.setRows(dataGrid.getRows()); rlt.setTotal(PersonDao.getPersonPageCount(personModel)); rlt.setResults(PersonDao.getPersonInfo(personModel, queryPage, page, rows)); return rlt; }
PersonDao
@Arguments({"personModel", "queryPage", "page", "rows"}) @ResultType(PersonEntity.class) public List<PersonEntity> getPersonInfo(@Param("personModel") PersonEntity personModel, @Param("queryPage") int queryPage,@Param("page") int page, @Param("rows") int rows);
sql
select * from person where 1=1 <#if personModel.name? exists &&personModel.name ?length gt 0> and name like CONCAT('%', :personModel.name,'%') </#if> order by name limit :queryPage, :rows