字段映射与表名映射
1、当数据库表名tbl_user与实体类名User不一致时:在实体类上添加 :@TableName("tbl_user")
package com.itheima.domain; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; @Data @TableName("tbl_user") public class User { private Long id; private String name; private String password; private Integer age; private String tel; }
2、当数据库字段名password与实体类属性名不一致pwd时,在实体类属性上添加:@TableField(value = "pwd")
package com.itheima.domain; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; @Data @TableName("tbl_user") public class User { private Long id; private String name; @TableField(value = "pwd") private String password; private Integer age; private String tel; }
3、当实体类中的属性online在数据库表字段中不存在时:在online属性上添加:@TableField(exist = false)
package com.itheima.domain; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; @Data @TableName("tbl_user") public class User { private Long id; private String name; @TableField(value = "pwd") private String password; private Integer age; private String tel; @TableField(exist = false) private Integer online; }
4、设置pwd不被查询:在pwd上添加:@TableField(value = "pwd", select = false)
package com.itheima.domain; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; @Data @TableName("tbl_user") public class User { private Long id; private String name; @TableField(value = "pwd", select = false) private String password; private Integer age; private String tel; @TableField(exist = false) private Integer online; }
标签:TableField,兼容性,MyBatisPlus,String,映射,TableName,private,import,com From: https://www.cnblogs.com/fxzm/p/17133025.html