表:
需求:
將表中的數(shù)據(jù),按照一級(jí)二級(jí)分類返回給前端json數(shù)據(jù)
代碼實(shí)現(xiàn):
java代碼:
1
2
3
|
public class ResultIndustry { private String industryFirst; //一級(jí)行業(yè) private List<String> industrySecondList; //二級(jí)行業(yè) |
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> |
總結(jié):
其實(shí)就是一對(duì)多的封裝數(shù)據(jù),從傳統(tǒng)的表關(guān)聯(lián)的一對(duì)多,聯(lián)想到單表內(nèi)的一對(duì)多.
以上所述是小編給大家介紹的通過(guò)Mybatis實(shí)現(xiàn)單表內(nèi)一對(duì)多的數(shù)據(jù)展示示例代碼,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)服務(wù)器之家網(wǎng)站的支持!
原文鏈接:http://www.cnblogs.com/lukeheng/archive/2017/08/26/7435088.html