mybatis中mysql递归查询多级_Mybatis + mysql 实现两级级联的查询

”,我们在一的mapper.xml中,用collection定义多的一个集合即可。

3f9115e4a727f6e464ae2d610bfa7f40.png

property --->对应实体类中,多的那个子类,list

ofType--->对应子类的试题类型

column---->父类传递给子类查询的外键

select----> 子类查询的方法

1.定义父类+子类的实体类

packagecom.imocc.mall.pojo;importlombok.Data;importjava.util.List;/***@authorwy*/@Datapublic classProvince {privateInteger id;privateString provinceid;privateString province;private Listlist;

@OverridepublicString toString() {return "Province{" +

"id=" + id +

", provinceid=‘" + provinceid + ‘\‘‘ +

", province=‘" + province + ‘\‘‘ +

", list=" + list +

‘}‘;

}

}

packagecom.imocc.mall.pojo;importlombok.Data;

@Datapublic classCity {privateInteger id;privateString cityid;privateString city;privateString father;

}

2.mapper类

fcd1cc39ebd9cb74216a7a9a31bea167.png

2. mapperxml文件

3f26ed16404c4109db84c3a5f4d0c441.png

3. 测试

20a7482fa8e79c114419436372afc5c8.png

JDBC Connection [HikariProxyConnection@1532915766wrapping com.mysql.cj.jdbc.ConnectionImpl@62dbe64e] will not be managed by Spring==> Preparing: select * from hat_province where provinceID =?

==> Parameters: 110000(String)<==Columns: id, provinceID, province<== Row: 1, 110000, 北京市====> Preparing: select id, cityID, city, father from hat_city where father = ?

====> Parameters: 110000(String)<====Columns: id, cityID, city, father<==== Row: 1, 110100, 市辖区, 110000

<==== Row: 2, 110200, 县, 110000

<==== Total: 2

<== Total: 1Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@8f2098e]

Province{id=1, provinceid=‘110000‘, province=‘北京市‘, list=[City(id=1, cityid=110100, city=市辖区, father=110000), City(id=2, cityid=110200, city=县, father=110000)]}

Mybatis + mysql 实现两级级联的查询

标签:mysq   ==   app   package   color   类型   情况   block   思想

本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉

本文系统来源:https://www.cnblogs.com/Edward-Wang/p/12080365.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值