mybatis中resultType为map时,null值的字段不返回
<select id="getUser" parameterType="map" resultType="map"> SELECT id, name, addr FROM user WHERE id = #{id} </select>
以上查询,当addr字段值在数据库中为null时,返回的结果如下:
1 {
2 "id": 1,
3 "name": "test"
4 }
正常我们想要的应该是这样:
1 {
2 "id": 1,
3 "name": "test",
4 "addr": null
5 }
解决办法:
1. 使用实体类进行接收
2.修改application.yml配置
mybatis:
configuration:
call-setters-on-nulls: true
使用了 mybatis-plus的 配置
mybatis-plus:
configuration:
call-setters-on-nulls: true
本文来自博客园,作者:天军,原文链接:https://www.cnblogs.com/h2285409/p/17803324.html
本文来自博客园,作者:void_main(),转载请注明原文链接:https://www.cnblogs.com/void--main/p/18289716

浙公网安备 33010602011771号