当前位置:主页 > 软件编程 > 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>

    总结:

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

您可能感兴趣的文章:

相关文章