软件编程
位置:首页>> 软件编程>> java编程>> 通过Mybatis实现单表内一对多的数据展示示例代码

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

作者:你是不是想家了  发布时间:2021-12-20 12:34:31 

标签:mybatis,一对多

表:

通过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实现单表内一对多的数据展示示例代码网站的支持!

来源:http://www.cnblogs.com/lukeheng/archive/2017/08/26/7435088.html

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com