栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Mybatis-Plus了解与简单使用

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Mybatis-Plus了解与简单使用

Mybatis-plus的结构

简单理解

先去扫描实体

通过反射抽取把实体类的属性抽取出来

然后分析我们要操作的表是谁

生成对应的sql语句

注入到mybatis容器中

操作的表和表中的字段是由实体类以及实体类中的属性决定

1使用:

1.1引入依赖


    com.baomidou
    mybatis-plus-boot-starter
    3.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 ServiceImpl implements 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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/943650.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号