mybatis resultMap 嵌套,将部分属性对应封装到Map中,复杂映射mapper

霸气de小男生 提交于 2019-12-01 23:18:33

 

XML文件 

    <resultMap type="com.wpg.web.dto.TemplateColumnsVO" id="TemplateColumnsVO">
        <result column="type" property="type" />
        <result column="column_code" property="columnCode" />
        <result column="label" property="label" />
        <result column="placeholder" property="placeholder" />
        <result column="b_required" property="require"/>
        <result column="value" property="value"/>
        <collection property="values" javaType="ArrayList" ofType="com.wpg.web.dto.ColumnValuesVO">
        	<result column="dicValue" property="value"/>
        	<result column="dicName" property="name"/>
            <collection property="haha" resultMap="myMap">
            </collection>
        </collection>
    </resultMap>
    <resultMap id="myMap" type="java.util.Map">
        <result column="dic" property="dic"/>
    </resultMap>

//查询方法
	<select id="getColumnValueById" resultMap="TemplateColumnsVO">
		SELECT
			tc.type ,tc.column_code ,tc.label ,tc.placeholder , tc.b_required , tc.value ,tcd.value  as dicValue ,tcd.name as dicName,tcd.name as dic
		FROM
			template_column tc
			LEFT JOIN template_column_dict tcd ON tc.id = tcd.template_column_id
			where tc.tamplate_id= #{templateId}
			order by tc.order_by ,tcd.order_by
	</select>

部分Java实体类 

@Data
public class ColumnValuesVO {

	private String name;

	private String value;

	private Map<String,Object> haha;

}

 结果如图:

参考文档连接:https://www.cnblogs.com/hamhog/p/3959451.html  介绍的是map的嵌套,讲解的很清楚,谢谢作者

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!