问题描述:
select gantryId as "gantryId",name as "tollStationName",roadId as "roadId",countyName as "countyName",cityName as "cityName"
from doorframedata where gantryId = "123456"
List<Map<String, Object>> getTollStationData(String gantryId);
因为数据库的原因出现:
{
"gantryId": "123456",
"cityName": "天津市",
"tollStationName": "xxx收费站名",
//该处本应该显示 "roadId": "",
"countyName": "北辰区"
}
解决方法:
修改yml文件中Mybatis的配置,设置call-setters-on-nulls为true。
例如:
#MR配置
mybatis-plus:
#mappers文件存放位置
mapperLocations: classpath:mapper/*.xml
#配置MR在控制台输出日志
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
map-underscore-to-camel-case: false
#解决Mybatis 查询返回类型为Map 空值字段不显示
call-setters-on-nulls: true