日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

mybatis学习(51):扩展集

發布時間:2023/12/10 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mybatis学习(51):扩展集 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

大部分現實應用中我們并不需要把數據庫中的整行數據都拉出來, 所以要做擴展結果集

筆記: 在實際項目過程中, 先用逆向工程自動生成, 然后再做擴展結果集來滿足大部分的現實需要

?

本節內容應該注意擴展結果集的命名方式

創建一個擴展類ShopCustom, (這樣命名可以和Shop在項目樹里面排列在一起)

package io.github.coinsjack.pojo;public class ShopCustom extends Shop {private String shopName;private String shopDesc;public ShopCustom() {}

創建一個mapper接口 ShopMapperCustom?

package io.github.coinsjack.dao;import io.github.coinsjack.pojo.ShopCustom;public interface ShopMapperCustom {ShopCustom getShopById(Integer id);}

創建對應的映射文件

<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="io.github.coinsjack.dao.ShopMapperCustom"><cache/> <resultMap id="shopResultMap" type="ShopCustom"><id column="shop_id" property="id" ></id><result column="shop_name" property="shopName"></result><result column="shop_desc" property="shopDesc"/></resultMap><select id="getShopById" parameterType="int" resultMap="shopResultMap" >select `shop_id`, `shop_name`, `shop_desc`from tb_shopwhere `shop_id` = #{id}</select> </mapper>

測試

@Test public void testGetShopByIdCustom() {SqlSession session = MyBatisUtil.getSqlSession();ShopMapperCustom mapper = session.getMapper(ShopMapperCustom.class);System.out.println(mapper.getShopById(29));session.close(); }

結果

2018-12-29 11:33:32,656 [main] DEBUG [io.github.coinsjack.dao.ShopMapperCustom] - Cache Hit Ratio [io.github.coinsjack.dao.ShopMapperCustom]: 0.0
2018-12-29 11:33:33,128 [main] DEBUG [io.github.coinsjack.dao.ShopMapperCustom.getShopById] - ==> Preparing: select `shop_id`, `shop_name`, `shop_desc` from tb_shop where `shop_id` = ??
2018-12-29 11:33:33,237 [main] DEBUG [io.github.coinsjack.dao.ShopMapperCustom.getShopById] - ==> Parameters: 29(Integer)
2018-12-29 11:33:33,309 [main] DEBUG [io.github.coinsjack.dao.ShopMapperCustom.getShopById] - <== Total: 1
ShopCustom{shopName='暴漫奶茶店', shopDesc='過來喝喝就知道啦,你是我的奶茶'}

?


Java知識點

如果父類實現了某接口,子類也會繼承接口的實現

總結

以上是生活随笔為你收集整理的mybatis学习(51):扩展集的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。