Supposed I have a code that update the table using the JpaRepository package
public User test(Long userId, UserDto userDto) {
User user = findByUserId(userId);
User mappedUser = modelMapper.map(userDto, User.class);
if (mappedUser.getAddress() != null) {
user.setAddress(mappedUser.getAddress());
}
if (mappedUser.getContact() != null) {
user.setContact(mappedUser.getContact());
}
... // more checking if != null
return userRepository.saveAndFlush(user);
}
Is there a way where I can avoid the multiple checking of != null
that uses the if statement? before saving it to the database? Thanks in advance Im new in using spring boot