Параметр MyBatis не найден - PullRequest
       7

Параметр MyBatis не найден

0 голосов
/ 07 января 2019

Я пытаюсь вызвать приложение отдыха, но получаю ошибку 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 не находит переменную?

1 Ответ

0 голосов
/ 07 января 2019

@ У аннотации Param есть два, один принадлежит весне, другой принадлежит mybatis. Их использование отличается.

  • org.springframework.data.repository.query.Param
    User getUserById(@Param("id") Integer id);
    <select id="getUserById" resultMap="userMap">
        select name,age
        from user
        where id=#{0, jdbcType=INTEGER}
    <select/>
    
    Он основан на порядке параметров и начинается с 0.

  • 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.

...