mybatis异常:org.apache.ibatis.binding.BindingException: Parameter '' not foun

葱花鸡蛋 2016-12-17 07:28:42
1. 文件目录

2. spring配置文件代码
	<util:properties id="jdbc" location="classpath:jdbc.properties"></util:properties>

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="#{jdbc.driver}"></property>
<property name="url" value="#{jdbc.url}"></property>
<property name="username" value="#{jdbc.user}"></property>
<property name="password" value="#{jdbc.password}"></property>
</bean>

<bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="mapperLocations" value="classpath:com/fourinnovation/dao/*.xml"></property>
</bean>

<bean id="MapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.fourinnovation.dao"></property>
<property name="annotationClass" value="com.fourinnovation.annotation.MyBatisRepository"></property>
</bean>

3. interface代码
package com.fourinnovation.dao;

import java.util.List;

import com.fourinnovation.annotation.MyBatisRepository;
import com.fourinnovation.bean.Emp;

@MyBatisRepository
public interface EmpMapper {
List<Emp> findAll();
//分页查询
List<Emp> findByPage(int begin,int end);
}

4. mapper代码
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.fourinnovation.dao.EmpMapper">
<select id="findAll" resultType="com.fourinnovation.bean.Emp">
select * from t_emp
</select>

<select id="findByPage" resultType="com.fourinnovation.bean.Emp">
select * from (
select e.*,rownum r from (
select * from t_emp
order by empno
) e
) where r>=#{0} and r<=#{1}
</select>
</mapper>

5. 测试类代码
	@Test
public void test2(){
ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
EmpMapper mapper=ac.getBean("empMapper",EmpMapper.class);
List<Emp> list=mapper.findByPage(1,10);
for(Emp e : list){
System.out.println(e.getEmpno()+" "+e.getEname());
}
}

6. 错误
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter '0' not found. Available parameters are [arg1, arg0, param1, param2]
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:79)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:447)
at com.sun.proxy.$Proxy10.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:231)
at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:137)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:75)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53)
at com.sun.proxy.$Proxy11.findByPage(Unknown Source)
at com.fourinnovation.test.TestCase.test2(TestCase.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: org.apache.ibatis.binding.BindingException: Parameter '0' not found. Available parameters are [arg1, arg0, param1, param2]
at org.apache.ibatis.binding.MapperMethod$ParamMap.get(MapperMethod.java:195)
at org.apache.ibatis.reflection.wrapper.MapWrapper.get(MapWrapper.java:45)
at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:122)
at org.apache.ibatis.executor.BaseExecutor.createCacheKey(BaseExecutor.java:219)
at org.apache.ibatis.executor.CachingExecutor.createCacheKey(CachingExecutor.java:146)
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:82)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:434)
... 30 more


7. 我用的是mybatis3.4.1,后来我换到了mybatis3.2.5就没有错误了。网上找了很多都没办法解决,刚学习mybatis请各位指教一下
...全文
4455 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
sinet_non 2017-11-19
  • 打赏
  • 举报
回复
之前遇到过,楼上张蛋蛋说得对,那样可以解决考虑是版本问题,还有@param注解,这个mybatis generator自动生成有的
葱花鸡蛋 2016-12-18
  • 打赏
  • 举报
回复
我试了下map还有在参数前加@Param都可以,看样只能用这两种方法了,谢谢各位的帮助
爱睡觉的阿狸 2016-12-18
  • 打赏
  • 举报
回复
那就是版本问题,推荐用实体类或者map封装参数传入。
  • 打赏
  • 举报
回复
高版本是不是不支持这种方式。

50,527

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧