Mybatis传多个参数的问题 及MyBatis报错 Parameter '0' not found. Available parameters are [arg1, arg0, param1 问题
对于使用Mybatis ,传多个参数,我们可以使用对象封装外,还可以直接传递参数
对象的封装,例如查询对象条件basequery对象
<select id="getProductByProductQuery" parameterType="com.niulande.product.query.BaseQuery" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from pd_product
<include refid="whereSql"/>
</select>
<sql id= "whereSql" >
<where>
<if test="gameCode != null and gameCode != ''" >
and game_type_coding = #{gameCode}
</if>
<if test="goodsTypeId != null">
and goods_type_id = #{goodsTypeId}
</if>
<if test="accId != null">
and account_id = #{accId}
</if>
<if test="delFlag != null">
and del_flag = #{delFlag}
</if>
</where>
limit #{start},#{rows}
</sql>
</mapper>
直接传递参数
例如:
mapper方法
selectByGameIdAndGoodsTypeId(Long gameTypeId, Long goodsTypeId);
对应的xml文件方法:
<select id="selectByGameIdAndGoodsTypeId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from pd_game_goods_type_mid
where game_type_id = #{gameTypeId} AND goods_type_id = #{goodsTypeId}
</select>
第一:在select标签后就不再使用parameterType,因为这个标签只能指定一个参数,而两个参数及以上的,则不用再使用
第二:在sql语句里面以上的写法是错误的(为了演示执行报错)
会报错
Parameter '0' not found. Available parameters are [arg1, arg0, param1, param2] 注意这里使用的mybatis的版本号 在MyBatis3.4.4版不能直接使用#{0}要使用 #{arg0}
0是指参数的索引,从0开始。第一个参数是0,第二个参数是1,依次类推
以下正确的写法:
<select id="selectByGameIdAndGoodsTypeId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from pd_game_goods_type_mid
where game_type_id = #{arg0} AND goods_type_id = #{arg1}
</select>
第三种:
<select id="selectByGameIdAndGoodsTypeId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from pd_game_goods_type_mid
where game_type_id = #{gameTypeId} AND goods_type_id = #{goodsTypeId}
</select>
刚刚说这样的会报错。解决办法,更改mapper方法
加上@Param注解
selectByGameIdAndGoodsTypeId(@Param("gameTypeId")Long gameTypeId, @Param("goodsTypeId") Long goodsTypeId)
Mybatis传多个参数的问题 及MyBatis报错 Parameter '0' not found. Available parameters are [arg1, arg0, param1 问题的更多相关文章
- MyBatis报错 Parameter '0' not found. Available parameters are [arg1, arg0, param1, param2]
修改 <update id="updateStatusById" parameterType="java.lang.Integer"> update ...
- org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'userId' not found. Available parameters are [arg1, arg0, param1, param2]
2018-06-27 16:43:45.552 INFO 16932 --- [nio-8081-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : ...
- SpringBoot整合Mybatis注解版---update出现org.apache.ibatis.binding.BindingException: Parameter 'XXX' not found. Available parameters are [arg1, arg0, param1, param2]
SpringBoot整合Mybatis注解版---update时出现的问题 问题描述: 1.sql建表语句 DROP TABLE IF EXISTS `department`; CREATE TABL ...
- java 传入多个参数时报"Parameter 'XXX' not found. Available parameters are [arg1, arg0, param1,..." 解决方案
@Select("SELECT id FROM ae_post ORDER BY id DESC LIMIT #{page},#{size}") List<Post> ...
- 怪事年年有,今天特别多!org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'empno' not found. Available parameters are [emp, deptno, param1, param
错误: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.Binding ...
- Mybatis报错:Parameter 'list' not found. Available parameters are [groupList, param1]
GroupDao.java 里面定义的方法: void batchInsertLog(@Param("groupList") List<MktPromotionIntegra ...
- org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'employeeId' not found. Available parameters are [page, map, param1, param2] 解决方法
原因很简单就是没映射到接口添加 @Param 注解 ->@Param("map") 然后在mapper.xml map.employeeId 再次测试 已经解决 ->
- org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'username' not found. Available parameters are [1, 0, param1, param2]
Spring+mybatis错误:org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.bi ...
- 【spring data jpa】repository中使用@Query注解使用hql查询,使用@Param引用参数,报错:For queries with named parameters you need to use provide names for method parameters. Use @Param for query method parameters, or when on
在spring boot中, repository中使用@Query注解使用hql查询,使用@Param引用参数 如题报错: For queries with named parameters you ...
随机推荐
- php中的闭包类
看注释 <?php //闭包类实现匿名函数 //call方法调用 class Customer { private $firstname; private $lastname; public f ...
- Java8新特性(1)—— Stream集合运算流入门学习
废话,写在前面 好久没写博客了,懒了,以后自觉写写博客,每周两三篇吧! 简单记录自己的学习经历,算是对自己的一点小小的督促! Java8的新特性很多,比如流处理在工作中看到很多的地方都在用,是时候扔掉 ...
- C#WinForm程序异常退出的捕获、继续执行与自动重启
本文参考网上搜索的信息,并做了适当修改可以让捕捉到异常之后阻止程序退出. 另给出了通过命令行自动重启的方法. 如果一个线程里运行下面的代码 ; / a; 将会导致程序自动结束,而且没有任何提示信息 但 ...
- Shell 日常 ip 端口可用性测试
ip port 可用测试 telnet 测试某个ip 端口是否可用很方便,但是如果ip比较多,写脚本就不方便了因为是阻塞的 这里强烈推荐 nc nc -z -w 1 127.0.0.1 8990 这里 ...
- vuex2 mapActions 报错 `unknown action type: xxxx`
export const setBreadCrumb = ({ dispatch }, data) => { dispatch('SET_BREADCRUMB', data) } 当调用的时候报 ...
- Find the Weak Connected Component in the Directed Graph
Description Find the number Weak Connected Component in the directed graph. Each node in the graph c ...
- 拓展-教你手把手用纯CSS写轮播图
先看成品图[示例网址:][1] [1]: https://huruji.github.io/css-imitate-js/slider/index.html一.随便说几句####css3动画效果的强大 ...
- base64文件隐写脚本
base64文件隐写脚本 base64 可以在文件中隐藏信息,记录一下提取脚本 ''' base64文件隐写脚本 import re import base64 b64chars = 'ABCDEFG ...
- Edraw Max 9.4 Crack Method
使用010editor修改以下两个文件. BaseCore.dll (修改二进制内容hex) Before C6 45 C8 62 C6 45 C9 64 C6 45 CA 65 C6 45 CB 6 ...
- MongoDB远程连接-MongoDB Compass
MongoDB Compass Community连接界面设置