配置分页插件
@Configuration public class MybatisPlusConfig { /** * 分页插件 */ @Bean public PaginationInterceptor paginationInterceptor() { return new PaginationInterceptor(); } }
Controller层:
@RequestMapping("/getProjectList")
@ResponseBody public Page getProjectList(HttpServletRequest request) { int offset = Integer.parseInt(request.getParameter("offset")); int limit = Integer.parseInt(request.getParameter("limit")); String yearStr = request.getParameter("year"); Integer year = null; if(yearStr!=null){ year = Integer.parseInt(request.getParameter("yearStr")); } QueryWrapper queryWrapper = new QueryWrapper(); Page page = new Page<>(offset / limit + 1, limit); Page projectWinInfoList = (Page) electricityDao.getAll(page,queryWrapper,year); return projectWinInfoList; }
Dao层:
@Mapper public interface ElectricityDao extends BaseMapper<EneElectricity> { IPage getAll (Page page, @Param(Constants.WRAPPER) Wrapper queryWrapper, @Param("year")Integer year); }
Mapper.xml:
<select id="getAll" resultType="java.util.HashMap"> select NUM,LIVE from ene_electricity <if test="year!=null and year!=''"> where year = #{year} </if> </select>