當(dāng)前位置:
首頁(yè) >
前端技术
> javascript
>内容正文
javascript
SpringBoot 2.x 整合Mybatis二:PageHelper分页
生活随笔
收集整理的這篇文章主要介紹了
SpringBoot 2.x 整合Mybatis二:PageHelper分页
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
轉(zhuǎn)載請(qǐng)標(biāo)明出處:http://blog.csdn.net/zhaoyanjun6/article/details/80696898
本文出自【趙彥軍的博客】
Mybatis-PageHelper 簡(jiǎn)介
PageHelper 最方便使用的分頁(yè)插件,支持多種數(shù)據(jù)庫(kù):
Oracle Mysql MariaDB SQLite Hsqldb PostgreSQL DB2 SqlServer(2005,2008) Informix H2 SqlServer2012 Derby PhoenixGitHub: https://github.com/pagehelper/Mybatis-PageHelper
依賴添加
buildscript {ext {springBootVersion = '2.0.2.RELEASE'}repositories {mavenCentral()}dependencies {classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")} }apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management'group = 'com.yanjun' version = '0.0.1-SNAPSHOT' sourceCompatibility = 1.8repositories {mavenCentral() }dependencies {compile('org.springframework.boot:spring-boot-starter','org.springframework.boot:spring-boot-starter-web',)testCompile('org.springframework.boot:spring-boot-starter-test')runtime('mysql:mysql-connector-java') //mysql驅(qū)動(dòng)compile 'org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.0'compile 'com.github.pagehelper:pagehelper-spring-boot-starter:1.2.3' //pagehelper }配置文件 application.yml
spring:datasource:url: jdbc:mysql://127.0.0.1:3306/mybatisusername: rootpassword: 123456driver-class-name: com.mysql.jdbc.Driversql-script-encoding: UTF-8pagehelper:helperDialect: mysqlreasonable: truesupportMethodsArguments: trueparams: count=countSqlserver:port: 8023實(shí)戰(zhàn)演練
創(chuàng)建實(shí)體類 User
public class User {Integer id;String name;Integer age;public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public Integer getAge() {return age;}public void setAge(Integer age) {this.age = age;} }創(chuàng)建 Mapper 類 UserMapper
public interface UserMapper {@Select("select * from user")List<User> findAll(); }創(chuàng)建 service 類 UserService
@Service public class UserService {@AutowiredUserMapper userMapper;public PageInfo findAll(int pageNum, int pageSize) {PageHelper.startPage(pageNum, pageSize);List<User> userList = userMapper.findAll();PageInfo<User> pageInfo = new PageInfo<>(userList);return pageInfo;} }創(chuàng)建 controller 類 UserController
@RestController public class UserController {@AutowiredUserService userService;@GetMapping("findAll")public PageInfo getUser(int pageNum, int pageSize) {return userService.findAll(pageNum,pageSize);} }添加掃包注解
@SpringBootApplication @MapperScan("com.yanjun.mybatis.mapper")public class MybatisApplication {public static void main(String[] args) {SpringApplication.run(MybatisApplication.class, args);} }效果測(cè)試
總結(jié)
本文所有代碼已經(jīng)上傳至 GitHub ,分支 PageHelper
地址: https://github.com/zyj1609wz/SpringBootMybatis
個(gè)人微信號(hào):zhaoyanjun125 , 歡迎關(guān)注
總結(jié)
以上是生活随笔為你收集整理的SpringBoot 2.x 整合Mybatis二:PageHelper分页的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: SpringBoot 2.x 整合Myb
- 下一篇: SpringBoot 2.x 整合Myb