ローマSychok:
私は私の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);
}
}
Lakshan:
春のドキュメントの定義方法は、次のようにgetone
<S extends T> Optional<S> findOne(Example<S> example)
あなたの方法では、あなたの入力パラメータは、int型の「ID」ですが、例のインタフェースにバインドされません。
それは「ID」は、メソッドを使用することができてエンティティを検索するには
Optional<T> findById(ID id)
あなたの実装によると、あなたはそれを書くこと
@Override
public Country findOne(int id) {
return dao.findById(id);
}