SpringBoot+Mybatis+Pagehelper实现简单的分页查询

刚刚写博客小萌新,写的不好轻喷
springboot+mybatis的配置我就不展示了直接从分页插件的使用开始

全是文字加图片hhhh

1.配置pom依赖(主要导入Pagehelper依赖)

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

2.实体类(可以使用lombok简化代码)

public class Rwa_material implements Serializable {

    private Integer id;

    private String productName;

    private String specifications;

    private String model;

    private String type;

    private String number;

    private String batchNumber;

    private String purpose;

    private String inputNumber;

    private Date inputDate;

    private String inboundBatchNumber;

    private String warehouser;

    private String storekeeper;

    private Integer status;


    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getProductName() {
        return productName;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }

    public String getSpecifications() {
        return specifications;
    }

    public void setSpecifications(String specifications) {
        this.specifications = specifications == null ? null : specifications.trim();
    }

    public String getModel() {
        return model;
    }

    public void setModel(String model) {
        this.model = model == null ? null : model.trim();
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type == null ? null : type.trim();
    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number == null ? null : number.trim();
    }




    public String getPurpose() {
        return purpose;
    }


    public void setPurpose(String purpose) {
        this.purpose = purpose == null ? null : purpose.trim();
    }


    public String getBatchNumber() {
        return batchNumber;
    }

    public void setBatchNumber(String batchNumber) {
        this.batchNumber = batchNumber;
    }

    public String getInputNumber() {
        return inputNumber;
    }

    public void setInputNumber(String inputNumber) {
        this.inputNumber = inputNumber;
    }

    public Date getInputDate() {
        return inputDate;
    }

    public void setInputDate(Date inputDate) {
        this.inputDate = inputDate;
    }

    public String getInboundBatchNumber() {
        return inboundBatchNumber;
    }

    public void setInboundBatchNumber(String inboundBatchNumber) {
        this.inboundBatchNumber = inboundBatchNumber;
    }

    public String getWarehouser() {
        return warehouser;
    }

    public void setWarehouser(String warehouser) {
        this.warehouser = warehouser == null ? null : warehouser.trim();
    }

    public String getStorekeeper() {
        return storekeeper;
    }

    public void setStorekeeper(String storekeeper) {
        this.storekeeper = storekeeper == null ? null : storekeeper.trim();
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }
}

3.controller层(个人习惯喜欢从controller开始)


@Controller
@RequestMapping("/rwamaterial")
public class Rwa_MaterialController {

    @Autowired
    Rwa_MaterialService rwa_materialService;
    
```//    分页查询
    @ResponseBody
    @RequestMapping("findAll")
    public PageInfo<Rwa_material> findAll(int page, int pageSize){

        return  rwa_materialService.findAll(page,pageSize);
    }
    
}

4.Service层(我直接写的impl)

@Service
public class Rwa_MaterialService {

  @Autowired
    Rwa_materialMapper rwa_materialMapper;
    
    public PageInfo<Rwa_material> findAll(int page,int pageSize) {
        PageHelper.startPage(page, pageSize);//改写语句实现分页查询
        List<Rwa_material> all = rwa_materialMapper.findAll();
        PageInfo<Rwa_material> info = new PageInfo<>(all);
        return info;
    }
  }

最后就是dao层啦

5.Dao层

@Repository
public interface Rwa_materialMapper {
 List<Rwa_material> findAll();
 }

6.mapper映射(这边使用到了generator的自动生成话说真的挺好用的)

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.aiqiao.pmp.dao.warehouse.Rwa_materialMapper" >
  <resultMap id="BaseResultMap" type="com.aiqiao.pmp.bean.warehouse.Rwa_material" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="productName" property="productName" jdbcType="VARCHAR" />
    <result column="specifications" property="specifications" jdbcType="VARCHAR" />
    <result column="model" property="model" jdbcType="VARCHAR" />
    <result column="type" property="type" jdbcType="VARCHAR" />
    <result column="number" property="number" jdbcType="VARCHAR" />
    <result column="batchNumber" property="batchNumber" jdbcType="VARCHAR" />
    <result column="purpose" property="purpose" jdbcType="VARCHAR" />
    <result column="inputNumber" property="inputNumber" jdbcType="VARCHAR" />
    <result column="inputDate" property="inputDate" jdbcType="DATE" />
    <result column="inboundBatchNumber" property="inboundBatchNumber" jdbcType="VARCHAR" />
    <result column="warehouser" property="warehouser" jdbcType="VARCHAR" />
    <result column="storekeeper" property="storekeeper" jdbcType="VARCHAR" />
    <result column="status" property="status" jdbcType="INTEGER" />
  </resultMap>

  
  <select id="findAll"  resultMap="BaseResultMap">
    select * from rwa_material
  </select>
</mapper>

7.用的navicat可视化工具 下面是表(mysql数据库)

在这里插入图片描述随便添加的一些数据

8.最后的测试(测试用的谷歌浏览器 中间使用了JSONView插件美化数据)

在这里插入图片描述改变数据在测一下
在这里插入图片描述

9.总结

也不知道说些啥 第一次写博客 希望大佬们喜欢

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值