1. 程式人生 > >Spring錯誤:org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.B

Spring錯誤:org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.B

使用springmvc+mybaties出現如下錯誤:

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'user_type' not found. Available parameters are [2, 1, 0, param1, param2, param3]
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:368)
at com.sun.proxy.$Proxy37.selectOne(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:163)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:43)
at com.sun.proxy.$Proxy41.getUserByPasswordAndType(Unknown Source)
at cn.piaole.mybatis.demo.core.service.impl.UserServiceImpl.register(UserServiceImpl.java:42)
at cn.piaole.mybatis.demo.action.RegisterAction.register(RegisterAction.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

原因:

其實是忘了使用@Param,當只有一個引數時,Mapper中可以不使用

public User getUser(String name); 

但是當你有多個引數時就必須使用
public User getUser(@Param("name") String name,@Param("password") String password);