我的 CountryServiceImpl 有问题,当我想在 CountryServiceImpl 中实现方法 findOne 时,它告诉我“类型参数‘S’的推断类型‘S’不在其范围内;应该扩展‘ua.com.store.entity.Country’” .
我想自己修复,但我不明白这是什么意思。你能帮我解决这个问题吗?
谢谢你。
@Entity
@Getter
@Setter
@NoArgsConstructor
@ToString
public class Country {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String countryName;
@OneToMany(mappedBy = "country")
private Set<Brand> brands = new HashSet<Brand>();
}
public interface CountryDAO extends JpaRepository<Country, Integer> {
@Query("from Country c where c.countryName=:name")
Country findByCountryName(@Param("name") String name);
}
public interface CountryService {
void save(Country country);
void delete(Country country);
List<Country> findAll();
Country findOne(int id);
Country findByCountryName(String name);
}
@Service
public class CountryServiceImpl implements CountryService {
@Autowired
private CountryDAO dao;
@Override
public void save(Country country) {
dao.save(country);
}
@Override
public void delete(Country country) {
dao.delete(country);
}
@Override
public List<Country> findAll() {
return dao.findAll();
}
@Override
public Country findOne(int id) {
return dao.findOne(id);
}
@Override
public Country findByCountryName(String name) {
return dao.findByCountryName(name);
}
}
原文由 Roman Sychok 发布,翻译遵循 CC BY-SA 4.0 许可协议
Spring 文档定义方法 getOne 如下
在您的方法中,您的输入参数是 int 类型的“id”,但不受接口示例的限制。
要查找带有“id”的实体,您可以使用该方法
根据您的实现,您可以编写它