当在查询的时候需要传入多个参数的时候该怎么办呢:shiyong
1,封装成一个Model对象,底层HashMap还是一个
2,使用HashMap封装
3,使用注解,@param
queryUserByuserNameAndPass(String userName,String PassWord); //返回值类型为Usre
//sql
<select id="queryUserByuserNameAndPass" resultType="User">
select * from user u where u.user_name=#{userName} and u.pass_word=#{passWord}//会报错的
</select>
改为如下:
<select id="queryUserByuserNameAndPass" resultType="User">
select * from user u where u.user_name=#{0} and u.pass_word=#{1}//运行成功但是,可读性不高
</select>
//使用HashMap定义:
HashMap <String,Object> map=new HashMap<String,Object>();
map.put("userName","zhangsan");
map.put("password","123456");
queryUserByuserNameAndPass(map);//为返回值类型为User
//sql 如下:
<select id="queryUserByuserNameAndPass" resultType="User">
select * from user u where u.user_name=#{userName} and u.pass_word=#{passWord}//
</select>
ibati用HashMap封装是sql如下:
<select id="queryUserByuserNameAndPass" parameterClass="java.util.HashMap" resultType="User">
select * from user u where u.user_name=#{userName} and u.pass_word=#{passWord}
</select>