源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2020-09-11 09:14 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:通过Mybatis实现单表内一对多的数据展示示例代码
[b]表:[/b]   [img]http://files.jb51.net/file_images/article/201708/201708261456117.png[/img] [b]需求:[/b]   将表中的数据,按照一级二级分类返回给前端json数据 [b]代码实现:[/b]   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>
[b]    总结:[/b]   其实就是一对多的封装数据,从传统的表关联的一对多,联想到单表内的一对多. 以上所述是小编给大家介绍的通过Mybatis实现单表内一对多的数据展示示例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程素材网网站的支持!
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部