发布于 2017-12-12 22:25:00 | 170 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的MyBatis教程,程序狗速度看过来!

MyBatis 基于Java的持久层框架

MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google code,并且改名为MyBatis 。


最近做项目遇到这样的需求要求将表中的数据,按照一级二级分类返回给前端json数据,下面通过本文给大家分享通过Mybatis实现单表内一对多的数据展示示例代码,感兴趣的朋友参考下吧

表:

  

需求:

  将表中的数据,按照一级二级分类返回给前端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实现单表内一对多的数据展示示例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对PHPERZ网站的支持!



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务