mybatis xml 中resultMap collection 的column传入多个参数问题
1. mapper 写法
List<ToolSortVo> listGroupByToolSort(ToolInfo query);
2. bean
@Data
public class ToolInfo {
/**
* 工具名称
*/
private String toolName;
}
3. 查询示例
<select id="listGroupByToolSort" resultMap="toolSortVoResultMap" parameterType="Object">
SELECT b.dictionary_key,b.dictionary_value , '${toolName}' as tool_name
from dictionary a,dictionary_kv b
</select>
<!-- 工具类型 Result Map-->
<resultMap id="toolSortVoResultMap" type="cn.xxx.ToolSortVo">
<result column="dictionary_key" property="toolSortNo"/>
<result column="dictionary_value" property="toolSortName"/>
<!-- 参数当成下游的伪列-->
<result column="tool_name" property="toolName"/>
<!-- 工具信息 一对多-->
<collection property="toolList" ofType="cn.xxx.ToolVo"
select="selectToolLists" column="{too_sort_no=dictionary_key,toolName=tool_name}"/>
<!-- column={下游列=上游列 } 这种形式配置-->
</resultMap>
<!-- 工具信息 一对多-->
<select id="selectToolLists"
resultType="cn.xxx.ToolVo"
resultMap="toolVoResultMap">
SELECT create_author,update_time,update_author
from tool_info
<where>
tool_sort = #{too_sort_no}
<if test="toolName!= null and toolName!=''">
and tool_name like concat('%', #{toolName},'%')
</if>
</where>
</select>
参考:
2021-06-11 mybatis collection column属性用法