我在REST中使用spring数据。我有一个表格国家和一个与之相对应的实体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'!
最佳答案
我定了
查询需要修改为
@Query("select c from Country c where c.codeAlpha3=:code and c.active=1")
而不是?1 ,它应该是:代码