目录
Mybatis的简单使用
依赖
项目结构
父pom文件
pom文件
配置文件
实体类
controller
mapper
xml
结果
mybatis开启驼峰映射
方式一:
方式二:
方式三:
方式四:
MyBatis结合PageHelper进行分页
父pom文件
pom文件
配置文件
MyBatisConfig
controller
结果
Mybatis的简单使用
本示例为父子项目演示:
依赖
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
项目结构
父pom文件
注意:父pom中 starter-web和starter-test不需要
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<!-- <version>3.1.2</version>-->
<version>2.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.chensir</groupId>
<artifactId>springboot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot</name>
<description>springboot</description>
<properties>
<java.version>8</java.version>
<hutool.version>5.8.3</hutool.version>
<lombok.version>1.18.24</lombok.version>
<alibaba-sdk.version>2.0.0</alibaba-sdk.version>
</properties>
<packaging>pom</packaging>
<modules>
<module>servlet</module>
<module>spring-interceptor</module>
<module>spring-aop</module>
<module>spring-united-reslut</module>
<module>spring-jdbc</module>
<module>spring-mybatis</module>
</modules>
<dependencyManagement>
<dependencies>
<!--钉钉机器人消息-->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>alibaba-dingtalk-service-sdk</artifactId>
<version>${alibaba-sdk.version}</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>${hutool.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-web</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-test</artifactId>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
pom文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.chensir</groupId>
<artifactId>springboot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>spring-mybatis</artifactId>
<dependencies>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter-test</artifactId>
<version>2.1.4</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
错误再现
本人在这入了个坑,刚开始子项目中引入lombok依赖后版本为1.18.12,而父pom文件中版本是1.18.24;结果调用接口时提示说实体类在SpringMvc中转换异常!好家伙,这我也联想不到是lombok的原因啊。所以就一直排查问题(几个小时后)我把实体类中@data去掉后 手动写入@set、@get等方,接口就完全通了!由此开始去看@lombok注解 才发现子项目中引入
<dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency>
这个注解后,子项目中lombok依赖版本就变成了1.18.12。然后接口就还报那个错误!把依赖注释掉,子项目中lombok依赖版本继承父项目版本为1.18.24,接口可以调通;但是过一会 我把子项目中lombok依赖又加上,发现lombok的版本又不会改变了(1.18.24),刷新maven、重启idea还是不会变!这他娘的让我摸不着头脑!真奇葩啊!
最后我在父pom中使用<dependencyManagement></dependencyManagement>去管理依赖版本,防止父子依赖版本不对而冲突!
dependencyManagement里只是声明依赖,并不自动实现引入,因此子项目需要显示的声明需要用的依赖。如果不在子项目中声明依赖,是不会从父项目中继承下来的;只有在子项目中写了该依赖项,并且没有指定具体版本,才会从父项目中继承该项,并且version和scope都读取自父pom;另外如果子项目中指定了版本号,那么会使用子项目中指定的jar版本。
这个原因就是父pom中引用了
<!--父pom中不要加此依赖,否则依赖clean会报错,原因是父pom中并没指定版本--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency>
这两个依赖;并且这俩注解也没指定版本,以至于子pom中找不到版本号;
在clean右键 Run Maven Build时会报全部的子项目中找不到starter-web、starter-test版本号;在父pom中去掉这两个依赖即可!
配置文件
spring.datasource.url=jdbc:mysql://localhost:3306/db1?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=true
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
mybatis.mapper-locations = classpath*:mapper/*Mapper.xml
实体类
@Data
public class Users {
private Long id;
private String name;
private Integer age;
private String sex;
private String tel;
// 数据库timestamp类型时间转化java规定格式时间
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
// 接受前端表单传递过来的字符串类型的时间数
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date createTime;
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDateTime updateTime;
}
controller
@RestController
public class UsersController {
@Resource
private UsersService usersService;
@GetMapping("/demo1")
public List<Users> selectUsersList() {
List<Users> users = usersService.selectUsersList();
return users;
}
@GetMapping("/demo2")
public Users selectUsers(){
Users users = usersService.selectUsers();
return users;
}
@GetMapping("/demo3")
public Map selectUsersToMap(){
return usersService.selectUsersToMap();
}
}
mapper
@Mapper
public interface UsersMapper {
List<Users> selectUsersList();
Users selectUsers();
Map<String,Object> selectUsersToMap();
}
xml
<?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.chensir.mapper.UsersMapper">
<select id="selectUsersList" resultType="com.chensir.entity.Users">
select * from users
</select>
<select id="selectUsers" resultType="com.chensir.entity.Users">
select * from users where id = 1
</select>
<select id="selectUsersToMap" resultType="java.util.Map">
select * from users where id = 1
</select>
</mapper>
结果
查询后发现时间为null!这是因为mybatis需要开启驼峰映射,默认是关闭的(mybatis-plus默认是开启的);
mybatis开启驼峰映射
方式一:
在xml中做映射(本人不喜欢这样写法)
<resultMap type="com.chensir.entity.Users" id="resultList">
<result property="id" column="id"/>
<result property="name" column="name"/>
<result property="createTime" column="create_time"/>
</resultMap>
方式二:
mybatis-config.xml文件:但是使用SpringBoot后这中方式也不常使用
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<!-- 开启驼峰,开启后,只要数据库字段和对象属性名字母相同,无论中间加多少下划线都可以识别 -->
<setting name="mapUnderscoreToCamelCase" value="true" />
</settings>
</configuration>
方式三:
在配置文件中配置
mybatis.mapper-locations = classpath*:mapper/*Mapper.xml
#开启驼峰映射
mybatis.configuration.map-underscore-to-camel-case=true
mybatis-plus配置(mybatis-plus默认是开启的)
mybatis-plus:
configuration:
#在映射实体或者属性时,将数据库中表名和字段名中的下划线去掉,按照驼峰命名法映射 address_book ---> addressBook
map-underscore-to-camel-case: true
注意:如果SqlSessionFactory自己手动配置后,无论配置文件中配置的扫描 Mapper.xml还是开启驼峰映射都会失效,这时就需要在cofnig中手动配置并注入,详见方式四;
方式四:
手动配置SqlSessionFactory并往SqlSessionFactory注入扫描Mapper.xml、驼峰映射等;
手动配置SqlSessionFactory后自动装配就不会使用官方的,启动项目后会先扫描自己注册的!
package com.chensir.config;
import com.github.pagehelper.PageInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.boot.autoconfigure.ConfigurationCustomizer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.util.CollectionUtils;
import javax.sql.DataSource;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@Configuration
@Slf4j
public class MyBatisConfig {
@Autowired
private ConfigurationCustomizer configurationCustomizer;
/**
* 自己注册SqlSessionFactory 目的是增强功能,添加分页插件
* @param ds 代表数据源
* @return
* @throws Exception
*/
@Bean
public SqlSessionFactory sqlSessionFactory(DataSource ds) throws Exception {
SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
// 设置数据源
factoryBean.setDataSource(ds);
// 把分页插件设置到SqlSessionFactory插件库
factoryBean.setPlugins(new PageInterceptor());
// 配置mapper.xml地址
factoryBean.setMapperLocations(resolveMapperLocations());
//驼峰映射注册到SqlSessionFactory中
org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration();
configurationCustomizer.customize(configuration);
factoryBean.setConfiguration(configuration);
// 返回具体实例对象
SqlSessionFactory bean = factoryBean.getObject();
return bean;
}
/**
* 开启驼峰映射
* @return
*/
@Bean
public ConfigurationCustomizer configurationCustomizer(){
return new ConfigurationCustomizer() {
@Override
public void customize(org.apache.ibatis.session.Configuration configuration) {
configuration.setMapUnderscoreToCamelCase(true);
}
};
}
/**
* 查找 xxxMapper.xml
* @return
*/
public Resource[] resolveMapperLocations() {
ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
List<String> mapperLocations = new ArrayList<>();
mapperLocations.add("classpath*:mapper/*Mapper.xml");
// mapperLocations.add("classpath*:com/meiwei/ping/dao/**/*Mapper.xml");
List<Resource> resources = new ArrayList();
if (!CollectionUtils.isEmpty(mapperLocations)) {
for (String mapperLocation : mapperLocations) {
try {
Resource[] mappers = resourceResolver.getResources(mapperLocation);
resources.addAll(Arrays.asList(mappers));
} catch (IOException e) {
log.error("Get myBatis resources happened exception", e);
}
}
}
return resources.toArray(new Resource[resources.size()]);
}
}
MyBatis结合PageHelper进行分页
使用pagehelper进行分页时起初我并没有自己注入SqlSessionFactory,而是使用官方的;但是在
users强转page时会报强转错误;于是乎我开始使用PageInfo方式;
虽然不报错了,结果能分页了,但是页码和条数不生效! 唉,一波未停一波又起啊!
于是乎,我又开始去手动配置SqlSessionFactory(MyBatisConfig),并且把扫描xxxMapper.xml、驼峰映射注入;详细流程请看下方代码。
父pom文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<!-- <version>3.1.2</version>-->
<version>2.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.chensir</groupId>
<artifactId>springboot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot</name>
<description>springboot</description>
<properties>
<java.version>8</java.version>
<hutool.version>5.8.3</hutool.version>
<lombok.version>1.18.24</lombok.version>
<alibaba-sdk.version>2.0.0</alibaba-sdk.version>
</properties>
<packaging>pom</packaging>
<modules>
<module>servlet</module>
<module>spring-interceptor</module>
<module>spring-aop</module>
<module>spring-united-reslut</module>
<module>spring-jdbc</module>
<module>spring-mybatis</module>
</modules>
<dependencyManagement>
<dependencies>
<!--钉钉机器人消息-->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>alibaba-dingtalk-service-sdk</artifactId>
<version>${alibaba-sdk.version}</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>${hutool.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
<!--父pom中不要加此依赖,否则依赖clean会报错,原因是父pom中并没指定版本-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-web</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-test</artifactId>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
pom文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.chensir</groupId>
<artifactId>springboot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>spring-mybatis</artifactId>
<dependencies>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.10</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter-test</artifactId>
<version>2.1.4</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
配置文件
spring.datasource.url=jdbc:mysql://localhost/db1?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
MyBatisConfig
package com.chensir.config;
import com.github.pagehelper.PageInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.boot.autoconfigure.ConfigurationCustomizer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.util.CollectionUtils;
import javax.sql.DataSource;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@Configuration
@Slf4j
public class MyBatisConfig {
@Autowired
private ConfigurationCustomizer configurationCustomizer;
/**
* 自己注册SqlSessionFactory 目的是增强功能,添加分页插件
* @param ds 代表数据源
* @return
* @throws Exception
*/
@Bean
public SqlSessionFactory sqlSessionFactory(DataSource ds) throws Exception {
SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
// 设置数据源
factoryBean.setDataSource(ds);
// 把分页插件设置到SqlSessionFactory插件库
factoryBean.setPlugins(new PageInterceptor());
// 配置mapper.xml地址
factoryBean.setMapperLocations(resolveMapperLocations());
//驼峰映射注册到SqlSessionFactory中
org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration();
configurationCustomizer.customize(configuration);
factoryBean.setConfiguration(configuration);
// 返回具体实例对象
SqlSessionFactory bean = factoryBean.getObject();
return bean;
}
/**
* 开启驼峰映射
* @return
*/
@Bean
public ConfigurationCustomizer configurationCustomizer(){
return new ConfigurationCustomizer() {
@Override
public void customize(org.apache.ibatis.session.Configuration configuration) {
configuration.setMapUnderscoreToCamelCase(true);
}
};
}
/**
* 查找 xxxMapper.xml
* @return
*/
public Resource[] resolveMapperLocations() {
ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
List<String> mapperLocations = new ArrayList<>();
mapperLocations.add("classpath*:mapper/*Mapper.xml");
// mapperLocations.add("classpath*:com/meiwei/ping/dao/**/*Mapper.xml");
List<Resource> resources = new ArrayList();
if (!CollectionUtils.isEmpty(mapperLocations)) {
for (String mapperLocation : mapperLocations) {
try {
Resource[] mappers = resourceResolver.getResources(mapperLocation);
resources.addAll(Arrays.asList(mappers));
} catch (IOException e) {
log.error("Get myBatis resources happened exception", e);
}
}
}
return resources.toArray(new Resource[resources.size()]);
}
}
controller
有PageInfo和Page两种方式
package com.chensir.controller;
import com.chensir.entity.Users;
import com.chensir.service.UsersService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
public class UsersController {
@Resource
private UsersService usersService;
@GetMapping("/demo1")
public Map selectUsersList(Integer pageNum,Integer pageSize) {
// 启用分页,查询第一页,每页3条
PageHelper.startPage(pageNum,pageSize);
//-------------PageInfo方式---------------
// PageInfo<Users> usersPageInfo = new PageInfo<>(usersService.selectUsersList());
// return usersPageInfo;
//-------------PageInfo方式---------------
//-------------Page方式---------------
List<Users> users = usersService.selectUsersList();
Page page = (Page) users;
int pages = page.getPages();
long total = page.getTotal();
Map<String,Object> pageMap = new HashMap<>();
pageMap.put("pages",pages);
pageMap.put("total",total);
pageMap.put("items",users);
return pageMap;
//-------------Page方式---------------
}
@GetMapping("/demo2")
public Users selectUsers(){
Users users = usersService.selectUsers();
return users;
}
@GetMapping("/demo3")
public Map selectUsersToMap(){
return usersService.selectUsersToMap();
}
}
结果
{
"total": 5,
"pages": 2,
"items": [
{
"id": 1,
"name": "chjnzkcn",
"age": 18,
"sex": "男",
"tel": "123",
"createTime": "2023-05-11",
"updateTime": "2023-05-11"
},
{
"id": 2,
"name": "czvfzsvdv",
"age": 20,
"sex": "男",
"tel": "2315",
"createTime": "2023-05-11",
"updateTime": "2023-05-11"
},
{
"id": 3,
"name": "sczvszv",
"age": 18,
"sex": "女",
"tel": "2112321",
"createTime": "2023-05-11",
"updateTime": "2023-05-11"
}
]
}
但是这样的分页不足以满足我们的需要,在我们想要进行分页时需要重复撰写这样的代码,显然很不方便!下篇开始来对分页进行封装!