我正在尝试调用休息应用程序,但收到 500 错误。问题可能出在 MyBatis 调用上,但仍然无法修复。
这是我调用MyBatis执行的地方
@Override
public List<IdentitatBDTO> searchIdentitatsRepresentantsByRelacioIdentitatRepresentat(final String representatIdentificador, final Date dateFi) {
List<Identitat> identitats = myBatisTemplate.execute(RelacioDao.class, new MyBatisDaoCallback<List<Identitat>>() {
@Override
public List<Identitat> execute(MyBatisDao dao) {
return ((RelacioDao) dao).searchIdentitatsRepresentantsByRelacioIdentitatRepresentat(representatIdentificador, dateFi);
}
});
我收到的错误是
{
"errorUrl":
"http://localhost:8080/idjrepresentaciorest/rest/representacio/representants/12340002L",
"errorMessage": "\r\n### Error querying database. Cause: org.apache.ibatis.binding.BindingException: Parameter 'representatIdentificador' not found. Available parameters are [1, 0, param1, param2]\r\n### Cause: org.apache.ibatis.binding.BindingException: Parameter 'representatIdentificador' not found. Available parameters are [1, 0, param1, param2]",
"errorStackTrace": "org.apache.ibatis.exceptions.PersistenceException: \r\n### Error querying database. Cause: org.apache.ibatis.binding.BindingException: Parameter 'representatIdentificador' not found. Available parameters are [1, 0, param1, param2]\r\n### Cause: org.apache.ibatis.binding.BindingException: Parameter 'representatIdentificador' not found. Available parameters are [1, 0, param1, param2]\r\n\tat org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)\r\n\tat org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150)\r\n\tat org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)\r\n\tat org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:137)\r\n\tat org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:75)\r\n\tat org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53)\r\n\tat com.sun.proxy.$Proxy85.searchIdentitatsRepresentantsByRelacioIdentitatRepresentat(Unknown Source)\r\n\tat es.bcn.idj.representaciorest.business.impl.RelacioServiceImpl$1.execute(RelacioServiceImpl.java:61)\r\n\tat es.bcn.idj.representaciorest.business.impl.RelacioServiceImpl$1.execute(RelacioServiceImpl.java:1)\r\n\tat net.opentrends.openframe.services.persistence.mybatis.template.impl.MyBatisTemplateImpl.execute(MyBatisTemplateImpl.java:64)\r\n\tat
但是我调试了一下,发现问题所在的变量填充正确,那么为什么 MyBatis 没有找到该变量呢?
最佳答案
@Param注解有两种,一种属于spring,一种属于mybatis。它们的用法不同。
- org.springframework.data.repository.query.Param
它基于参数的顺序,并且从 0 开始。User getUserById(@Param("id") Integer id); <select id="getUserById" resultMap="userMap"> select name,age from user where id=#{0, jdbcType=INTEGER} <select/>
- org.apache.ibatis.annotations.Param
基于参数名称。User getUserById(@Param("id") Integer id); <select id="getUserById" resultMap="userMap"> select name,age from user where id=#{id, jdbcType=INTEGER} <select/>
因此,请检查您在mapper.java中引入的注释是否与mapper.xml中的用法一致。
关于java - MyBatis 参数未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54070841/