zoukankan      html  css  js  c++  java
  • SpringBoot集成MybatisPlus实现分页

    注意:如果数据库选择oracle,时间类型字段设置为timestamp而不是date类型时,这时用分页插件查询会报错,还没搞明白咋回事

    Pom依赖:

      <!--    mybatis-plus依赖-->
            <dependency>
                <groupId>com.baomidou</groupId>
                <artifactId>mybatis-plus-boot-starter</artifactId>
                <version>3.1.0</version>
            </dependency>

    配置分页插件:

    @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")); } Page page = new Page<>(offset / limit + 1, limit); Page projectWinInfoList = (Page) electricityDao.getAll(page,year); return projectWinInfoList; }

    Dao层:

    @Mapper
    public interface ElectricityDao extends BaseMapper<EneElectricity> {
        IPage getAll (Page page,@Param("year")Integer year);
    }

    Mapper.xml:注意resultType为HashMap时,返回的数据完全是查询的数据库字段,而不是实体类属性,二者有一些大小写,或者命名的差别。

      <select id="getAll" resultType="java.util.HashMap">
            select * from ene_electricity
            <if test="year!=null and year!=''">
                where  year = #{year}
            </if>
        </select>
  • 相关阅读:
    异常处理
    JPG转换成BMP不成功???
    Vmware 7 下装载的最新Ubuntu10.04镜像会出现无法识别键盘输入的解决方法
    动态IP获取
    最佳Web设计资源
    设置NFS
    Ubuntu设置root用户自动登录
    编译QT4.5
    tq2440修改默认串口不支持打印控制台
    英语作文
  • 原文地址:https://www.cnblogs.com/wanlige/p/14714041.html
Copyright © 2011-2022 走看看