一、单个参数:
public ListgetXXBeanList(@param("id")String id); 其中方法名和ID一致,#{}中的参数名与方法中的参数名一致, 这里采用的是@Param这个参数,实际上@Param这个最后会被Mabatis封装为map类型的。 select 后的字段列表要和bean中的属性名一致, 如果不一致的可以用 as 来补充。 二、多参数:
public ListgetXXXBeanList(String xxId, String xxCode); 由于是多参数那么就不能使用parameterType, 改用#{index}是第几个就用第几个的索引,索引从0开始
public ListgetXXXBeanList(@Param("id")String id, @Param("code")String code); 由于是多参数那么就不能使用parameterType, 这里用@Param来指定哪一个 三、Map封装多参数:
public ListgetXXXBeanList(HashMap map); 其中hashmap是mybatis自己配置好的直接使用就行。map中key的名字是那个就在#{}使用那个,map如何封装就不用了我说了吧。 四、List封装in:
public ListgetXXXBeanList(List list); foreach 最后的效果是select 字段... from XXX where id in ('1','2','3','4')
五、selectList()只能传递一个参数,但实际所需参数既要包含String类型,又要包含List类型时的处理方法:
将参数放入Map,再取出Map中的List遍历。如下:
Listlist_3 = new ArrayList ();Map map2 = new HashMap (); list.add("1");
list.add("2");
- map.put("list", list); //网址id
-
- map.put("siteTag", "0");//网址类型
public ListgetSysInfo(Map map2) { return getSqlSession().selectList("sysweb.getSysInfo", map2);}