我现在需要从后端给前端传一个仓库的名字,但我的数据库的物资表data_material中只记录的仓库的id,storage_id字段.仓库的名称信息记录在data_storage表中的name字段,为了拿到这个name,我使
detail.setStorageName(storageService.getById(detail.getStorageId()).getName());
便能通过storageId拿到storage的name,
但storageName并不是一个在数据库中存在的字段,
我们可以在利用MybatisPlus中@TableField注解,
在实体类中这么写
@TableField(exist = false)
@Excel(name = "所属仓库")
private String storageName;//所属仓库
exist = false表示当前属性不是数据库的字段,但在项目中必须使用,这样在新增等使用bean的时候,mybatis-plus就会忽略这个,不会报错.