一、單個引數:
public List<XXBean> getXXBeanList(String xxCode);
<select id="getXXXBeanList" parameterType="java.lang.String" resultType="XXBean">
  select t.* from tableName t where t.id=
</select>
其中方法名和ID一致,
select 後的欄位列表要和bean中的屬性名一致, 如果不一致的可以用 as 來補充。
複製程式碼
二、多引數:
public List<XXXBean> getXXXBeanList(String xxId, String xxCode);
<select id="getXXXBeanList" resultType="XXBean">
  select t.* from tableName where id =
</select>
由於是多引數那麼就不能使用parameterType, 改用
複製程式碼
三、Map封裝多引數:
public List<XXXBean> getXXXBeanList(HashMap map);
<select id="getXXXBeanList" parameterType="hashmap" resultType="XXBean">
  select 欄位... from XXX where id=
</select>
其中hashmap是mybatis自己配置好的直接使用就行。map中key的名字是那個就在
複製程式碼
四、List封裝in:
public List<XXXBean> getXXXBeanList(List<String> list);
<select id="getXXXBeanList" resultType="XXBean">
  select 欄位... from XXX where id in
  <foreach item="item" index="index" collection="list" open="(" separator="," close=")">
    
  </foreach>
</select>
foreach 最後的效果是select 欄位... from XXX where id in ('1','2','3','4')
複製程式碼
五、多引數傳遞之註解方式示:
例子:
public AddrInfo getAddrInfo(@Param("corpId")int corpId, @Param("addrId")int addrId);
xml配置這樣寫:
<select id="getAddrInfo" resultMap="com.xxx.xxx.AddrInfo">
SELECT * FROM addr__info
    where addr_id=
</select>
以前在<select>語句中要帶parameterType的,現在可以不要這樣寫。
複製程式碼
六、selectList()只能傳遞一個引數,但實際所需引數既要包含String型別,又要包含List型別時的處理方法:
List<String> list_3 = new ArrayList<String>();
Map<String, Object> map2 = new HashMap<String, Object>();
list.add("1");
list.add("2");
map2.put("list", list); //網址id
map2.put("siteTag", "0");//網址型別
複製程式碼
public List<SysWeb> getSysInfo(Map<String, Object> map2) {
  return getSqlSession().selectList("sysweb.getSysInfo", map2);
}
複製程式碼
<select id="getSysInfo" parameterType="java.util.Map" resultType="SysWeb">
  select t.sysSiteId, t.siteName, t1.mzNum as siteTagNum, t1.mzName as siteTag, t.url, t.iconPath
from TD_WEB_SYSSITE t
left join TD_MZ_MZDY t1 on t1.mzNum = t.siteTag and t1.mzType = 10
WHERE t.siteTag =
and t.sysSiteId not in
<foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
</foreach>
</select>
複製程式碼
WiHongNoteBook