Collection filters empty fields in MyBatis resultMap

When using MyBatis to query data, the return value can be defined as resultMap.

If there is a list in the returned object, it can also collectionbe defined using tags.

At this time, if you do not want data with some empty fields to be added to the list, you can use notNullColumnattributes to define it:

<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>

notNullColumnThe attribute corresponds to columnthe value of the attribute. Multiple fields can be set, ,separated by.

The above code will filter out idand nameadd data to the list, realizing the function of collecting empty fields in resultMap .

Guess you like

Origin blog.csdn.net/qq_37770674/article/details/132361021