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 ...
随机推荐
- jvm内存模型-和内存分配以及jdk、jre、jvm是什么关系(阿里,美团,京东)
参考:JVM的垃圾回收机制 总结(垃圾收集.回收算法.垃圾回收器) 1.什么是jvm?(1)jvm是一种用于计算设备的规范,它是一个虚构出来的机器,是通过在实际的计算机上仿真模拟各种功能实现的.(2) ...
- FTPClient中使用completePendingCommand方法注意事项
方法介绍: * There are a few FTPClient methods that do not complete the * entire sequence of FTP commands ...
- 图像处理中Stride和Width的关系
一行有 11 个像素(Width = 11), 对一个 32 位(每个像素 4 字节)的图像, Stride = 11 * 4 = 44. 但还有个字节对齐的问题, 譬如: 一行有 11 个像素(Wi ...
- Invalid mime type "application nd.ms-excel; charset=utf-8;charset=utf-8": does not contain '/'
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is ...
- mysql 事件计划
一.开启mysql事件计划 首先在sql中查询计划事件的状态:SHOW VARIABLES LIKE 'event_scheduler'如果返回的是off表示当前是关闭状态,如果是on当前已经开启了计 ...
- 201671010426 孙锦喆 实验十四 团队项目评审&课程学习总结
徐明锦 徐明锦 2 95 2019-06-30T14:54:00Z 2019-06-30T14:54:00Z 9 608 3472 28 8 4072 14.00 Clean Clean false ...
- Spring Cloud 组件 —— gateway
Spring Cloud 网关主要有三大模块:route.predicates.filters 其中 filter 最为关键,是功能增强的核心组件. 列举出一些功能组件: 5.6 CircuitBre ...
- python的email、smtplib、poplib模块收发邮件
一封电子邮件的旅程是: MUA:Mail User Agent--邮件用户代理.(即类似Outlook的电子邮件软件) MTA:Mail Transfer Agent--邮件传输代理,就是那些Emai ...
- NSURLProtocol
An NSURLProtocol object handles the loading of protocol-specific URL data. @abstract This method reg ...
- BZOJ 3561: DZY Loves Math VI 莫比乌斯反演+复杂度分析
推到了一个推不下去的形式,然后就不会了 ~ 看题解后傻了:我推的是对的,推不下去是因为不需要再推了. 复杂度看似很大,但其实是均摊 $O(n)$ 的,看来分析复杂度也是一个能力啊 ~ code: #i ...