Я хочу знать лучший и эффективный способ обновления объекта, который является отраслевой практикой. Что я знаю на данный момент для обновления сущности
@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);
}
}
Здесь мне пришлось вручную задать все поля. Если бы у меня было более 20 полей, был ли бы это эффективный подход к обновлению сущности? Каков эффективный подход для этого?
Я хочу знать лучший и эффективный способ обновления объекта, который является отраслевой практикой. Что я знаю на данный момент для обновления сущности [code]@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 {
[/code] Здесь мне пришлось вручную задать все поля. [b]Если бы у меня было более 20 полей[/b], был ли бы это эффективный подход к обновлению сущности? Каков эффективный подход для этого?