這裡是高階查詢
現在有三個表: user,role,user_role
根據三個表建立對映實體類:
class user
public class userrole
這裡把user,role 放到userrole裡是最簡單的方式,當乙個user對應多個role的時候,這樣寫取出多個role也是最方便的,有人會說為什麼不把private role roles; 換成private listroles;這是因為我們有很多業務會直接取role中的role屬性,所以使用這種方法取role屬性的時候也是最方便的。
ur.id ,
ur.u_id,
ur.r_id
u.id,
u.username,
u.password
r. id,
r. role
select ,
, ,from user_role ur
left join `user` u on u.id=ur.u_id
left join role r on
r.id=ur.r_id
where
u_id=#
這樣三個表就關聯好了。
mybatis關聯查詢
備註 1 type是實體類 2 id是唯一標識,是resulmap指定的標識 4 collection是集合對映,用於多個物件 association是用於單個物件 5 如果裡面有collection,又有association,應該把association放前面,不然會報錯 6 無論是associ...
mybatis級聯 關聯 查詢
級聯 關聯 查詢,mybatis已經有了很好的支援,配置也相當簡單,示例 一種是一對一的,一種是一結多的,association用於前者,collection用於後者。下面都有相應配置。當然一對一的,可以直接配置在一起,就不用兩次查詢了。select from school where id sel...
表關聯查詢
一 內連線和外連線 內連線用於返回滿足連線條件的記錄 而外連線則是內連線的擴充套件,它不僅會滿足連線條件的記錄,而且還會返回不滿足連線條件的記錄,語法如下 oracle 1.select table1.column,table2.column from table1 inner left right...