解决Parameter 'offset' not found. Available parameters are [0, 1, param1, param2]的方法

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter ‘offset‘ not found. Available parameters are [0, 1, param1, param2]

    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371)
    at com.sun.proxy.$Proxy15.selectList(Unknown Source)
    at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:198)
    at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:119)
    at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63)
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
    at com.sun.proxy.$Proxy16.queryAll(Unknown Source)
    at org.seckill.dao.SeckillDaoTest.queryAll(SeckillDaoTest.java:57)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:254)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.apache.ibatis.binding.BindingException: Parameter ‘offset‘ not found. Available parameters are [0, 1, param1, param2]
    at org.apache.ibatis.binding.MapperMethod$ParamMap.get(MapperMethod.java:165)
    at org.apache.ibatis.reflection.wrapper.MapWrapper.get(MapWrapper.java:44)
    at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:116)
    at org.apache.ibatis.executor.BaseExecutor.createCacheKey(BaseExecutor.java:186)
    at org.apache.ibatis.executor.CachingExecutor.createCacheKey(CachingExecutor.java:129)
    at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:76)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)
    ... 35 more

这个异常是我在测试ssm项目中的dao层的一个方法时抛出的,他的主要原因我已经用红笔标注,表示的是Mybatis不能找到offset这个参数,offset的定义如下:

List<Seckill> queryAll(int offset,int limit);

那么问题到底出在哪里,问题在于java中没有保留形参记录的功能,如果是一个参数时,那么在mybatis中获取时无所谓顺序,只要是这个参数,那么我通过#{参数}便能获取,但是当有多个时他在mybatis中就会转换成如下:

List<Seckill> queryAll(arg0,arg1);

那么这两个参数的顺序在#{}取值时便不能明确表示是哪一个,此时Mybatis为我们提供了一个注解:

List<Seckill> queryAll(@Param("offset") int offset, @Param("limit") int limit);

这样的话,Mybatis中取值的时候就会知道arg0代表的offset,而arg1代表的limit。

解决Parameter 'offset' not found. Available parameters are [0, 1, param1, param2]的方法

时间: 2024-10-31 13:55:29

解决Parameter 'offset' not found. Available parameters are [0, 1, param1, param2]的方法的相关文章

Parameter &#39;email&#39; not found. Available parameters are [0, 1, param1, param2]解决方案

转自:https://blog.csdn.net/wdehxiang/article/details/77619569 原因: 传入多个值时,mybatis会自动将这些值转成类似map形式的值,以0,1,2…的序列为keyName. 这里我们需要先简单了解一下mybatis的传值机制.Mybatis现在可以使用的parameterType有基本类型和Java负责类型 基本数据类型:包含int,String,Date等.基本数据类型作为传参,只能传入一个.通过#{参数名}获取. 复杂数据类型:包含

Parameter &#39;name&#39; not found. Available parameters are [arg1, arg0, param1, param2]

解决方法: <select id="selectIf" resultType="student"> SELECT id,name,age,score FROM t_student WHERE 1=1 <if test="arg0 != null and arg0 !=''"> AND name LIKE '%' #{arg0} '%' </if> <if test="arg1>=0&quo

org.apache.ibatis.binding.BindingException: Parameter &#39;xxx&#39; not found. Available parameters are [arg1, arg0, param1, param2]

这个异常说明参数没有加上@Param注解,加上这个注解就行了. org.apache.ibatis.binding.BindingException: Parameter 'xxx' not found. Available parameters are [arg1, arg0, param1, param2] 原文地址:https://www.cnblogs.com/FengZeng666/p/12012727.html

解决Parameter &#39;__frch_item_0&#39; not found. Available parameters 问题

1. 问题描述: 出现如下问题,执行报错信息 Caused by: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter '__frch_item_0' not found. Available parameters are [list, param1] at org.mybatis.spring.MyBatisExc

java 传入多个参数时报&quot;Parameter &#39;XXX&#39; not found. Available parameters are [arg1, arg0, param1,...&quot; 解决方案

@Select("SELECT id FROM ae_post ORDER BY id DESC LIMIT #{page},#{size}") List<Post> getAllForPage(@Param("page") int page, @Param("size")int size); dao层写入,解决方法如上 注:多参数需要添加 @Param("参数名") int 参数名 java 传入多个参数时报&q

Mybatis报错:Parameter &#39;list&#39; not found. Available parameters are [groupList, param1]

GroupDao.java 里面定义的方法: void batchInsertLog(@Param("groupList") List<MktPromotionIntegralLog> groupList); 修改前的GroupMapper.xml <insert id="batchInsertLog" parameterType="java.util.List"> INSERT INTO table (ps_id,goo

Mybatis错误:Parameter &#39;XXX&#39; not found. Available parameters are [1, 0, param1, param2]

Mybatis错误:Parameter 'XXX' not found. Available parameters are [1, 0, param1, param2] 原因:传递的参数超过一个 记 解决办法: (1)直接把值改成数字 <select id="LoginUser" parameterType="String" resultMap="userMap"> SELECT * FROM user where emplnumb

org.apache.ibatis.binding.BindingException: Parameter &#39;start&#39; not found. Available parameters are [1, 0, param1, param2]

DEBUG 2018-05-30 08:43:26,091 org.springframework.jdbc.datasource.DataSourceTransactionManager: Rolling back JDBC transaction on Connection [[email protected]]DEBUG 2018-05-30 08:43:26,091 org.mybatis.spring.SqlSessionUtils$SqlSessionSynchronization:

Parameter &#39;xxx&#39; not found. Available parameters are [collection, list]

mybatis报错问题: dao层: List<HqjTrade> queryHongbao(ArrayList<String> listType); 映射文件下sql: <select id="queryHongbao" resultType="HqjTrade" > select * from hqj_trade where tradetype in <foreach collection="listType&