【发布时间】:2026-01-19 18:50:02
【问题描述】:
我正在使用带有 REST 的 spring 数据。我有一个表 country 和一个与之对应的实体,称为 Country.java
我已将 CountryRepositopry 中的方法注释为
public interface CountryRepository extends Repository<Country, Short> {
@RestResource(path = "bycode3")
@Query("select c from Country c where c.codeAlpha3=?1 and c.active=1")
Country findCountryByCodeAlpha3(@Param("code") String countryCode);
}
我在启动 tomcat 时遇到以下异常-
Caused by: java.lang.IllegalStateException: Using named parameters for method public abstract com.persistence.entity.common.Country com.persistence.repository.CountryRepository.findCountryByCodeAlpha3(java.lang.String) but parameter 'code' not found in annotated query 'select c from Country c where c.codeAlpha3=?1 and c.active=1'!
【问题讨论】:
-
使用
:而不是?
标签: jpa spring-data-rest