Mybatis學習第17節 -- 嵌套查詢(多對一和一對一)
阿新 • • 發佈:2019-03-17
tsql mes 店鋪 ltm map div 審核 app 文件 Shop實體類
Area實體類
ShopMapper映射文件
AreaMapper接口
測試用例
運行結果
總結
觀察Preparing可以明顯從結果中看出,進行了嵌套查詢.
package io.github.coinsjack.pojo;
Area area;
} |
public class Area implements Serializable{
|
<resultMap id="simpleResultMap" type="Shop">
|
這裏需要註意, association必須放置在result後面
AreaMapper映射文件
<?xml version="1.0" encoding="UTF-8" ?>
|
public interface AreaMapper {
|
@Test
|
2018-12-28 20:33:07,171 [main] DEBUG [io.github.coinsjack.dao.ShopMapper] - Cache Hit Ratio [io.github.coinsjack.dao.ShopMapper]: 0.0 2018-12-28 20:33:07,565 [main] DEBUG [io.github.coinsjack.dao.ShopMapper.getShopById] - ==> Preparing: select * from tb_shop where `shop_id` = ? 2018-12-28 20:33:07,655 [main] DEBUG [io.github.coinsjack.dao.ShopMapper.getShopById] - ==> Parameters: 1(Integer) 2018-12-28 20:33:07,728 [main] DEBUG [io.github.coinsjack.dao.AreaMapper.getAreaById] - ====> Preparing: select * from tb_area WHERE `area_id` = ?; 2018-12-28 20:33:07,729 [main] DEBUG [io.github.coinsjack.dao.AreaMapper.getAreaById] - ====> Parameters: 3(Integer) 2018-12-28 20:33:07,736 [main] DEBUG [io.github.coinsjack.dao.AreaMapper.getAreaById] - <==== Total: 1 2018-12-28 20:33:07,737 [main] DEBUG [io.github.coinsjack.dao.ShopMapper.getShopById] - <== Total: 1 Shop{id=1, ownerId=1, area=Area{id=3, name=‘長治學院‘, priority=2, createTime=null, lastEditTime=null}, categoryId=14, name=‘new 正式店鋪名稱‘, desc=‘測試描述‘, addr=‘正式地址‘, phone=‘13810524086‘, image=‘/upload/item/shop/1/2017091621545314507.jpg‘, priority=10, createTime=2017-08-03, lastEditTime=2017-09-16, enableStatus=0, advice=‘審核中‘} |
Mybatis學習第17節 -- 嵌套查詢(多對一和一對一)