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 ...
随机推荐
- 项目Beta冲刺(团队)——用户试用调查报告
项目Beta冲刺(团队)--用户试用调查报告 格式描述 课程名称:软件工程1916|W(福州大学) 作业要求:项目Beta冲刺(团队) 团队名称:为了交项目干杯 作业目标:针对相应版本展开用户试用,完 ...
- 日志分析查看——grep,sed,sort,awk运用
概述 我们日常应用中都离不开日志.可以说日志是我们在排查问题的一个重要依据.但是日志并不是写了就好了,当你想查看日志的时候,你会发现线上日志堆积的长度已经超越了你一行行浏览的耐性的极限了.于是,很有必 ...
- org.springframework.security.access.AccessDeniedException: Access is denied
org.springframework.security.access.AccessDeniedException: Access is denied at org.springframework.s ...
- leetcode 合并重叠区间变异 合并多个时间段 取并集
public class Solution { public static ArrayList<Interval> merge(ArrayList<Interval> inte ...
- ssh配置连接远程主机 彻底解放你的双手
查看ssh支持配置 man ssh_config 打开ssh并配置 vi ~/.ssh/config 基本配置示例说明 密钥文件连接 Host <别名> Port <机器端口号> ...
- CGLIB和Java动态代理的区别(笔记)
java常用知识点: 1.Java动态代理只能够对接口进行代理,不能对普通的类进行代理(因为所有生成的代理类的父类为Proxy,Java类继承机制不允许多重继承):CGLIB能够代理普通类:2.Jav ...
- SQL进阶-数据类型转换
一般有这几种转换: 一.数值型与字符型的转化 ### 数值型转为字符型: –> '65' select cast(65 as char); –> 'A' select char(65); ...
- 配送城市地址联动选择JQuery
记录一次使用jq实现3层地址联动选择流程!效果如图. 需要引入 jq.js.layer.js.layui.js.layui.css (icon图标) 二.选中后页面展示效果 三.页面展示HTML &l ...
- Codeforces1254B2 Send Boxes to Alice (Hard Version)(贪心)
题意 n个数字的序列a,将i位置向j位置转移x个(a[i]-x,a[j]+x)的花费为\(x\times |i-j|\),最终状态可行的条件为所有a[i]均被K整除(K>1),求最小花费 做法 ...
- oracle--CKPT
一,CKPT功能 ) 调度数据写: ) 会将已经完成的检查点写到数据文件头: ) 把已经完成的检查点写到控制文件: . other:其他进程: . 注意:磁盘.内存支持并行I/O,磁带不支持: . 服 ...