springboot加mybatisplus框架搭建
时间: 2023-06-23 09:10:02 浏览: 105
好的,下面是使用Spring Boot和MyBatis Plus框架搭建项目的步骤:
1. 创建Spring Boot项目
首先,在IDE中创建一个新的Spring Boot项目。
2. 添加依赖
在pom.xml文件中添加以下依赖,其中包括Spring Boot、MyBatis Plus、MySQL等:
```
<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- MyBatis Plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.3.2</version>
</dependency>
<!-- MySQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.23</version>
</dependency>
```
3. 配置数据库连接信息
在application.properties文件中配置数据库连接信息:
```
spring.datasource.url=jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
```
4. 创建实体类
创建实体类,使用MyBatis Plus的@TableField注解和@TableId注解分别标注表的字段和主键。
5. 创建Mapper接口
创建Mapper接口,使用MyBatis Plus的BaseMapper接口。
6. 创建Service接口和实现类
创建Service接口和实现类,使用MyBatis Plus的IService接口和ServiceImpl类。
7. 编写Controller
编写Controller,使用@RestController注解和@Autowired注入Service。
8. 测试
启动项目,访问http://localhost:8080/,测试接口是否正常。
以上就是使用Spring Boot和MyBatis Plus框架搭建项目的步骤。
阅读全文
相关推荐














