色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

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

mybatis 多表關聯mapper文件寫法操作

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

兩張表SystemParam(系統參數表) Suit (主題)

SystemParam 與 Suit 是多對一

Suit 的higerSuit字段是Suit 的父及主題id 是多對一,需要自連接查詢,因為重名所以父表sql字段加別名

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; //父級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 繼承上級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>

補充知識:Mybatis中resultMap標簽實現多表查詢(多個對象)

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中添加查詢全部

<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是當屬性為集合類型時使用的標簽

2 多表聯合

<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 多表關聯mapper文件寫法操作就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持好吧啦網。

標簽: Mybatis 數據庫
相關文章:
主站蜘蛛池模板: 欧美日韩精品一区二区三区不卡 | 欧美人性影片免费看 | 欧美精品黄页免费高清在线 | 精品视频亚洲 | 欧美精品久久一区二区三区 | 国产精品色午夜视频免费看 | 国产在线激情视频 | 久久综合九九亚洲一区 | 性感美女视频黄.免费网站 性高湖久久久久久久久 | 欧美透逼 | 中文字幕高清在线天堂网 | 杨幂精品国产专区91在线 | 欧美一区二区不卡视频 | 艳女伦交一级毛片 | 国产性自拍 | 欧美一级xxxx俄罗斯一级 | 欧美激情久久久久久久久 | 香蕉香蕉国产片一级一级毛片 | 极品美女户外勾搭无套 | 美女张开腿让我桶 | 午夜在线亚洲男人午在线 | 亚洲在线播放视频 | 欧美成人全部免费观看1314色 | 香焦视频在线观看黄 | 亚洲欧美一区在线 | 国内精品久久久久久久星辰影视 | 131美女爱做免费毛片 | 视频一区色眯眯视频在线 | 久久精品a | 特级毛片在线播放 | 99re这里只有精品99 | 欧美激情视频一级视频一级毛片 | 日韩欧美a级高清毛片 | 毛片免费在线观看网址 | 欧美亚洲国产成人综合在线 | 最新亚洲一区二区三区四区 | 成人久久视频 | 日本一本久 | 日韩精品亚洲人成在线观看 | 草草影院www色欧美极品 | 国产v视频|