使用MybatisPlus在实体中添加数据库表中不存在的字段

时间:2025-01-25 09:03:50

使用MybatisPlus在实体中添加数据库表中不存在的字段

文章目录

  • 使用MybatisPlus在实体中添加数据库表中不存在的字段
    • 一、问题描述
    • 二、报错如下
    • 三、解决方式

一、问题描述

在使用mybatis-plus时候,会在实体中添加一些数据库表中不存在的字段,为了在页面显示该属性,如果运行那么这个字段就会无法进行自动映射而报错。

二、报错如下

Error querying database. Cause:.: Unknown column ‘***’ in ‘field list’

三、解决方式

例如:age属性在表中不存在,在实体中添加age属性,需要在字段上加注解 @TableField(exist = false)

@Data
@TableName("sys_user")
public class UserEntity{

	private String id;
	
	private String user_name;
	
	@TableField(exist = false)
	private Integer user_age;
}