在 spring-mybatis配置檔案中新增分頁查詢功能
阿新 • • 發佈:2018-11-14
先將包匯入
然後在resource下面新建mybatisConfig.xml檔案,內容如下:
然後再將該配置檔案整合到 spring-mybatis.xml檔案中,在 bean id="sqlSessionFactory" 下面增加 <property name="configLocation" value="classpath:mybatisConfig.xml"></property>
也可以使用sql語句在 .mapper檔案中實現分頁: 在語句末尾新增 limit page,count
<?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> <plugin interceptor="com.github.pagehelper.PageHelper"> <!-- 設定資料庫型別 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六種資料庫--> <property name="dialect" value="mysql"/> </plugin> </plugins> </configuration>
然後再將該配置檔案整合到 spring-mybatis.xml檔案中,在 bean id="sqlSessionFactory" 下面增加 <property name="configLocation" value="classpath:mybatisConfig.xml"></property>
也可以使用sql語句在 .mapper檔案中實現分頁: 在語句末尾新增 limit page,count