1.application.yaml设置mybayisPlus没加call-setters-on-nulls: true之前
mybatis-plus:
mapper-locations: classpath*:/mapper/**Mapper.xml
#实体扫描,多个package用逗号或者分号分隔
typeAliasesPackage: com.vkl.booking.persistence.entity
configuration.cache-enabled: false
global-config.db-config.db-type: mysql
configuration.jdbc-type-for-null: null
调用mybatisPlus的selectMaps方法。好处:如果返回类型某个对象缺少字段,这里可以自定义要返回的字段。
public Message test(){
List<Map<String, Object>> mapList = cLibraryMapper.selectMaps(new LambdaQueryWrapper<CompanyBookingLibrary>());
for(Map<String,Object> map :mapList){
/*自定义添加自己想要的字段*/
map.put("test","1");
}
return Message.object(mapList);
}
请求结果:
2.添加call-setters-on-nulls: true之后
mybatis-plus:
mapper-locations: classpath*:/mapper/**Mapper.xml
#实体扫描,多个package用逗号或者分号分隔
typeAliasesPackage: com.vkl.booking.persistence.entity
configuration.cache-enabled: false
global-config.db-config.db-type: mysql
configuration.jdbc-type-for-null: null
configuration:
call-setters-on-nulls: true
返回结果:
为空的字段也返回出来了,大功告成!