对于使用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. Linux 定时重启 Tomcat、重启Keepalived

    1.在 tomcat 目录新建一个.sh 文件: vi restartTomcat.sh 2.输入内容: #!/bin/bash# author: Linnuo # date: -- # Filena ...

  2. modbus-poll和modbus-slave工具的学习使用——modbus协议功能码3的解析(及欧姆龙温控器调试笔记)

    最近的项目中使用到了欧姆龙的温控器,里面有很多的通信方式,我们使用的常见的modbus——RTU方式,其他方式我们不使用,其中通信手册上面有很多通信的实例,欧姆龙modbus还区分4字节模式和2字节模 ...

  3. 创建Maven之后,Java包下无法直接创建servlet的原因:

    ---恢复内容开始--- 没有导入servlet-api的依赖,导入完依赖就可以直接创建了   依赖如下:   <dependency> <groupId>javax.serv ...

  4. [Javascript] Working with Static Properties on a Class

    Classes are syntactic sugar over functions and functions are also referred to as "callable" ...

  5. 【转】Fiddler抓包指南:结合Proxifier工具

    本文转自:https://blog.csdn.net/china_jeffery/article/details/93000824 本文介绍如何使用Fiddler抓取HTTP和HTTPS协议的包,同时 ...

  6. nginx unit java 试用

    unit 当前已经支持java了,当时支持基于servlet 的开发模式,以下是一个简单的学习 基于官方的demo 环境准备 docker-compose文件   version: "3&q ...

  7. Unicode-objects must be encoded before hashing 错误解决办法

    提交注册用户数据后出来这个,错误原因是update()必须指定要加密的字符串的字符编码 #encryptions1 = sha1()s1.update(upwd.encode("utf8&q ...

  8. 【BZOJ2095】[Poi2010]Bridges

    [BZOJ2095][Poi2010]Bridges 题面 darkbzoj 题解 首先可以想到二分答案,那么我们就是要求我们新图中给所有边定向是否存在欧拉回路. 而有向图存在欧拉回路的充要条件为所有 ...

  9. Linux中的文件

    一般情况下,每个存储设备或存储设备的分区(存储设备是硬盘.软盘.U盘 ..)被格式化为文件系统后,都会有两部份,一部份是iNode,另一部份是Block.Block是用来存储数据用的,而iNode就是 ...

  10. 牛顿迭代法(c++)

    编写一个用牛顿法解方程x=tanx 的程序,求最接近4.5和7.7的根 #include <iostream> #include <cmath> using namespace ...