(一)單個參數
public List getXXBeanList(String xxCode);
select 字段… from XXX where code = #{xxCode}
其中方法名和ID一致,#{}中的參數名與方法中的參數名一直, 我這裏採用的是XXXBean是採用的短名字, select 後的字段列表要和bean中的屬性名一致, 如果不一致的可以用 as 來補充。
(二)多參數
public List getXXXBeanList(String xxId, String xxCode);
select 字段… from XXX where id=#{0} code = #{1}
由於是多參數那麼就不能使用parameterType, 改用#{index}是第幾個就用第幾個的索引,索引從0開始
(三)Map封裝多參數
public List getXXXBeanList(HashMap map);
select 字段… from XXX where id=#{xxId} code = #{xxCode}
其中hashmap是mybatis自己配置好的直接使用就行。map中key的名字是那個就在#{}使用那個,map如何封裝就不用了我說了吧。
(四)List封裝IN
public List getXXXBeanList(List list);
select 字段… from XXX where id in
(五)多參數傳遞之註解方式示
@Param(“xxx”) int xxx
(六)實體
select * from Teacher where c_id=#{id}
[java] view plain copy
java代碼
Teacher queryTeacher=new Teacher();
queryTeacher.setId(2);
List tList = teacherMapper.selectTeacher(queryTeacher);
for (Teacher entityTemp : tList) {
System.out.println(entityTemp.toString()); }