SpringBoot使用MybatisPlus

前言:MybatisPlus是是一个 MyBatis 的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发、提高效率而生。


一、导入pom

<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>3.3.0</version>
</dependency>

二、配置

在入口文件进行配置注解
@MapperScan(“com.baomidou.mybatisplus.samples.quickstart.mapper”)

@SpringBootApplication
@MapperScan("com.baomidou.mybatisplus.samples.quickstart.mapper")
public class Application {
    
    
    public static void main(String[] args) {
    
    
        SpringApplication.run(QuickStartApplication.class, args);
    }
}

三、mapper需要继承BaseMapper

public interface User2Mapper extends BaseMapper<User> {
    
    
}

四、使用

在service中使用的时候,自动装配对应的mapper,然后使用即可

@Service
public class UserServiceImpl implements UserService {
    
    
    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> findAll() {
    
    
        System.out.println("使用了MybatisPlus形式编写");
        return userMapper.selectList(null);
    }

关于MybatisPlus的相关由来以及更为详细的使用不是本文重点,可以移步官网查看。

使用过程一些不错得案例和使用技巧可以移步博客进行查看。

猜你喜欢

转载自blog.csdn.net/weixin_42656358/article/details/108725265