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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值