SpringBoot快速整合Mybatis&MybatisPlus

mysql

mysql-connector-java

5.1.45

com.baomidou

mybatis-plus-boot-starter

3.4.0

[](()2.2 在application.yml进行配置数据源
[](()2.2.1 新建applicaiton.yml`

环境隔离

spring:

profiles:

active: dev

《一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》无偿开源 威信搜索公众号【编程进阶路】
server:

compression:

请求gzip压缩

enabled: true

mime-types: text/html,text/xml,text/plain,text/css,text/javascript,application/javascript,application/json,application/xml

min-response-size: 1024

application:

name: edu-front-web

模板视图 thymeleaf

thymeleaf:

cache: false

prefix: classpath:/templates/

mode: HTML

encoding: UTF-8

json的转换配置

jackson:

date-format: yyyy-MM-dd HH:mm:ss

time-zone: GMT+8

locale: zh_CN

generator:

write-numbers-as-strings: true

write-bigdecimal-as-plain: true

##mybatis的原生态支持

mybatis-plus:

mapper-locations: classpath*:/mapper/*.xml

type-aliases-package: com.example.entity

#logging:<

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot整合MyBatis(Mybatis-Plus)和Swagger的步骤如下: 1. 首先,确保已经创建了一个Spring Boot项目。可以使用Spring Initializr或者手动创建。 2. 在项目的pom.xml文件中,添加MyBatisMybatis-Plus的依赖。例如: ```xml <dependencies> <!-- Spring Boot Starter --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- MyBatis --> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.2.0</version> </dependency> <!-- Mybatis-Plus --> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.4.2</version> </dependency> <!-- Swagger --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.9.2</version> </dependency> <!-- 其他依赖... --> </dependencies> ``` 3. 创建一个数据库表,并在application.properties/application.yml文件中配置数据库连接信息。 4. 创建MyBatis的Mapper接口和对应的XML文件,定义SQL语句和对应的映射关系。 5. 创建一个实体类,用于映射数据库表的字段。 6. 创建一个Service类,使用@Serive注解标识,并在类中注入Mapper接口,并实现相应的业务逻辑。 7. 创建一个Controller类,使用@RestController注解标识,并使用@Autowired注入Service类,在方法中实现相应的接口。 8. 在启动类上使用@EnableSwagger2注解开启Swagger的支持。 9. 运行项目,访问Swagger UI页面(http://localhost:8080/swagger-ui.html),可以查看和测试API接口。 以上就是Spring Boot整合MyBatis(Mybatis-Plus)和Swagger的基本步骤。根据实际需求,可以进一步配置和扩展。希望对你有所帮助!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值