MybatisPlus实现分页

 

配置分页插件

@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>

 

上一篇:微信的OAuth2.0的接口配置信息修改部署Nginx


下一篇:JavaWeb宿舍管理系统(附 演示、源码下载地址)