通過Mybatis實現(xiàn)單表內(nèi)一對多的數(shù)據(jù)展示示例代碼
表:
需求:
將表中的數(shù)據(jù),按照一級二級分類返回給前端json數(shù)據(jù)
代碼實現(xiàn):
java代碼:
public class ResultIndustry { private String industryFirst;//一級行業(yè) private List<String> industrySecondList;//二級行業(yè)
mybatis代碼:
<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ù)據(jù),從傳統(tǒng)的表關(guān)聯(lián)的一對多,聯(lián)想到單表內(nèi)的一對多.
以上所述是小編給大家介紹的通過Mybatis實現(xiàn)單表內(nèi)一對多的數(shù)據(jù)展示示例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
詳解備忘錄模式及其在Java設(shè)計模式編程中的實現(xiàn)
這篇文章主要介紹了詳解備忘錄模式及其在Java設(shè)計模式編程中的實現(xiàn),備忘錄模式數(shù)據(jù)的存儲過程中應(yīng)當注意淺拷貝和深拷貝的問題,需要的朋友可以參考下2016-04-04Jackson中json格式的字符串與對象的互相轉(zhuǎn)換方式
這篇文章主要介紹了Jackson中json格式的字符串與對象的互相轉(zhuǎn)換方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-07-07SpringBoot如何在線程中獲取@Service Bean類
這篇文章主要介紹了SpringBoot如何在線程中獲取@Service Bean類,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-02-02消息隊列 RabbitMQ 與 Spring 整合使用的實例代碼
本篇文章主要介紹了消息隊列 RabbitMQ 與 Spring 整合使用的實例代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-08-08