springboot如何使用mabtisplus
时间: 2023-01-31 21:01:52 浏览: 124
1. 在pom.xml文件中添加mybatis-plus的依赖。例如:
```
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.1</version>
</dependency>
```
2. 在application.properties文件中配置数据源信息。例如:
```
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=root
```
3. 在启动类中添加@MapperScan注解,扫描mapper接口所在的包。例如:
```
@SpringBootApplication
@MapperScan("com.example.demo.mapper")
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
```
4. 在mapper接口中使用mybatis-plus的注解进行数据库操作。例如:
```
@Mapper
public interface UserMapper extends BaseMapper<User> {
}
```
在这个mapper接口中就可以使用mybatis-plus提供的CRUD方法了。
阅读全文
相关推荐









