Mybatis-plus 基础注解解析
注解解析
在 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);
}
}
@TableName(“sys_user”)
描述:表名注解,标识实体类对应的表
使用位置:实体类
@TableName("sys_user")
public class User {
@TableId
private Long id;
private String name;
}
@TableId(type = IdType.AUTO)
描述:主键注解
使用位置:实体类主键字段
@TableName("sys_user")
public class User {
@TableId(type = IdType.AUTO)
private Long id;
private String name;
private Integer age;
private String email;
}
IdType(opens new window)
@TableField(opens new window)
描述:字段注解(非主键)
@TableField(value = "user_name")
private String userName;
@TableField(value = "password",select = false)
private String password;