欢迎来到代码驿站!

JAVA代码

当前位置:首页 > 软件编程 > JAVA代码

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

时间:2021-05-26 08:14:34|栏目:JAVA代码|点击:

表:

  

需求:

  将表中的数据,按照一级二级分类返回给前端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>

    总结:

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

上一篇:Java设计模式之观察者模式(Observer模式)介绍

栏    目:JAVA代码

下一篇:Java实现鼠标拖拽移动界面组件

本文标题:通过Mybatis实现单表内一对多的数据展示示例代码

本文地址:http://www.codeinn.net/misctech/129238.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有