IBatis查询条件为多个参数时如何配置
2014-08-06 14:21
281 查看
1) 用String代替
Java代码 String sql = "uid = '" + username + "' and pwd='" + password + "'";
Integer r = (Integer) sqlMap.queryForObject("checkLogin", sql);
Xml代码
<select id="checkLogin" parameterClass="java.lang.String" resultClass="java.lang.Integer">
SELECT count(*) AS value FROM userinfo WHERE $sql$
</select>
2)用 Map
Java代码 Map map=new HashMap();
map.put("uid", username);
map.put("pwd", password);
Integer r = (Integer) sqlMap.queryForObject("checkLogin2", map);
一种写法:
Xml代码
<select id=" " parameterClass="java.util.Map" resultClass="java.lang.Integer">
SELECT count(*) AS value FROM userinfo WHERE uid=#uid# and pwd=#pwd#
</select>
另一种写法
Xml代码
<parameterMap class="java.util.HashMap" id="parameterMap">
<parameter property="uid"/>
<parameter property="pwd"/>
</parameterMap>
<select id="checkLogin2" resultClass="java.lang.Integer" parameterMap="parameterMap">
SELECT count(*) AS value FROM userinfo WHERE uid=? and pwd=?
</select>
3)用bean
Java代码 public Student queryStudentsByNameAndId(HashMap<String,String> hashMap) {
Student s=null;
try {
s=(Student)sqlMapClient.queryForObject("selectStudentByIdAndName",hashMap);
} catch (SQLException e) {
e.printStackTrace();
}
return s;
}
Xml代码
<parameterMap class="java.util.HashMap" id="parameterMap">
<parameter property="sid"/>
<parameter property="sname"/>
</parameterMap>
<select id="selectStudentByIdAndName" resultClass="Student" parameterMap="parameterMap">
select * from student where sid=? and sname=?
</select>
相关文章推荐
- IBatis查询条件为多个参数时如何配置
- [转]iBATIS查询条件为多个参数
- struts2 笔记01 登录、常用配置参数、Action访问Servlet API 和设置Action中对象的值、命名空间和乱码处理、Action中包含多个方法如何调用
- 如何进行ibatis动态多条件组合查询以及模糊查询
- IBatisNet/IBatis动态条件查询XMl映射配置终极解决方案实例
- 如何进行ibatis动态多条件组合查询以及模糊查询
- 如何进行ibatis动态多条件组合查询以及模糊查询(oracle,mysql)
- IBATIS 查询操作 查询条件包含多个元素
- 如何进行ibatis动态多条件组合查询以及模糊查询(oracle,mysql)
- 关于存储过程中一个参数表示多个查询条件使用方法的简单处理
- IBatisNet/IBatis动态条件查询XMl映射配置终极解决方案实例
- thinkphp5多条件模糊查询以及多条件查询带分页如何保留参数
- 笔记01 登录、常用配置参数、Action访问Servlet API 和设置Action中对象的值、命名空间和乱码处理、Action中包含多个方法如何调用
- 如何在VS2008中的Language Integrated Query动态条件查询
- 如何利用XML文件,做为配置参数?
- 分页存储过程,可将查询条件作为参数传递的分页查询存储过程
- 当某个参数不传入值时,查询语句中where后面不加相应条件处理
- SQL - 如何查询某个存储过程的的所有参数:
- FAQ_DB2如何在命令行下查看修改实例和数据库配置参数
- 如何在AS/400 SQL 查询中实现条件表达式