Springboot整合MybatisPlus及分页功能

1 引入pom

xml 复制代码
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot</artifactId>
    <version>2.7.14</version>
</dependency>
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>3.5.3.2</version>
</dependency>
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.29</version>
</dependency>

2 编写配置类MybatisPlusConfig

java 复制代码
@Configuration
public class MybatisPlusConfig {
    /**
     * 分页插件
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }
}

3 业务实现

3.1 Controller层

java 复制代码
    @Autowired
    IComponentService componentService;

    @ApiOperation(value = "查询基础组件列表", notes = "根据条件查询基础组件列表")
    @GetMapping("/list")
    public ResponseMessage<IPage<Component>> queryList(@RequestBody QueryEntity<ComponentDTO> queryEntity){
        IPage<Component> page = new Page<>(queryEntity.getPageNum(), queryEntity.getPageSize());
        LambdaQueryWrapper<Component> query = new LambdaQueryWrapper<>();
//        query.eq(Component::getType, queryEntity.getQuery().getType());
        return ResponseMessage.success("查询成功",componentService.queryList(page,query));
    }

3.2 service层

java 复制代码
IPage<Component> queryList(IPage<Component> page, LambdaQueryWrapper<Component> queryWrapper);

3.3 service实现层

java 复制代码
	@Override
    public IPage<Component> queryList(IPage<Component> page, LambdaQueryWrapper<Component> queryWrapper) {

        return componentMapper.selectPage(page,queryWrapper);
    }

3.4 dao层

java 复制代码
@Mapper
public interface ComponentMapper extends BaseMapper<Component> {

}

4 yaml配置

yaml 复制代码
server:
  #运行端口号
  port: 8090
  servlet:
    context-path: /hom

spring:
#  mvc:
#    pathmatch:
#      matching-strategy: ANT_PATH_MATCHER
  #数据源配置
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/hom?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=Asia/Shanghai
    username: root
    password: marlon

#mybatis-plus配置
mybatis-plus:
  configuration:
    #sql日志打印
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
    #开启驼峰命名匹配
    map-underscore-to-camel-case: true
    #mapper文件
  mapper-locations: classpath:mapper/**/*.xml,classpath:mapper/*.xml
  #数据库实体类的包全路径,方便在mapper.xml中不许使用实体类的全路径,写类名就行(不区分大小写)
  type-aliases-package: cn.com.marlon.hom.entity
  global-config:
    db-config:
      #逻辑删除
      logic-delete-value: 0
      logic-not-delete-value: 1
      logic-delete-field: deleted

5 postman测试

相关推荐
飞翔的佩奇1 小时前
Java项目: 基于SpringBoot+mybatis+maven+mysql实现的图书管理系统(含源码+数据库+答辩PPT+毕业论文)
java·数据库·spring boot·mysql·spring·毕业设计·图书管理
一 乐2 小时前
基于vue船运物流管理系统设计与实现(源码+数据库+文档)
前端·javascript·数据库·vue.js·spring boot·后端·船运系统
lwprain4 小时前
springboot 2.7.6 security mysql redis jwt配置例子
spring boot·redis·mysql
酷爱码7 小时前
springboot 动态配置定时任务
java·spring boot·后端
计算机-秋大田7 小时前
基于SpringBoot的美食烹饪互动平台的设计与实现(源码+SQL脚本+LW+部署讲解等)
vue.js·spring boot·后端·课程设计·美食
我的K84099 小时前
Spring Boot基本项目结构
java·spring boot·后端
字节全栈_kYu9 小时前
FastDFS实用笔记 (Docker 搭建环境 + 整合 SpringBoot)
spring boot·笔记·docker
晴空๓10 小时前
Spring Boot项目如何使用MyBatis实现分页查询
spring boot·后端·mybatis
customer0818 小时前
【开源免费】基于SpringBoot+Vue.JS体育馆管理系统(JAVA毕业设计)
java·vue.js·spring boot·后端·开源
计算机-秋大田20 小时前
基于微信小程序的电子竞技信息交流平台设计与实现(LW+源码+讲解)
spring boot·后端·微信小程序·小程序·课程设计