一、加依賴:
1 <dependency> 2 <groupId>com.baomidou</groupId> 3 <artifactId>mybatis-plus</artifactId> 4 <version>${mybatis-plus.version}</version> 5 </dependency>
二、加配置:
1 <plugins> 2 <!-- 分頁查詢插件 --> 3 <plugin interceptor="com.baomidou.mybatisplus.plugins.PaginationInterceptor"> 4 <property name="dialectType" value="mysql" /> 5 </plugin> 6 </plugins>
三、controller使用:
1 @PostMapping("orderlist.api") 2 @ApiOperation(value = "分頁查詢", produces = MediaType.APPLICATION_JSON_VALUE) 3 public Object memberOrderlist(@RequestBody DriverDto dto, HttpServletRequest request, HttpServletResponse response) { 4 Page<BizOrderlist> page = new Page<BizOrderlist>(dto.getPage() == null ? 1 : dto.getPage() , dto.getPageSize() == null ? 15 : dto.getPageSize()); //初始化分頁條數,如果傳入的值為空在默認第一頁,15條。 5 Parameter orderparameter = new Parameter(getService(), "getOrderlist").setParam(page,params); //在servie中獲取list,傳遞分頁Page和查詢參數 6 Page<BizOrderlist> orderList = (Page<BizOrderlist>) provider.execute(orderparameter).getResult();
四、service中使用:
1 public Page<BizOrderlist> getOrderlist(Page<BizOrderlist> page,Map<String, Object> params) { 2 3 List<BizOrderlist> orderlist = (List<BizOrderlist>) ((OrderListMapper) mapper).getOrderList(page,param1,params2,params3); 4 page = page.setRecords(orderlist); //查出的list調用setRecords 5 return page;
五、Mapper:
1 public interface OrderListMapper extends BaseMapper<BizOrderlist> { 2 3 List<BizOrderlist> getOrderList(Pagination page,@Param("param1") Double param1...........);
