1. 程式人生 > >mybatis學習之多表關聯查詢和resultmap的常用標籤和屬性 和分頁查詢

mybatis學習之多表關聯查詢和resultmap的常用標籤和屬性 和分頁查詢

對映方式一:

resultType和resultMap都可以用但要注意欄位的名稱和pojo屬性的名稱;如果pojo屬性不夠可 採用繼承和新增屬性的方式去實現對映;

resultMap:在多表查詢的時候,查詢到多條資料,需要把資料封裝到pojo中,再把pojo放到list集合中;

resultMap中用到的屬性和標籤;

標籤:<collection  property="" ofType=""/javaType="">//返回一個list集合

<id column="" property="" >//id:唯一表示列(用來表示主鍵)

<result  column ="" property="">//對映的屬性和欄位對應

</colllection>  

<association property="”屬性" javaType="屬性所對應的型別”>//返回一個單體(一般指的是物件)

<id column="items_id" property="id"/>

<result column="items_name" property="name"/>

<result column="items_pic" property="pic"/>

</association>

property:對映的屬性名稱;

javaType:對映的屬性對應的型別;

ofType:對映屬性對應的型別;

column:資料庫表中的欄位

propert:對應pojo類的屬性

mybatis 分頁查詢外掛

推薦:com.github.pagehelper public class PageHelper ;