对于使用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 问题的更多相关文章

  1. MyBatis报错 Parameter '0' not found. Available parameters are [arg1, arg0, param1, param2]

    修改 <update id="updateStatusById" parameterType="java.lang.Integer"> update ...

  2. 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].[/]       : ...

  3. 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 ...

  4. 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> ...

  5. 怪事年年有,今天特别多!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 ...

  6. Mybatis报错:Parameter 'list' not found. Available parameters are [groupList, param1]

    GroupDao.java 里面定义的方法: void batchInsertLog(@Param("groupList") List<MktPromotionIntegra ...

  7. 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 再次测试 已经解决 ->

  8. 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 ...

  9. 【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 ...

随机推荐

  1. 无故出现 mysql dead but subsys locked的有关问题

    无故出现 mysql dead but subsys locked的问题问题描述:1.mysql安装完成后,使用service mysqld restart总是出现stop mysqld servic ...

  2. C++传递不定参函数

    定义不定参数函数,要用到下面这些宏: va_start(ap, farg): 初始化一个va_list变量ap,farg是第一个形参 va_arg(ap, type): 获取(下)一个type类型的参 ...

  3. Bomb Enemy

    Description Given a 2D grid, each cell is either a wall 'W', an enemy 'E' or empty '0' (the number z ...

  4. netflix conductor 2.x 版本新功能简单说明

    netflix conductor 2.x 已经发布很长时间了,同时官方也发布了关于2.x 新特性的说明,当前github 行的release 版本为2.14.4 新特性 grpc 框架支持 一个可选 ...

  5. JS线程机制与事件机制

    JS线程机制与事件机制 1.进程与线程 (1).定义: 进程:程序的一次执行,它占有一片独有的内存空间 CPU的基本调度单位,是程序执行的一个完整的流程 (2).进程与线程的关联 一个进程一般至少有一 ...

  6. 洛谷 P1825 【[USACO11OPEN]玉米田迷宫Corn Maze】

    P1825 传送门 简单的题意 就是一个有传送门的迷宫问题(我一开始以为是只有1个传送门,然后我就凉了). 大体思路 先把传送门先存起来,然后跑一下\(BFS\). 然后,就做完了. 代码鸭 #inc ...

  7. 统计学基础知识(一)---描述统计学(Descriptive Statistics)

    描述统计学(Descriptive Statistics):将数据的信息以表格, 图形或数值的形式进行汇总. 数据类型:分为定量数据(数值型数据)和定性数据(类别型数据).数值型数据又可以分为连续型和 ...

  8. python: str()

    tx1 = '中国' tx2 = u'中国' print tx1 print tx2 print type(tx1) print type(tx2) #<type 'str'> str() ...

  9. SQLSERVER|CDC日志变更捕获机制

    一.什么是CDC? 变更数据捕获(Change Data Capture ,简称 CDC)记录 SQL Server 表的插入.更新和删除活动.SQLServer的操作会写日志,这也是CDC捕获数据的 ...

  10. [Beta]Scrum Meeting#1

    github 本次会议项目由PM召开,时间为5月6日晚上10点30分 时长15分钟 任务表格 人员 昨日工作 下一步工作 木鬼 beta初步计划 撰写博客整理文档 swoip 前端改进计划 模块松耦合 ...