【Mybatis】【逆向工程】【Mapper】【Pagehelper】下的條件查詢加分頁

pom.xml如下:

<dependency>
      <groupId>com.github.pagehelper</groupId>
      <artifactId>pagehelper</artifactId>
      <version>5.0.0</version>
</dependency>
<!-- 會自動引入jsqlparser0.9.5 ,如果沒有,自己引入-->

mybatis插件配置:

<plugins>
		<plugin interceptor="com.github.pagehelper.PageInterceptor">
		<!--5.0以上不要配置這條-->
		<!--<property name="dialect" value="mysql"></property>-->
		</plugin>
</plugins>

然後代碼正常調用即可:

public EUDataGridResult getContentList(int page, int rows,long categoryId) {
        TbContentExample example=new TbContentExample();
        TbContentExample.Criteria criteria=example.createCriteria();
        criteria.andCategoryIdEqualTo(categoryId);
        PageHelper.startPage(page,rows);
        List<TbContent> list=contentMapper.selectByExample(example);
        EUDataGridResult result=new EUDataGridResult();
        result.setRows(list);
        PageInfo<TbContent> pageInfo=new PageInfo<>(list);
        result.setTotal(pageInfo.getTotal());
        return result;
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章