zoukankan      html  css  js  c++  java
  • springboot整合pagehelper实现分页

    springboot整合pagehelper实现分页

     

    在pom.xml中添加依赖包

    		<dependency>
    			<groupId>com.github.pagehelper</groupId>
    			<artifactId>pagehelper-spring-boot-starter</artifactId>
    			<version>1.2.13</version>
    		</dependency>
    

    创建mapper

    package com.jeff.mapper;
    
    import java.util.List;
    
    import org.apache.ibatis.annotations.Mapper;
    import org.apache.ibatis.annotations.Param;
    import org.apache.ibatis.annotations.Select;
    
    import com.github.pagehelper.Page;
    import com.jeff.entity.User;
    
    @Mapper
    public interface UserMapper {
    	
    	@Select("select * from sys_user where id=#{id}")
        User getUserById(@Param("id") Long id);
    
    	@Select("select * from sys_user")
    	List<User> getUserList();
    
    	@Select("select * from sys_user")
    	Page<User> getUserList2();
    
    }
    
    

    创建service

    package com.jeff.service;
    
    import java.util.List;
    
    import com.github.pagehelper.Page;
    import com.jeff.entity.User;
    
    public interface UserService {
    
    	User getUserById(Long id);
    
    	List<User> getUserList1();
    
    	Page<User> getUserList2();
    
    }
    
    

    创建serviceImpl

    package com.jeff.service.impl;
    
    import java.util.List;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    
    import com.github.pagehelper.Page;
    import com.jeff.entity.User;
    import com.jeff.mapper.UserMapper;
    import com.jeff.service.UserService;
    
    @Service
    public class UserServiceImpl implements UserService {
    	
    	@Autowired
    	private UserMapper mapper;
    
    	@Override
    	public User getUserById(Long id) {
    		
    		return mapper.getUserById(id);
    	}
    
    	@Override
    	public List<User> getUserList1() {
    		
    		return mapper.getUserList();
    	}
    
    	@Override
    	public Page<User> getUserList2() {
    		
    		return mapper.getUserList2();
    	}
    
    }
    
    

    创建controller

    package com.jeff.controller;
    
    import java.util.List;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    import com.github.pagehelper.Page;
    import com.github.pagehelper.PageHelper;
    import com.github.pagehelper.PageInfo;
    import com.jeff.entity.User;
    import com.jeff.entity.request.PageEntity;
    import com.jeff.service.UserService;
    
    @RestController
    @RequestMapping("user")
    public class UserController {
    
    	@Autowired
    	private UserService service;
    
    	@RequestMapping("getUserById")
    	public User getUserById(Long id) {
    
    		return service.getUserById(id);
    	}
    
    	/**
    	 * 
    	 * @description: 分页查询方法一
    	 * @author: Jeff
    	 * @date: 2020年3月14日
    	 * @param page
    	 * @return
    	 */
    	@RequestMapping("getUserList1")
    	public Object getUserList1(PageEntity page) {
    		PageHelper.startPage(page.getPage(), page.getRows());
    		List<User> list = service.getUserList1();
    		PageInfo<User> pageInfo = new PageInfo<>(list);
    		return pageInfo;
    	}
    
    	/**
    	 * 
    	 * @description: 分页查询方法二
    	 * @author: Jeff
    	 * @date: 2020年3月14日
    	 * @param page
    	 * @return
    	 */
    	@RequestMapping("getUserList2")
    	public Object getUserList2(PageEntity page) {
    		PageHelper.startPage(page.getPage(), page.getRows());
    		Page<User> list = service.getUserList2();
    		return list;
    	}
    
    }
  • 相关阅读:
    oracle-RAC修改服务器ip
    windows下安装sphinx-3.1.1
    linux下安装sphinx-for-chinese 支持中文全文索引
    TP通过sphinxapi接口实现全文搜索
    oracle常用公式
    查看TR请求内所有对象信息
    请求释放后如何取消释放
    S4 TO HANA 升级 比对升级过程中的程序变更 TR
    S4,执行外币评估(FAGL_FCV)后,对原因代码的替代不生效
    OVAH 由原提示消息改成报错 SO
  • 原文地址:https://www.cnblogs.com/telwanggs/p/13094898.html
Copyright © 2011-2022 走看看