当前位置: 代码迷 >> 综合 >> spring boot加mybatis使用Map返回时,当值为空时属性也会没有
  详细解决方案

spring boot加mybatis使用Map返回时,当值为空时属性也会没有

热度:82   发布时间:2023-11-02 12:50:25.0

已解决:

如题,

1.当使用spring boot加mybatis时,设置Map返回,当值为空时属性也会没有

在application.properties中加入下面配置,将会解决这个问题。

#当查询数据为空时字段返回为null,不加这个查询数据为空时,字段将被隐藏

mybatis.configuration.call-setters-on-nulls=true

2.与springBoot搭配使用时:把下面configuration这段复制到yml中就行了

mybatis:mapperLocations: classpath*:mapper/**/*.xml#mybatis数据库字段内容为空时,返回该字段configuration:call-setters-on-nulls: true

3.mybatis配置中修改:

 
<settings>  <setting name="cacheEnabled" value="true"/>   <setting name="callSettersOnNulls" value="true"/>  </settings>  

 

  相关解决方案