MyBatis的坑(Parameter 'XXX' not found)
来源:互联网 发布:淘宝海运到美国 编辑:程序博客网 时间:2024/06/05 07:20
MyBatis(Parameter ‘XXX’ not found)
在今天的工作中,使用了MyBatis这个框架进行查询,但是在使用时遇见了一个问题:具体的需求是这样的,因为公司项目的需求,我需要做一个查询,这个查询是结合了模糊查询和IN查询;这个模糊查询的条件是一个String类型,而IN查询的参数则是一个Set集合。在刚开始的时候,我在Mapper.class中声明如下
public List<ApiManager> getByName(String companyName,Set<Integer> set);
然后我在Mapper.xml中做了如下的配置
<select id="getByName" resultMap="apimanagermap"> select <include refid="common"></include> from api_manage where CompanyName like CONCAT(CONCAT('%',#{companyName}),'%') and Id in <foreach item="item" index="index" collection="list" open="(" separator="," close=")"> #{item} </foreach></select>
结果没想到程序一运行,我执行查询时,就出Bug了,这个报错的信息如下
org.apache.ibatis.binding.BindingException: Parameter 'XXX' not found.
看到这里,我想你就明白这是什么问题了:这个是由于在执行sql的时候无法匹配sql语句的通配符造成的。面对这样的问题如何修改,尤其是当我们遇见多参数时,该如何去处理参数,才能正确的执行查询呢,在这里我推荐一种方式,我个人觉得比较方便:那就是把参数封装成Map,在使用Hibernate时,我也会根据具体情况把参数封装成Map来做一个动态的条件查询。于是乎,我的代码就变成了下面的形式
Mapper.class:
public List<ApiManager> getByName(Map<String, Object> map);
Mapper.xml
<select id="getByName" resultMap="apimanagermap"> select <include refid="common"></include> from api_manage where Id in <foreach item="item" index="index" collection="set" open="(" separator="," close=")"> #{item} </foreach> and CompanyName like CONCAT(CONCAT('%',#{companyName}),'%') </select>
其实查询的数据库代码没怎么做修改,只是先查了一下主键,减少查询范围,这样能提高一下查询的效率。在Service层调用这个Mapper中的方法时,把查询的参数先封装成一个Map,这个Map的键和查询的条件名要相同。
阅读全文
0 0
- MyBatis的坑(Parameter 'XXX' not found)
- mybatis Parameter 'XXX' not found问题
- Parameter xxx not found.
- Mybatis异常 Parameter "..." not found
- Mybatis出现Parameter not found
- ibatis.binding.BindingException: Parameter 'XXX' not found
- ibatis.binding.BindingException: Parameter 'xxx' not found
- Mybatis错误:Parameter 'XXX' not found. Available parameters are [1, 0, param1, param2]
- Mybatis错误:Parameter 'XXX' not found. Available parameters are [1, 0, param1, param2]
- bug记录:Mybatis-error:Parameter 'xxx' not found. Available parameters are [list]
- 【Mybatis】Parameter 'xxx' not found. Available parameters are [1, 0, param1, param2]
- Mybatis错误:Parameter 'XXX' not found. Available parameters are [1, 0, param1, param2]
- Mybatis错误:Parameter 'XXX' not found. Available parameters are [1, 0, param1, param2]
- MyBatis:Parameter 'xxx' not found. Available parameters are [1, 0, param1, param2]错误
- Mybatis错误:Parameter 'XXX' not found. Available parameters are [1, 0, param1, param2]
- mybatis错误: Parameter 'XXX' not found. Available parameters are [0, 1,2, param5, param2]
- Mybatis错误:Parameter 'XXX' not found. Available parameters are [1, 0, param1, param2]
- Mybatis错误:Parameter 'XXX' not found. Available parameters are [1, 0, param1, param2]
- MTK的充电方案—PMIC充电
- AC自动机
- 统计学习方法笔记, 第四章,朴素贝叶斯python实现
- mybatis-入门案例
- Linux---stat函数以及自己实现stat
- MyBatis的坑(Parameter 'XXX' not found)
- POJ 1458 Common Subsequence(最长公共子序列模版题)
- AtOffer笔记
- 能否向函数传递一个数组?
- 在idea里,点击浏览器图标没反应,解决方案
- char 字符型
- Linux 常用基本命令 压缩 解压缩 tar
- JS和JSP的区别
- windows下向GitHub上传代码