mybatis resultMap 嵌套,將部分屬性對應封裝到Map中,複雜映射mapper

 

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的嵌套,講解的很清楚,謝謝作者

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章