1
나는 다음 내 @query에서 오류를 받고 있어요
HQL 질의 :최대 절전 모드 예외
List<User> result = userRepository.findByCityTypeAndName(city, DentistType.valueOf(type), name);
: 나는 메서드를 호출 내 컨트롤러에서
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);
그러나 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
어떻게 해결할 수 있습니까? 쿼리
@Query(value = "select u from User u " +
" where u.city = :city and u.dentistType = :type " +
" and (u.firstName like CONCAT(:name,'%') or u.lastName like CONCAT(:name,'%')")
List<User> findByCityTypeAndName(@Param("city") String city, @Param("type") DentistType type, @Param("name") String name);
에서 CONCAT를 사용
'같은 쿼리 무언가를하지 않고하는 방법을 만들 수 있습니다 '이름 %는'수 없습니다. 'findByCityTypeAndName' 메소드를 호출하기 전에 따옴표를 제거하고'%'를 추가해야합니다. –
감사합니다. 문제가 해결되었습니다. – JJey