Ibatis中queryforList传入多个参数的方法

来源:互联网 发布:联想网络同传软件下载 编辑:程序博客网 时间:2024/05/23 17:53

一般情况下,我们用ibatis都是传入一个参数,这个参数可以为一个类,一个字符串,一个整型等等,例如:

<select id="selectpw" parameterClass="String" resultClass="String">
            select pwd from userinfo
            where userid=#userid#
        </select>

在方法体里可以用:password = (String)sqlMapClient.queryForObject("selectpw", userid)得到password。

但是有时候我们却想从前面传入两个或多个参数,这时候怎么办呢? -----------------用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>

这样就可以将多个参数传过去了。

0 0
原创粉丝点击