springboot Mybatis整合分页插件 PageHelper

pageHelper PageHelper 是一款好用的开源免费的 Mybatis 第三方物理分页插件 物理分页

com.github.pagehelper

pagehelper-spring-boot-starter

1.2.5

 

 

配置信息

spring.datasource.url=jdbc:mysql://localhost:3306/test

spring.datasource.username=root

spring.datasource.password=root

spring.datasource.driver-class-name=com.mysql.jdbc.Driver

 

 

logging.level.com.example.demo.dao=DEBUG

pagehelper.helperDialect=mysql

pagehelper.reasonable=true

pagehelper.supportMethodsArguments=true

pagehelper.params=count=countSql

pagehelper.page-size-zero=true

 

Entity层

@Data

public class User {

 

private Integer id;

private String name;

private Integer age;

}

Mapper层

 

public interface UserMapper1 {

 

@Insert("insert into user (name,age) values (#{name},#{age})")

public int save(@Param("name") String name,@Param("age") Integer age);

 

@Select("select * from user")

public List selectList();

}

 

package com.yanye.yanye.test1.service.impl;

 

 

import com.github.pagehelper.PageHelper;

import com.github.pagehelper.PageInfo;

import com.yanye.yanye.entity.User;

import com.yanye.yanye.test1.mapper.UserMapper1;

import com.yanye.yanye.test1.service.UserService1;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

 

import java.util.List;

 

@Service

public class UserService1Impl implements UserService1 {

@Autowired

private UserMapper1 userMapper1;

 

 

public int save(String name, Integer age) {

return userMapper1.save(name,age);

}

 

@Override

public PageInfo selectList(int page, int size) {

PageHelper.startPage(page, size);

List users = userMapper1.selectList();

PageInfo userList = new PageInfo<>(users);

return userList;

}

}

controller层

@RestController

public class IndexController {

@Autowired

private UserService userService;

 

@RequestMapping("/findUserList")

public PageInfo findUserList(int page, int size) {

return userService.findUserList(page, size);

}

 

}

返回结果

 

你可能感兴趣的:(springboot,java,mybaties,PageHelper)