MyBatis-Plus使用小结

官网:
https://mybatis.plus/
https://gitee.com/baomidou/mybatis-plus
https://github.com/baomidou/mybatis-plus
1.引入依赖:

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

2.编写自己接口继承BaseMapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

@Repository
public interface StuDescMapper extends BaseMapper<StuDesc> {}

3.设置yml文件,官方配置介绍https://mybatis.plus/config/

spring:
  datasource:
    name: student_info
    url: jdbc:mysql://127.0.0.1:3306/student_info?serverTimezone=GMT%2B8
    username: root
    password: test
    driver-class-name: com.mysql.cj.jdbc.Driver

server:
  port: 9090
  
#根据自己的需求配置
mybatis-plus:
 mapperLocations: classpath:mapper/*.xml
 configuration :
  mapUnderscoreToCamelCase: true
 globalConfig:
  banner: true

4.编辑实体,官方注解说明https://mybatis.plus/guide/annotation.html

@TableName(value = "s_desc")
public class StuDesc {
    private String id;
    @TableId
    private Integer userId;
    private String scoreLevel;
    @TableField(value = "`desc`")
    private String desc;

5.crdu的使用
查询条件的构造:

QueryWrapper<StuDesc> stuDescQueryWrapper = new QueryWrapper<>();

(1)QueryWrapper可以直接填充实体StuDesc,根据实体的内容去执行;
(2)QueryWrapper也可构造添加去执行,stuDescQueryWrapper.eq(“表字段名”,“具体的值”);

附加:MyBatis-Plus功能很强大,还有很多功能可以使用,
CRUD 接口:https://mybatis.plus/guide/crud-interface.html
条件构造器:https://mybatis.plus/guide/wrapper.html

发布了29 篇原创文章 · 获赞 0 · 访问量 4038

猜你喜欢

转载自blog.csdn.net/InternetJava/article/details/104592531