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

posted @ 2024-07-08 13:34  void_main()  阅读(206)  评论(0)    收藏  举报