MyBatisPlus(六)字段映射 @TableField

字段注解(非主键)

@TableField 用于映射对象的 属性 和表中的 字段

属性名字段名 差异较大的时候,无法通过默认的映射关系对应起来,就需要指定 属性名 对应 的 字段名

官网示例

MyBatisPlus(六)字段映射 @TableField_第1张图片

代码实例

package com.example.web.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;

@Data
public class User {
    private Long id;
    @TableField("username")
    private String name;
    private Integer age;
    private String email;
}

使用效果

普通查询

普通查询,能够正确的映射。
MyBatisPlus(六)字段映射 @TableField_第2张图片

方法引用(条件查询)

使用 方法引用 进行条件查询时,也能正常映射。
MyBatisPlus(六)字段映射 @TableField_第3张图片

你可能感兴趣的:(MyBatis,mybatis)