Mybatis中的高級映射一對一、一對多、多對多
學(xué)習(xí)hibernate的時候,小編已經(jīng)接觸多各種映射,mybatis中映射有到底是如何運轉(zhuǎn)的,今天這篇博文,小編主要來簡單的介紹一下mybatis中的高級映射,包括一對一、一對多、多對多,希望多有需要的小伙伴有幫助,小編主要從四個方面進行介紹,訂單商品數(shù)據(jù)模型、一對一查詢、一對多查詢、多對多查詢。
一、訂單商品數(shù)據(jù)模型
1、數(shù)據(jù)庫執(zhí)行腳本,如下所示:
<span style="font-family:Comic Sans MS;font-size:18px;">CREATE TABLE items ( id INT NOT NULL AUTO_INCREMENT, itemsname VARCHAR(32) NOT NULL COMMENT '商品名稱', price FLOAT(10,1) NOT NULL COMMENT '商品定價', detail TEXT COMMENT '商品描述', pic VARCHAR(64) DEFAULT NULL COMMENT '商品圖片', createtime DATETIME NOT NULL COMMENT '生產(chǎn)日期', PRIMARY KEY (id) ) DEFAULT CHARSET=utf8; /*Table structure for table `orderdetail` */ CREATE TABLE orderdetail ( id INT NOT NULL AUTO_INCREMENT, orders_id INT NOT NULL COMMENT '訂單id', items_id INT NOT NULL COMMENT '商品id', items_num INT DEFAULT NULL COMMENT '商品購買數(shù)量', PRIMARY KEY (id), KEY `FK_orderdetail_1` (`orders_id`), KEY `FK_orderdetail_2` (`items_id`), CONSTRAINT `FK_orderdetail_1` FOREIGN KEY (`orders_id`) REFERENCES `orders` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `FK_orderdetail_2` FOREIGN KEY (`items_id`) REFERENCES `items` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION ) DEFAULT CHARSET=utf8; /*Table structure for table `orders` */ CREATE TABLE orders ( id INT NOT NULL AUTO_INCREMENT, user_id INT NOT NULL COMMENT '下單用戶id', number VARCHAR(30) NOT NULL COMMENT '訂單號', createtime DATETIME NOT NULL COMMENT '創(chuàng)建訂單時間', note VARCHAR(100) DEFAULT NULL COMMENT '備注', PRIMARY KEY (`id`), KEY `FK_orders_1` (`user_id`), CONSTRAINT `FK_orders_id` FOREIGN KEY (`user_id`) REFERENCES `t_user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION ) DEFAULT CHARSET=utf8; /*Table structure for table `t_user` */ CREATE TABLE t_user ( id INT NOT NULL AUTO_INCREMENT, username VARCHAR(32) NOT NULL COMMENT '用戶名稱', birthday DATE DEFAULT NULL COMMENT '生日', sex CHAR(1) DEFAULT NULL COMMENT '性別', address VARCHAR(256) DEFAULT NULL COMMENT '地址', PRIMARY KEY (`id`) ) DEFAULT CHARSET=utf8; </span>
測試數(shù)據(jù)代碼
<span style="font-family:Comic Sans MS;font-size:18px;">/*Data for the table `items` */ INSERT INTO items(itemsname,price,detail,pic,createtime) VALUES ('臺式機',3000.0,'該電腦質(zhì)量非常好!',NULL,'2015-07-07 13:28:53'), ('筆記本',6000.0,'筆記本性能好,質(zhì)量好!',NULL,'2015-07-08 13:22:57'), ('背包',200.0,'名牌背包,容量大質(zhì)量好!',NULL,'2015-07-010 13:25:02'); /*Data for the table `orderdetail` */ INSERT INTO `orderdetail`(`orders_id`,`items_id`,`items_num`) VALUES (1,1,1), (1,2,3), (2,3,4), (3,2,3); /*Data for the table `orders` */ INSERT INTO `orders`(`user_id`,`number`,`createtime`,`note`) VALUES (1,'1000010','2015-06-04 13:22:35',NULL), (1,'1000011','2015-07-08 13:22:41',NULL), (2,'1000012','2015-07-17 14:13:23',NULL), (3,'1000012','2015-07-16 18:13:23',NULL), (4,'1000012','2015-07-15 19:13:23',NULL), (5,'1000012','2015-07-14 17:13:23',NULL), (6,'1000012','2015-07-13 16:13:23',NULL); /*Data for the table `user` */ INSERT INTO `t_user`(`username`,`birthday`,`sex`,`address`) VALUES ('王五',NULL,'2',NULL), ('張三','2014-07-10','1','北京市'), ('張小明',NULL,'1','河南鄭州'), ('陳小明',NULL,'1','河南鄭州'), ('張三豐',NULL,'1','河南鄭州'), ('陳小明',NULL,'1','河南鄭州'), ('王五',NULL,NULL,NULL), ('小A','2015-06-27','2','北京'), ('小B','2015-06-27','2','北京'), ('小C','2015-06-27','1','北京'), ('小D','2015-06-27','2','北京'); </span>
2、數(shù)據(jù)模型分析思路
(1).每張表記錄的數(shù)據(jù)內(nèi)容:分模塊對每張表記錄的內(nèi)容進行熟悉,相當(dāng) 于你學(xué)習(xí)系統(tǒng) 需求(功能)的過程;
(2).每張表重要的字段設(shè)置:非空字段、外鍵字段;
(3).數(shù)據(jù)庫級別表與表之間的關(guān)系:外鍵關(guān)系;
(4).表與表之間的業(yè)務(wù)關(guān)系:在分析表與表之間的業(yè)務(wù)關(guān)系時一定要建立在某個業(yè)務(wù)意義基礎(chǔ)上去分析。
3、針對訂單商品模型的數(shù)據(jù)庫思路分析,如下圖所示:
二、一對一查詢
2.1、需求:查詢訂單信息,關(guān)聯(lián)查詢用戶信息
2.2、resultType實現(xiàn)
2.2.1sql語句
確定查詢的主表:訂單表,確定查詢的關(guān)聯(lián)表,用戶表,代碼如下所示:
<span style="font-family:Comic Sans MS;font-size:18px;">SELECT t1.*, t2.username, t2.sex, t2.address FROM orders t1, t_user t2 WHERE t1.user_id=t2.id </span>
2.2.2創(chuàng)建entity實體
用戶實體User.java,代碼如下所示:
<span style="font-family:Comic Sans MS;font-size:18px;">package com.mybatis.entity; import java.util.Date; import java.util.List; /** * @ClassName: User * @Description: TODO(用戶實體) * @author 阿赫瓦里 */ public class User { private Integer id; // 姓名 private String username; // 性別 private String sex; // 地址 private String address; // 生日 private Date birthday; // 用戶創(chuàng)建的訂單列表 private List<Orders> ordersList; // getter and setter ...... } </span>
訂單實體orders.java
<span style="font-family:Comic Sans MS;font-size:18px;">package com.mybatis.entity; import java.util.Date; import java.util.List; /** * @ClassName: Orders * @Description: TODO(訂單實體) * @author 阿赫瓦里 */ public class Orders { /** 主鍵訂單Id */ private Integer id; /** 下單用戶id */ private Integer userid; /** 訂單號 */ private String number; /** 創(chuàng)建訂單時間 */ private Date createTime; /** 備注 */ private String note; // 用戶信息 private User user; // 訂單明細 private List<OrderDetail> orderdetails; // getter and setter ...... } </span>
商品實體:items.java
<span style="font-family:Comic Sans MS;font-size:18px;">package com.mybatis.entity; import java.util.Date; /** * @ClassName: Items * @Description: TODO(商品實體類) * @author 丁國華 */ public class Items { /** 商品表主鍵Id */ private Integer id; /** 商品名稱 */ private String itemsName; /** 商品定價 */ private float price; /** 商品描述 */ private String detail; /** 商品圖片 */ private String picture; /** 生產(chǎn)日期 */ private Date createTime; // getter and setter ...... } </span>
訂單明細實體orderDetail.java
<span style="font-family:Comic Sans MS;font-size:18px;">package com.mybatis.entity; /** * @ClassName: OrderDetail * @Description: TODO(訂單明細實體) * @author 丁國華 */ public class OrderDetail { /** 主鍵,訂單明細表Id */ private Integer id; /** 訂單Id */ private Integer ordersId; /** 商品id */ private Integer itemsId; /** 商品購買數(shù)量 */ private Integer itemsNum; // 明細對應(yīng)的商品信息 private Items items; // getter and setter ...... } </span>
創(chuàng)建一個包裝類,將查詢到的信息全部映射到此類OrdersCustom.java
<span style="font-family:Comic Sans MS;font-size:18px;">/** * @ClassName: OrdersCustom * @Description: TODO(訂單的擴展類,通過此類映射訂單和用戶的查詢結(jié)果,讓此類繼承字段較多的實體類) * @author: 丁國華 */ public class OrdersCustom extends Orders { // 添加用戶的屬性 private String username; private String sex; private String address; // getter and setter...... } </span>
2.2.3創(chuàng)建OrderscCustomMapper.java,代碼如下所示:
<span style="font-family:Comic Sans MS;font-size:18px;">package com.mybatis.Mapper; import java.util.List; import com.mybatis.entity.OrdersCustom; /** * @ClassName: OrdersMapperCustom * @Description: TODO(OrdersMapperCustom的mapper) * @author 丁國華 */ public interface OrdersCustomMapper { /** 查詢訂單,關(guān)聯(lián)查詢用戶信息 */ public List<OrdersCustom> findOrdersUser(); } </span>
2.2.4創(chuàng)建OrdersCustomMapper.xml和上面對應(yīng)的接口名稱一致,一邊通過mapper接口加載配置文件,代碼如下所示:
<span style="font-family:Comic Sans MS;font-size:18px;"><?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!-- namespace命名空間,作用就是對sql進行分類化的管理,理解為sql隔離 注意:使用mapper代理開發(fā)時,namespace有特殊作用,namespace等于mapper接口地址 --> <mapper namespace="com.mybatis.mapper.OrdersCustomMapper"> <!-- 查詢訂單,關(guān)聯(lián)查詢用戶信息 --> <select id="findOrdersUser" resultType="com.mybatis.entity.OrdersCustom"> SELECT t1.*, t2.username, t2.sex, t2.address FROM orders t1, t_user t2 WHERE t1.user_id=t2.id </select> </mapper> </span>
2.3resultMap實現(xiàn)
2.3.1sql語句同上
2.3.2resultMap映射思路:
使用resultMap將查詢結(jié)果中的訂單信息映射到Orders對象中,在orders類中添加User屬性,將關(guān)聯(lián)查詢出來的用戶信息映射到orders對象中的user屬性中(上面orders實體中已經(jīng)添加)。
2.3.3 ordersCustomMapper.xml
1、定義resultMap,代碼如下所示:
<span style="font-family:Comic Sans MS;font-size:18px;"><!-- 定義查詢訂單關(guān)聯(lián)用戶的 resultMap,將整個的查詢結(jié)果映射到com.mybatis.entity.Orders中 --> <resultMap type="com.mybatis.entity.Orders" id="OrdersUserResultMap"> <!-- 配置映射的訂單信息 --> <!-- id:查詢列中的唯一標(biāo)識,訂單信息中的唯一標(biāo)識,如果多列組成唯一標(biāo)識(如:一般數(shù)據(jù)庫設(shè)計中的字典表 使用聯(lián)合主鍵),就需要配置多個id column:訂單信息的唯一標(biāo)識 列 property:訂單信息的唯一標(biāo)識列所映射到orders中的那個屬性(假如:數(shù)據(jù)庫中orders表中的主鍵為orders_id,而實體屬性名稱為ordersId, 則這個配置應(yīng)為<id column="orders_id" property="ordersId"/>,類似hibernate實體映射文件配置)。 --> <id column="id" property="id"/> <result column="user_id" property="userid"/> <result column="number" property="number"/> <result column="createtime" property="createTime"/> <result column="note" property="note"/> <!-- 配置映射的關(guān)聯(lián)用戶信息 --> <!--association:用于映射關(guān)聯(lián)查詢單個對象的信息 property:要將關(guān)聯(lián)查詢的用戶信息映射到Orders中那個屬性 --> <association property="user" javaType="com.mybatis.entity.User"> <!-- id:關(guān)聯(lián)查詢用戶的唯一標(biāo)識 column:指定唯一標(biāo)識用戶信息的列 property:映射到user的那個屬性 --> <id column="user_id" property="id"/> <result column="username" property="username"/> <result column="sex" property="sex"/> <result column="address" property="address"/> </association> </resultMap> </span>
2、statement定義,代碼如下所示:
<span style="font-family:Comic Sans MS;font-size:18px;"><!-- 查詢訂單,關(guān)聯(lián)查詢用戶信息,使用resultMap實現(xiàn) --> <select id="findOrdersUserResultMap" resultMap="OrdersUserResultMap"> SELECT t1.*, t2.username, t2.sex, t2.address FROM orders t1, t_user t2 WHERE t1.user_id=t2.id </select></span>
3、OrderCustomMapper.java接口中添加下面的方法:
<span style="font-family:Comic Sans MS;font-size:18px;">/** 查詢訂單關(guān)聯(lián)查詢用戶信息,使用reslutMap實現(xiàn)*/ public List<Orders>findOrdersUserResultMap(); </span>
4、對resultType和resultMap實現(xiàn)的junit測試,代碼如下所示:
<span style="font-family:Comic Sans MS;font-size:18px;">package com.mybatis.test; import java.io.InputStream; import java.util.List; import org.apache.ibatis.io.Resources; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; import org.junit.Before; import org.junit.Test; import com.mybatis.entity.Orders; import com.mybatis.entity.OrdersCustom; import com.mybatis.mapper.OrdersCustomMapper; public class OrdersCustomMapperTest { private SqlSessionFactory sqlSessionFactory; // 此方法是在執(zhí)行findUserByIdTest之前執(zhí)行 @Before public void setUp() throws Exception { String resource = "SqlMapConfig.xml"; InputStream inputStream = Resources.getResourceAsStream(resource); // 創(chuàng)建SqlSessionFcatory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); } // 查詢訂單,關(guān)聯(lián)查詢用戶信息,使用resultType實現(xiàn)的測試 @Test public void TestFindOrdersUser() { SqlSession sqlSession = sqlSessionFactory.openSession(); // 創(chuàng)建代理對象 OrdersCustomMapper oc = sqlSession.getMapper(OrdersCustomMapper.class); // 調(diào)用mapper的方法 List<OrdersCustom> list = oc.findOrdersUser(); System.out.println(list); sqlSession.close(); } // 查詢訂單,關(guān)聯(lián)查詢用戶信息,使用resultMap實現(xiàn)的測試 @Test public void TestFindOrdersUserResultMap() { SqlSession sqlSession = sqlSessionFactory.openSession(); // 創(chuàng)建代理對象 OrdersCustomMapper oc = sqlSession.getMapper(OrdersCustomMapper.class); // 調(diào)用mapper的方法 List<Orders> list = oc.findOrdersUserResultMap(); System.out.println(list); sqlSession.close(); } } </span>
5、resultType和resultMap實現(xiàn)一對一查詢小結(jié)
實現(xiàn)一對一查詢:
a.resultType:使用resultType實現(xiàn)較為簡單,如果pojo中沒有包括查詢出來的列名,需要增加列名對應(yīng)的屬性,即可完成映射。
b.如果沒有查詢結(jié)果的特殊要求建議使用resultType。
c.resultMap:需要單獨定義resultMap,實現(xiàn)有點麻煩,如果對查詢結(jié)果有特殊的要求,使用resultMap可以完成將關(guān)聯(lián)查詢映射pojo的屬性中。
d.resultMap可以實現(xiàn)延遲加載,resultType無法實現(xiàn)延遲加載。
三、一對多查詢
3.1 需求:查詢訂單(關(guān)聯(lián)用戶)及訂單明細;
3.2 在orders.java類中添加List<orderDetail> orderDetails屬性(上面實體已添加)。最終會將訂單信息映射到orders中,訂單所對應(yīng)的訂單明細映射到orders中的orderDetails屬性中。
3.3 在ordersCustomMapper.xml中添加如下
<span style="font-family:Comic Sans MS;font-size:18px;"><!-- 查詢訂單關(guān)聯(lián)查詢用戶及訂單明細 --> <select id="findOrdersAndOrderDetailResultMap" resultMap="ordersAndOrderDetailResultMap"> SELECT t1.*, t2.username, t2.sex, t2.address, t3.id orderdetail_id, t3.items_id, t3.items_num, t3.orders_id FROM orders t1, t_user t2, orderdetail t3 WHERE t1.user_id = t2.id AND t3.orders_id=t1.id </select> </span>
resultMap的定義同樣添加到ordersCustomMapper.xml
<span style="font-family:Comic Sans MS;font-size:18px;"><!-- 查詢訂單(關(guān)聯(lián)用戶)及訂單明細的resultMap --> <resultMap type="com.mybatis.entity.Orders" id="ordersAndOrderDetailResultMap" extends="OrdersUserResultMap"> <!-- 訂單信息 --> <!-- 關(guān)聯(lián)用戶信息 --> <!-- 使用extends繼承,不用在中配置訂單信息和用戶信息的映射--> <!-- 關(guān)聯(lián)訂單明細信息 一個訂單關(guān)聯(lián)查詢出了多條訂單明細,要使用collection映射 collection:對關(guān)聯(lián)查詢到的多條記錄映射到集合中 property:將關(guān)聯(lián)查詢到的多條記錄映射到orders類的那個屬性 ofType:指定映射的集合屬性中pojo的類型 --> <collection property="orderdetails" ofType="com.mybatis.entity.OrderDetail"> <!-- id:唯一標(biāo)識 property:要將訂單明細的唯一標(biāo)識映射到com.mybatis.entity.OrderDetail的那個屬性 --> <id column="orderdetail_id" property="id"/> <result column="items_id" property="itemsId"/> <result column="items_num" property="itemsNum"/> <result column="orders_id" property="ordersId"/> </collection> </resultMap> </span>
3.4 在OrderCustomeMapper.java接口類中添加一個方法,代碼如下所示:
<span style="font-family:Comic Sans MS;font-size:18px;">/**查詢訂單(關(guān)聯(lián)用戶)以及訂單明細*/ public List<OrderDetail>findOrdersAndOrderDetailResultMap(); </span>
3.5 在Junit測試類中添加測試方法,代碼如下所示:
<span style="font-family:Comic Sans MS;font-size:18px;">// 查詢訂單(關(guān)聯(lián)用戶)以及訂單明細的測試 @Test public void TestFindOrdersAndOrderDetailResultMap() { SqlSession sqlSession = sqlSessionFactory.openSession(); // 創(chuàng)建代理對象 OrdersCustomMapper oc = sqlSession.getMapper(OrdersCustomMapper.class); // 調(diào)用mapper的方法 List<OrderDetail> list = oc.findOrdersAndOrderDetailResultMap(); System.out.println(list); sqlSession.close(); } </span>
3.6 小結(jié)
mybatis使用resultMap的collection對關(guān)聯(lián)查詢的多條記錄映射到一個list集合屬性中。使用resultType實現(xiàn):將訂單明細映射到orders中的orderdetails中,需要自己處理,使用雙重循環(huán)遍歷,去掉重復(fù)記錄,將訂單明細放在orderdetails中。
四、多對多查詢
4.1 需求:查詢用戶以及用戶購買的商品信息
4.2 映射思路
將用戶信息映射到user中,在user類中添加訂單列表屬性List<Orders>orderslist,將用戶創(chuàng)建的訂單映射到orderslist;在Orders中添加訂單明細列表屬性List<OrderDetail>orderdetials,將訂單的明細映射到orderdetials;在OrderDetail中添加Items屬性,將訂單明細所對應(yīng)的商品映射到Item。
4.3 OrdersCustomMapper.xml添加如下代碼:
<span style="font-family:Comic Sans MS;font-size:18px;"><!-- 查詢用戶即購買的商品信息的ResultMap --> <resultMap type="com.mybatis.entity.User" id="userAndItemsResultMap"> <!-- 用戶信息 --> <id column="user_id" property="id"/> <result column="username" property="username"/> <result column="sex" property="sex"/> <result column="address" property="address"/> <!-- 訂單信息 一個用戶對應(yīng)多個訂單,使用collection映射 --> <collection property="ordersList" ofType="com.mybatis.entity.Orders"> <id column="id" property="id"/> <result column="user_id" property="userid"/> <result column="number" property="number"/> <result column="createtime" property="createTime"/> <result column="note" property="note"/> <!-- 訂單明細 一個訂單包括 多個明細 --> <collection property="orderdetails" ofType="com.mybatis.entity.OrderDetail"> <id column="orderdetail_id" property="id"/> <result column="items_id" property="itemsId"/> <result column="items_num" property="itemsNum"/> <result column="orders_id" property="ordersId"/> <!-- 商品信息 一個訂單明細對應(yīng)一個商品 --> <association property="items" javaType="com.mybatis.entity.Items"> <id column="items_id" property="id"/> <result column="items_name" property="itemsName"/> <result column="items_detail" property="detail"/> <result column="items_price" property="price"/> </association> </collection> </collection> </resultMap> <!-- 查詢用戶及用戶購買的商品信息,使用resulaMap--> <select id="findUserAndItemsResultMap" resultMap="userAndItemsResultMap"> SELECT t1.*, t2.username, t2.sex, t2.address, t3.id orderdetail_id, t3.items_id, t3.items_num, t3.orders_id, t4.itemsname items_name, t4.detail items_detail, t4.price items_price FROM orders t1, t_user t2, orderdetail t3, items t4 WHERE t1.user_id = t2.id AND t3.orders_id=t1.id AND t3.items_id = t4.id </select> </span>
4.4 在OrderCustomMapper.java中添加如下方法:
<span style="font-family:Comic Sans MS;font-size:18px;"> /** 查詢用戶及用戶所購買的商品信息 */ public List<User> findUserAndItemsResultMap(); </span>
4.5 在Junit測試中添加測試方法,代碼如下所示:
<span style="font-family:Comic Sans MS;font-size:18px;">// 查詢用戶及用戶購買的商品的信息 @Test public void TestFindUserAndItemsResultMap() { SqlSession sqlSession = sqlSessionFactory.openSession(); // 創(chuàng)建代理對象 OrdersCustomMapper oc = sqlSession.getMapper(OrdersCustomMapper.class); // 調(diào)用mapper的方法 List<User> list = oc.findUserAndItemsResultMap(); System.out.println(list); sqlSession.close(); } </span>
4.6 resultMap總結(jié)
resultType:
作用:將查詢結(jié)果按照sql列名pojo屬性名一致性映射到pojo中。
場合:常見一些明細記錄的展示,比如用戶購買商品明細,將關(guān)聯(lián)查詢信息全部展示在頁面時,此時可直接使用resultType將每一條記錄映射到pojo中,在前端頁面遍歷list(list中是pojo)即可。
resultMap:
使用:association和collection完成一對一和一對多高級映射(對結(jié)果有特殊的映射要求)。
association:
作用:將關(guān)聯(lián)查詢信息映射到一個pojo對象中。
場合:為了方便查詢關(guān)聯(lián)信息可以使用association將關(guān)聯(lián)訂單信息映射為用戶對象的pojo屬性中,比如:查詢訂單及關(guān)聯(lián)用戶信息。
使用resultType無法將查詢結(jié)果映射到pojo對象的pojo屬性中,根據(jù)對結(jié)果集查詢遍歷的需要選擇使用resultType還是resultMap。
collection:
作用:將關(guān)聯(lián)查詢信息映射到一個list集合中。
場合:為了方便查詢遍歷關(guān)聯(lián)信息可以使用collection將關(guān)聯(lián)信息映射到list集合中,比如:查詢用戶權(quán)限范圍模塊及模塊下的菜單,可使用collection將模塊映射到模塊list中,將菜單列表映射到模塊對象的菜單list屬性中,這樣的作的目的也是方便對查詢結(jié)果集進行遍歷查詢。
如果使用resultType無法將查詢結(jié)果映射到list集合中。
以上所述是小編給大家介紹的Mybatis中的高級映射一對一、一對多、多對多,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
- Mybatis中一對多(collection)和一對一(association)的組合查詢使用
- Mybatis實現(xiàn)一對一、一對多關(guān)聯(lián)查詢的方法(示例詳解)
- 關(guān)于mybatis一對一查詢一對多查詢遇到的問題
- Mybatis使用@one和@Many實現(xiàn)一對一及一對多關(guān)聯(lián)查詢
- springboot整合mybatis-plus基于注解實現(xiàn)一對一(一對多)查詢功能
- mybatis 一對一、一對多和多對多查詢實例代碼
- Mybatis 中的一對一,一對多,多對多的配置原則示例代碼
- mybatis中一對一、一對多的<association> 配置使用
相關(guān)文章
關(guān)于Spring MVC同名參數(shù)綁定問題的解決方法
Spring MVC中的參數(shù)綁定還是蠻重要的,最近在使用中遇到了同名參數(shù)綁定的問題,想著總結(jié)分享出來,下面這篇文章主要給大家介紹了關(guān)于Spring MVC同名參數(shù)綁定問題的解決方法,需要的朋友可以參考借鑒,下面來一起看看吧。2017-08-08java實現(xiàn)音頻轉(zhuǎn)文本的實現(xiàn)步驟
本文主要介紹了java實現(xiàn)音頻轉(zhuǎn)文本的實現(xiàn)步驟,可以通過使用一些現(xiàn)成的庫或者API來實現(xiàn),文中通過示例代碼介紹的非常詳細,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2024-05-05如何在SpringBoot中添加攔截器忽略請求URL當(dāng)中的指定字符串
這篇文章主要介紹了在SpringBoot中添加攔截器忽略請求URL當(dāng)中的指定字符串,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-08-08完美解決Spring Boot前端的Access-Control-Allow-Origin跨域問題
這篇文章主要介紹了完美解決Spring Boot前端的Access-Control-Allow-Origin跨域問題,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-05-05Java實現(xiàn)數(shù)據(jù)連接池Druid舉例
本文主要介紹了Java實現(xiàn)數(shù)據(jù)連接池Druid舉例,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-03-03IDEA使用jformdesigner插件做管理系統(tǒng)MVC架構(gòu)的步驟和實現(xiàn)思路
在?IntelliJ?IDEA?中結(jié)合?JFormDesigner?插件,通過?Swing?框架實現(xiàn)一個管理系統(tǒng)的?MVC?架構(gòu)是一種經(jīng)典的開發(fā)方式,以下是具體的步驟和實現(xiàn)思路,包含從項目創(chuàng)建到?MVC?架構(gòu)的核心代碼實現(xiàn),需要的朋友可以參考下2024-12-12