午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁技術(shù)文章
文章詳情頁

mybatis 多表關(guān)聯(lián)mapper文件寫法操作

瀏覽:17日期:2023-10-21 09:13:02

兩張表SystemParam(系統(tǒng)參數(shù)表) Suit (主題)

SystemParam 與 Suit 是多對(duì)一

Suit 的higerSuit字段是Suit 的父及主題id 是多對(duì)一,需要自連接查詢,因?yàn)橹孛愿副韘ql字段加別名

mapper方法

Systemparam selectJoinSuit(String strparamcode);

Po類

public class Systemparam { //ManyToOne '主題' private Suit suitobj; private String strparamcode; private String strenable; private String strparamname; //suit表主鍵 private String suit; private String strparamvalue;} public class Suit { //ManyToOne private Suit suit; //主鍵 private String strsuitcode; private String strsuitname; //父級(jí)id private String higersuit;}

resultMap的寫法

<resultMap type='net.transino.model.Systemparam' > <id column='strParamCode' property='strparamcode' jdbcType='VARCHAR' /> <result column='strEnable' property='strenable' jdbcType='VARCHAR' /> <result column='strParamName' property='strparamname' jdbcType='VARCHAR' /> <result column='suit' property='suit' jdbcType='VARCHAR' /></resultMap>

resultMap 使用extends 繼承上級(jí)map

<resultMap type='net.transino.model.Systemparam' extends='BaseResultMap' > <result column='strParamValue' property='strparamvalue' jdbcType='LONGVARCHAR' /></resultMap><resultMap type='net.transino.model.Systemparam' extends='ResultMapWithBLOBs' > <association property='suitobj' javaType='Suit'> <id column='strSuitCode' property='strsuitcode' jdbcType='VARCHAR' /> <result column='strSuitName' property='strsuitname' jdbcType='VARCHAR' /> <result column='higerSuit' property='higersuit' jdbcType='VARCHAR' /> <association property='suit' javaType='Suit'> <id column='pstrSuitCode' property='strsuitcode' jdbcType='VARCHAR' /> <result column='pstrSuitName' property='strsuitname' jdbcType='VARCHAR' /> <result column='phigerSuit' property='higersuit' jdbcType='VARCHAR' /> </association> </association></resultMap>

select寫法

<select resultMap='JoinsuitMap' parameterType='java.lang.String'> select systempara0_.*, suit1_.*, suit2_.strSuitCode pstrSuitCode, suit2_.strSuitName pstrSuitName, suit2_.higerSuit phigerSuit from SystemParam systempara0_ LEFT OUTER JOIN Suit suit1_ ON systempara0_.suit=suit1_.strSuitCode LEFT OUTER JOIN Suit suit2_ ON suit1_.higerSuit=suit2_.strSuitCode WHERE systempara0_.strParamCode=#{strparamcode,jdbcType=VARCHAR}</select>

補(bǔ)充知識(shí):Mybatis中resultMap標(biāo)簽實(shí)現(xiàn)多表查詢(多個(gè)對(duì)象)

1 n+1

1 在teacher中添加List student,

public class Teacher { private int id; private String name; private List<Student> list;

2 在studentMapper.xml中添加通過tid查詢

<select resultType='Student' parameterType='int'> select * from student where tid=#{0}</select>

3 在TeacherMapper.xml中添加查詢?nèi)?/p>

<resultMap type='Teacher' id='mymap1'> <id column='id' property='id'/> <result column='name' property='name'/> <collection property='list' ofType='Student' select='com.bjsxt.mapper.StudentMapper.selByTid' column='id'></collection></resultMap> <select resultMap='mymap1'> select * from teacher </select>

其中collection是當(dāng)屬性為集合類型時(shí)使用的標(biāo)簽

2 多表聯(lián)合

<resultMap type='Teacher' id='stumap1'> <id column='tid' property='id'/> <result column='tname' property='name'/> <collection property='list' ofType='Student'> <id column='sid' property='id'/> <result column='sname' property='name'/> <result column='age' property='age'/> <result column='tid' property='tid'/> <association property='teacher' select='com.bjsxt.mapper.TeacherMapper.selById' column='tid'></association> </collection> </resultMap> <select resultMap='stumap1'> select t.id tid,t.name tname,s.id sid,s.name sname,age,tid from teacher t left join student s on t.id=s.tid </select>

以上這篇mybatis 多表關(guān)聯(lián)mapper文件寫法操作就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。

相關(guān)文章:
主站蜘蛛池模板: 亚洲精品少妇久久久久久 | a毛片网站 | 欧美黄色录像 | 亚洲一级精品 | 天天操天天操天天操天天操 | 国产精品性| 91精品一区二区三区蜜桃 | 亚洲欧美日韩中文字幕在线观看 | 自拍偷拍校园春色 | 精品无码三级在线观看视频 | 一起草av在线 | 欧美日韩中文字幕在线观看 | 亚洲第一视频在线播放 | 免费看av大片 | 国产成人精品a视频一区 | 青青草在线视频免费观看 | 在线观看日韩一区 | 亚洲美女在线观看 | 影音先锋每日资源 | 黄色一级片在线免费观看 | 国产精品色婷婷99久久精品 | 四虎精品影院 | 琪琪色av| 不卡av网| 日韩免费高清视频 | 五月婷婷激情综合 | 蜜桃传媒一区二区 | 亚洲一二区视频 | 欧美手机在线视频 | 在线观看日韩欧美 | 日韩一区二区三区免费视频 | 水密桃av | 夫妻性生活毛片 | 国产精品久久久久久久9999 | 91精品国产吴梦梦 | 永久黄色网址 | 国产精品福利小视频 | 亚洲国产精品一区二区三区 | 国产精品久久一区 | 国产一区二区视频网站 | 蘑菇福利视频一区播放 |