Mybatis-plus的结构
简单理解
先去扫描实体
通过反射抽取把实体类的属性抽取出来
然后分析我们要操作的表是谁
生成对应的sql语句
注入到mybatis容器中
操作的表和表中的字段是由实体类以及实体类中的属性决定
1使用:
1.1引入依赖
com.baomidou mybatis-plus-boot-starter3.5.1
1.2通过MP提供的方法CRUD
继承 BaseMapper
@Mapper public interface UserMapper extends BaseMapper{
1.3通过service去实现接口
1.3.1接口类继承IService
public interface UserService extends IService{ }
(我的具体实现方法:)
mapper类
@Mapper public interface UserMapper extends BaseMapper{ Map selectMapById(Long id); }
实体类
@TableName("user")
public class User {
@TableId(value = "id")
private Long id;
@TableField("user_name")
private String name;
private Integer age;
private String email;
@TableLogic
private Integer isDeleted;
}
配置文件
1.3.2类中实现并继承ServiceImpl-----M表示我们当前要操作的mapper接口,T表示我们当前要操作的实体类类型
@Service public class UserServiceImpl extends ServiceImplimplements UserService { }
2.mybatis-plus 全局配置
# mybatis-plus 全局配置
global-config:
db-config:
id-type: auto
table-prefix:
常用注解
1.@TableName("表名")
2.@TableId
将属性所对应的字段指定为主键
@TableId注解的value属性用于指定主键的字段
@TableId注解的type属性设置主键生成策略
@TableField
@TableFiled指定属性所对应的字段名
。。。。。。。。Over



