【spring-boot】分页类使用
2021-01-28 22:13
标签:override not default enc get 实现 list pack dem pom.xml中 pageDTO.java UserService.java UserServiceImpl.java 实现类 UserController.java 访问地址:http://127.0.0.1:6066/user/list?page=1&limit=10 【spring-boot】分页类使用 标签:override not default enc get 实现 list pack dem 原文地址:https://www.cnblogs.com/wangkongming/p/12835312.html引入分页类
公共层 - 分页DTO
package com.example.pagehelperdemo.common;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
/**
* @author komiles@163.com
* @date 2020-04-30 18:54
*/
@Data
@AllArgsConstructor
public class PageDTO
服务层 - 用户服务类
package com.example.pagehelperdemo.service;
import com.example.pagehelperdemo.common.PageDTO;
import com.example.pagehelperdemo.dao.User;
/**
* @author komiles@163.com
* @date 2020-04-30 18:49
*/
public interface UserService {
User getOne(Integer id);
PageDTO
package com.example.pagehelperdemo.service.impl;
import com.example.pagehelperdemo.common.PageDTO;
import com.example.pagehelperdemo.dao.User;
import com.example.pagehelperdemo.dao.UserExample;
import com.example.pagehelperdemo.mapper.UserMapper;
import com.example.pagehelperdemo.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* @author komiles@163.com
* @date 2020-04-30 18:50
*/
@Service
public class UserServiceImpl implements UserService {
@Resource
private UserMapper userMapper;
@Override
public User getOne(Integer id) {
return userMapper.selectByPrimaryKey(id);
}
@Override
public PageDTO
用户层 - controller
package com.example.pagehelperdemo.controller;
import com.example.pagehelperdemo.common.PageDTO;
import com.example.pagehelperdemo.dao.User;
import com.example.pagehelperdemo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* @author komiles@163.com
* @date 2020-04-30 18:47
*/
@RequestMapping("/user")
@RestController
public class UserController {
@Autowired
private UserService userService;
@GetMapping("/one")
public User getOne(@RequestParam("id") Integer id){
return userService.getOne(id);
}
@GetMapping("/list")
public PageDTO
启动文件
文章标题:【spring-boot】分页类使用
文章链接:http://soscw.com/index.php/essay/48414.html