springboot引入mybatisplus
时间: 2023-04-27 18:03:40 浏览: 139
Spring Boot引入Mybatis Plus可以通过以下步骤实现:
1. 在pom.xml文件中添加Mybatis Plus的依赖:
```
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.3.1</version>
</dependency>
```
2. 在application.properties或application.yml文件中配置Mybatis Plus的相关属性,如数据源、mapper扫描路径等:
```
# 数据源配置
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=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=root
# Mybatis Plus配置
mybatis-plus.mapper-locations=classpath*:mapper/*.xml
mybatis-plus.type-aliases-package=com.example.demo.entity
```
3. 创建Mapper接口并继承BaseMapper,如:
```
public interface UserMapper extends BaseMapper<User> {
}
```
4. 在Service中注入Mapper并调用相应的方法,如:
```
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper userMapper;
@Override
public List<User> list() {
return userMapper.selectList(null);
}
}
```
以上就是Spring Boot引入Mybatis Plus的基本步骤。
阅读全文
相关推荐















