zoukankan      html  css  js  c++  java
  • mybatis的分页插件pagehelper的使用

    1.今天实验了mybatis的分页插件pagehelper的使用,感觉这个东西很方便,

    公司项目居然连mybatis-config.xml文件都没写,直接写了个中间xml然后在spring中通过improt引入的

    自己写了了mybatis-config.xml文件,中间xml文件已经配置了扫描包,所以

    只有pagehelper配置

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE configuration
    PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-config.dtd">
    <!-- 配置管理器 -->
    <configuration>
    <plugins>
    <!-- com.github.pagehelper为PageHelper类所在包名 -->
    <plugin interceptor="com.github.pagehelper.PageHelper">
    <!-- 设置数据库类型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库 -->
    <property name="dialect" value="mysql" />
    </plugin>
    </plugins>
    </configuration>

    在sqlSessionFactory中引入

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="mapperLocations" value="classpath:mapper/*.xml" />
    <property name="configLocation" value="classpath:mybatis-config.xml" /><!--引入mybatis-config.xml文件 -->
    <property name="typeAliasesPackage" value="com.heb.user.model" />
    </bean>

    然后在service的实现层写入一下代码

    PageHelper.startPage(page,count);
    List<ResellModel> resellList = numeralLoginDao.showAllResellInfos();

    PageInfo pageResult = new PageInfo<>(resellList);

    page和count是两个传入的参数

    pageResult就是得到的分页结果

    返回到页面信息有

    "firstPage":1,"prePage":0,"nextPage":2,"lastPage":2,"isFirstPage":true,"isLastPage":false,"hasPreviousPage":false,"hasNextPage":true,"navigatePages":8,"navigatepageNums":[1,2]}}

    可通过对应的信息取出你所需要的值

  • 相关阅读:
    .net framework v4.5.2
    sql数据库不允许保存更改和保存失败解决方法
    如何查看笔记本电脑型号
    Premiere 5.0/5 .5菜单详解
    Python编辑器英文菜单的中文翻译及解释
    SqlServer--常用数据查询
    pycharm上方菜单栏不见了如何恢复
    笔记本电脑的f1到f12怎么按
    C#的访问权限
    封装,继承和多态知识点汇总
  • 原文地址:https://www.cnblogs.com/1736gerr/p/6934642.html
Copyright © 2011-2022 走看看