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 collection
be 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 notNullColumn
attributes 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>
notNullColumn
The attribute corresponds to column
the value of the attribute. Multiple fields can be set, ,
separated by.
The above code will filter out id
and name
add data to the list, realizing the function of collecting empty fields in resultMap .