东莞企业网站建设,wordpress auto draft,佳易网页王,做网站怎么去进行链接偶然碰到一个需要给xml传一个String类型和一个Integer类型的需求#xff0c;当时心想用map感觉有点太浪费#xff0c;所以专门研究了下各种方式。方法一#xff1a;不需要写parameterType参数public List getXXXBeanList(String xxId, String xxCode);select t.* from table…偶然碰到一个需要给xml传一个String类型和一个Integer类型的需求当时心想用map感觉有点太浪费所以专门研究了下各种方式。方法一不需要写parameterType参数public List getXXXBeanList(String xxId, String xxCode);select t.* from tableName where id #{0} and name #{1}由于是多参数那么就不能使用parameterType 改用#index是第几个就用第几个的索引索引从0开始方法二基于注解(最简单)public List getXXXBeanList(Param(id)String id, Param(code)String code);select t.* from tableName where id #{id} and name #{code}由于是多参数那么就不能使用parameterType 这里用Param来指定哪一个方法三Map封装public List getXXXBeanList(HashMap map);select 字段... from XXX where id#{xxId} code #{xxCode}其中hashmap是mybatis自己配置好的直接使用就行。map中key的名字是那个就在#{}使用那个map如何封装就不用了我说了吧。方法四List封装public List getXXXBeanList(List list);select 字段... from XXX where id in#{item}总结传递list和map在资源消耗上肯定远大于方法一和方法二但是有一些特殊的情形需要传递list比如你需要传递一个id集合并批量对id进行sql操作然后再返回等等。所以都需要了解。