表:
需求:
將表中的數據,按照一級二級分類返回給前端json數據
代碼實現:
java代碼:
1 public class ResultIndustry { 2 private String industryFirst;//一級行業 3 private List<String> industrySecondList;//二級行業
mybatis代碼:
1 <select id="getResultIndustryList" resultMap="resultIndustryMap"> 2 SELECT DISTINCT industry_first,industry_second 3 FROM results 4 WHERE industry_second IS NOT NULL 5 AND industry_second != "" 6 </select> 7 8 <resultMap id="resultIndustryMap" type="com.gy_resc.common.bean.ResultIndustry"> 9 <result property="industryFirst" column="industry_first" jdbcType="VARCHAR"/> 10 <collection property="industrySecondList" ofType="java.lang.String"> 11 <result property="industrySecond" column="industry_second" jdbcType="VARCHAR"/> 12 </collection> 13 </resultMap>
原文地址 http://www.cnblogs.com/lukeheng/p/7435088.html
總結:
其實就是一對多的封裝數據,從傳統的表關聯的一對多,聯想到單表內的一對多.