MyBatis resultMap中collection过滤空字段

在使用MyBatis查询数据时,返回值可以定义为resultMap

如果返回的对象中有列表,还可以使用collection标签进行定义。

此时,如果不想某些字段为空的数据加入列表,可以使用notNullColumn属性进行定义:

<resultMap id="resultMapDemo" type="返回值类型" >
    <id property="id" column="id" />
    <result property="name" column="name"/>
    <collection property="childList" notNullColumn="id,name" ofType="列表项类型">
      <id property="id" column="id"/>
      <result property="name" column="name"/>
      <result property="age" column="age"/>
    </collection>
  </resultMap>

notNullColumn属性可以设置多个字段,用,分隔。

以上代码会过滤掉idname的数据加入列表,实现了resultMap中collection过滤空字段的功能。

posted @   天航星  阅读(158)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
历史上的今天:
2022-08-17 设计模式 21 状态模式
2022-08-17 获取字符串中倒数第二个特定字符的位置
点击右上角即可分享
微信分享提示