【发布时间】:2017-12-14 14:59:51
【问题描述】:
我的@Query 出现错误,如下所示:
UserRepository.java
@Query(value = "select u from User u\n" +
" where u.city = :city and u.dentistType = :type\n" +
" and (u.firstName like ':name%' or u.lastName like ':name%')")
List<User> findByCityTypeAndName(@Param("city") String city, @Param("type") DentistType type, @Param("name") String name);
我从我的控制器调用方法:
List<User> result = userRepository.findByCityTypeAndName(city, DentistType.valueOf(type), name);
但是当我执行 get 请求时,我的 findByCityTypeAndName 方法被触发,我收到以下错误:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Parameter with that name [name] did not exist; nested exception is java.lang.IllegalArgumentException: Parameter with that name [name] did not exist] with root cause
java.lang.IllegalArgumentException: Parameter with that name [name] did not exist
知道如何解决这个问题吗?
【问题讨论】:
-
':name%'是不可能的。在调用findByCityTypeAndName方法之前,您需要自己删除引号并附加%。 -
谢谢,这解决了我的问题。
标签: java mysql spring hibernate