首页 > 编程 > Java > 正文

通过Mybatis实现单表内一对多的数据展示示例代码

2019-11-26 11:34:18
字体:
来源:转载
供稿:网友

表:

  

需求:

  将表中的数据,按照一级二级分类返回给前端json数据

代码实现:

  java代码:

 public class ResultIndustry {  private String industryFirst;//一级行业 private List<String> industrySecondList;//二级行业

  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>

    总结:

  其实就是一对多的封装数据,从传统的表关联的一对多,联想到单表内的一对多.

以上所述是小编给大家介绍的通过Mybatis实现单表内一对多的数据展示示例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对武林网网站的支持!

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表