mybatis plus分页实现总结

匿名 (未验证) 提交于 2019-12-03 00:09:02

Store为数据库实体
StoreQueryRequest 为请求参数对象

StoreItemVO 为自定义对象

简单单表分页

public interface StoreService {     IPage<Store> query(StoreQueryRequest param); }

 

StoreServiceImpl @Override public IPage<Store> query(StoreQueryRequest param) {     Page<Store> page = new Page<>(param.getPageIndex(), param.getPageSize());          QueryWrapper<Store> qw = new QueryWrapper<>();     qw.eq("store_id", param.getStoreId);          return storeMapper.selectPage(page, qw); }

 

StoreController @GetMapping(value = "/query") public IPage<Store> query(StoreQueryRequest param) {     IPage<Store> iPage = storeService.query(param);     return iPage; }

 

多表查询分页

StoreMapper public interface StoreMapper extends BaseMapper<Store> {     List<StoreItemVO> query(IPage<StoreItemVO> page, @Param("param") StoreQueryRequest param); }

 

StoreMapper.xml <select id="query" parameterType="com.demo.model.StoreQueryRequest" resultType="com.demo.model.StoreItemVO">     SELECT     *     FROM     t_store     <where>         <if test="param.storeId != null">             and id = #{param.storeId}         </if>     </where> </select>

 

StoreService public interface StoreService extends IService<Store> {     IPage<StoreItemVO> query(StoreQueryRequest param); }

 

StoreServiceImpl public class StoreServiceImpl extends ServiceImpl<StoreMapper, Store> implements StoreService {     @Autowired     private StoreMapper StoreMapper;      @Override     public IPage<StoreItemVO> query(StoreQueryRequest param) {         IPage<StoreItemVO> iPage = new Page<>(param.getPageIndex(), param.getPageSize());         List<StoreItemVO> list = StoreMapper.query(iPage, param);         iPage.setRecords(list);         return iPage;     } }

 

StoreController @GetMapping(value = "/query") public IPage<StoreItemVO query(StoreQueryRequest param) {     IPage<StoreItemVO> iPage = StoreService.query(param);     return iPage; }

 

以上ipage和page引用的包

import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!