下面要给大家介绍到的就是和mybatisplus相关的内容,那么它的分页应该怎样做呢?具体的代码实现方式是怎样的?
1、简单单表分页
代码:
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; }
2、多表查询分页
代码:
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;
Store-数据库实体
StoreQueryRequest-请求参数对象
StoreItemVO-自定义对象
关于mybatisplus分页就给你介绍到这里了,以上代码仅供参考,希望可以对你有所帮助。更多java编程常见问题,请继续关注奇Q工具网来了解吧。
推荐阅读: