Код: Выделить всё
@Service
public class StudentService {
@Autowired
private StudentRepository repository;
public Student findById(Long id) throws EntityNotFoundException {
return repository.findById(id).orElseThrow(() -> new EntityNotFoundException("Student not found with id: " + id));
}
public Student updateStudent(Long id, Student updatedData) throws EntityNotFoundException {
Student existingStudent = findById(id);
existingStudent.setFirstName(updatedData.getFirstName());
existingStudent.setLastName(updatedData.getLastName());
existingStudent.setEmail(updatedData.getEmail());
existingStudent.setDepartment(updatedData.getDepartment());
existingStudent.setPhone(updatedData.getPhone());
return repository.save(existingStudent);
}
}
Подробнее здесь: https://stackoverflow.com/questions/786 ... pring-boot