1,pom增加依赖
<dependencies>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
2,在 Spring Boot 启动类中添加 @MapperScan 注解,扫描 Mapper 文件夹:
@SpringBootApplication
@MapperScan("com.baomidou.mybatisplus.samples.quickstart.mapper")
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
3,编写实体类 User.java(此处使用了 Lombok
@Data
public class User {
private Long id;
private String name;
private Integer age;
private String email;
}
4,编写Mapper包下的UserMapper接口
public interface UserMapper extends BaseMapper<User> {
}
注:不需要xml文件。
开始使用
@Autowired
UserMapper userMapper;
@PostMapping("/insert")
@Log
public Result insert() {
User user = new User();
userMapper.insert(user);
return Result.getSuccessNoData();
}
具体CRUD参考文档
https://baomidou.com/pages/49cc81/#service-crud-%E6%8E%A5%E5%8F%A3
参考:
https://baomidou.com/pages/226c21/#%E5%88%9D%E5%A7%8B%E5%8C%96%E5%B7%A5%E7%A8%8B
标签:Java,E5%,private,Plus,User,Mysql,baomidou,com,public From: https://blog.51cto.com/u_15815563/5759288