国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

MyBatis映射文件resultMap元素中使用多個association的方法

瀏覽:5日期:2023-10-19 16:35:00

現在有一張訂單表t_stockorder,其擁有id、code、client_id、merchandise_id、merchandise_number、order_date、operator_id這些字段,其中client_id關聯t_client表中code字段,merchandise_id關聯t_merchandise表的code字段,operator_id關聯t_employee表的code字段。

現在要通過SQL語句將訂單表中t_stockorder的數據全部查詢出來,SQL語句如下所示:

select so.id, so.code, c.name cname, m.name mname, so.merchandise_number, so.order_date, e.name ename from inventory.t_stockorder so inner join inventory.t_client c on c.code = so.client_id inner join inventory.t_merchandise m on m.code = so.merchandise_id inner join inventory.t_employee e on e.code = so.operator_id

現在要在mapper映射文件中添加動態Sql語句,一般情況下映射文件中的resultMap元素中只可以有一個association,那如何添加多個association到resultMap中呢?正確代碼如下圖所示:

<resultMap type='com.lwz.entity.Stockorder'> <id property='id' column='id' /> <result property='code' column='code' /> <result property='merchandiseNumber' column='merchandise_number' /> <result property='orderDate' column='order_date' /> <association property='client' javaType='Client' resultMap='ClientResultMap'></association> <association property='merchandise' javaType='Merchandise' resultMap='MerchandiseResultMap'></association> <association property='employee' javaType='Employee' resultMap='EmployeeResultMap'></association> </resultMap> <resultMap type='com.lwz.entity.Client'> <id property='code' column='code' /> <result property='name' column='cname' /> </resultMap> <resultMap type='com.lwz.entity.Merchandise'> <id property='code' column='code' /> <result property='name' column='mname' /> </resultMap> <resultMap type='com.lwz.entity.Employee'> <id property='code' column='code' /> <result property='name' column='ename' /> </resultMap> <!--通過實體作為篩選條件查詢--> <select resultMap='StockorderMap'> select so.id, so.code, c.name cname, m.name mname, so.merchandise_number, so.order_date, e.name ename from inventory.t_stockorder so inner join inventory.t_client c on c.code = so.client_id inner join inventory.t_merchandise m on m.code = so.merchandise_id inner join inventory.t_employee e on e.code = so.operator_id <where> <if test='id != null'>and id = #{id} </if> <if test='code != null and code != ’’'>and so.code = #[code] </if> <if test='client != null'>and client_id = #{client.code} </if> <if test='merchandise != null'>and merchandise_id = #{merchandise.code} </if> <if test='merchandiseNumber != null'>and merchandise_number = #{merchandiseNumber} </if> <if test='orderDate != null'>and order_date = #{orderDate} </if> <if test='employee != null'>and operator_id = #{employee.code} </if> </where> </select>

resultMap中association的各個屬性的含義:

property:映射實體類的字段或屬性。 colum:數據庫的列名或者列標簽別名。 javaTyp:完整java類名或別名。 jdbcType支持的JDBC類型列表列出的JDBC類型。這個屬性只在insert,update或delete的時候針對允許空的列有用。 resultMap: 一個可以映射聯合嵌套結果集到一個適合的對象視圖上的ResultMap。這是一個替代的方式去調用另一個select語句。

到此這篇關于MyBatis映射文件resultMap元素中使用多個association的方法的文章就介紹到這了,更多相關MyBatis 多個association內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Mybatis 數據庫
相關文章:
主站蜘蛛池模板: 欧美国产日韩一区二区三区 | 欧美日韩性视频一区二区三区 | 精品三级国产一区二区三区四区 | 亚洲经典在线 | 91久久精品一区二区 | 亚洲精品国产免费 | 欧美另类高清xxxxx | 一级做a爰片久久毛片人呢 一级做a爰片久久毛片唾 | 麻豆国产一区 | 午夜爽爽爽 | 国产乱子伦在线观看不卡 | 亚洲福利视频一区二区三区 | 久草免费在线色站 | 亚洲精品一区二区三区在 | 性生活免费视频网站 | 日韩欧美在线观看视频一区二区 | 一级做a毛片在线看 | 99超级碰碰成人香蕉网 | 亚洲国产经典 | 欧美一区二区三区日韩免费播 | 久久一本色系列综合色 | 女人a级毛片 | 欧美黄色网络 | 亚洲国产日产韩国欧美综合 | 久久视频这里只有精品 | tom影院亚洲国产 | 国产在线高清不卡免费播放 | 国产视频亚洲 | 国产精品1区 | 长腿校花被啪到腿软视频 | 国产亚洲欧美在线播放网站 | 亚洲 欧美 在线观看 | 日本免费大黄在线观看 | 久久精品大片 | 免费黄色毛片视频 | 国产高清一级毛片在线不卡 | 欧美在线日韩在线 | 一级欧美视频 | 国产精品日韩专区 | 久久精品最新免费国产成人 | 国产日比视频 |