1.对于多参数的问题:
用 Map
情形一: <select id="checkLogin2" parameterClass="java.util.Map" resultClass="java.lang.Integer"> SELECT count(*) AS value FROM userinfo WHERE uid=#uid# and pwd=#pwd# </select> 这种办法显得要清楚的很多,也不需要自己手动编写sql到java之中。 Map map=new HashMap(); map.put("uid", username); map.put("pwd", password); Integer r = (Integer) sqlMap.queryForObject("checkLogin2", map); 在java中首先生成需要的map,然后作为输入参数传入即可。这个方法应该是比较好的,值得推荐。
情形二:
在方法体里:我们把多个参数存放在map里,然后在前面获得它:
Map map = new HashMap(); map.put("userid", userid); map.put("name", name);
cardList = (List)sqlMapClient.queryForList("findByName", map);
在SQL语句中:
<select id="findByName" parameterClass="java.util.Map" resultClass="Card"> select * from cardinfo where userid=#userid# and name like '$name$' </select>
这样就可以将多个参数传过去了。