表:
需求:
將表中的數據,按照一級二級分類返回給前端json數據
代碼實現:
java代碼:
1
2
3
|
public class ResultIndustry { private String industryFirst; //一級行業 private List<String> industrySecondList; //二級行業 |
mybatis代碼:
1
2
3
4
5
6
7
8
9
10
11
12
|
<select id= "getResultIndustryList" resultMap= "resultIndustryMap" > SELECT DISTINCT industry_first,industry_second FROM results WHERE industry_second IS NOT NULL AND industry_second != "" </select> <resultMap id= "resultIndustryMap" type= "com.gy_resc.common.bean.ResultIndustry" > <result property= "industryFirst" column= "industry_first" jdbcType= "VARCHAR" /> <collection property= "industrySecondList" ofType= "java.lang.String" > <result property= "industrySecond" column= "industry_second" jdbcType= "VARCHAR" /> </collection> </resultMap> |
總結:
其實就是一對多的封裝數據,從傳統的表關聯的一對多,聯想到單表內的一對多.
以上所述是小編給大家介紹的通過Mybatis實現單表內一對多的數據展示示例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對服務器之家網站的支持!
原文鏈接:http://www.cnblogs.com/lukeheng/archive/2017/08/26/7435088.html