mybatisplus搭建
时间: 2023-11-09 08:03:42 浏览: 89
要搭建Mybatis Plus,需要进行以下步骤:
1. 在pom.xml中添加Mybatis Plus的依赖:
```
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.x.x</version>
</dependency>
```
2. 配置Mybatis Plus的相关参数,如数据源、实体类扫描等:
```
@Configuration
@MapperScan("com.example.mapper")
public class MybatisPlusConfig {
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
}
```
3. 编写Mapper接口,继承BaseMapper接口,并使用@Mapper注解标注:
```
@Mapper
public interface UserMapper extends BaseMapper<User> {
}
```
4. 在Service中注入Mapper,并使用Mybatis Plus提供的方法进行数据库操作:
```
@Service
public class UserServiceImpl implements UserService {
@Autowired
private UserMapper userMapper;
@Override
public List<User> list() {
return userMapper.selectList(null);
}
}
```
阅读全文
相关推荐












