Код: Выделить всё
public abstract class CrudService{
protected R repository;
public CrudService(R repository){
this.repository = repository;
}
public ID create(E entity) {
return repository.save(entity).getId();
}
public List readAll(){
return repository.findAll();
}
public Optional readById(ID id){
return repository.findById(id);
}
public boolean update(E entity){
if(!repository.existsById(entity.getId())){
return false;
}
repository.save(entity);
return true;
}
public boolean delete(ID id) {
if(!repository.existsById(id)){
return false;
}
repository.deleteById(id);
return true;
}
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... ct-mappers
Мобильная версия