Код: Выделить всё
@Entity
@Data
public class User implements UserDetails {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
@Column(unique = true)
private String email;
private String password;
@Column(unique = true)
private String phoneNumber;
@Column(unique = true)
private String idNumber;
private UserRole userRole;
}
Код: Выделить всё
@Data
public class SignupRequest {
private String name;
private String email;
private String password;
private String phoneNumber;
private String idNumber;
}
Код: Выделить всё
@Override
public ResponseEntity createUserAccount(SignupRequest signupRequest) {
try {
if (!userRepository.existsByEmail(signupRequest.getEmail())){
System.out.println(signupRequest);
User user = modelMapper.map(signupRequest,User.class);
user.setPassword(new BCryptPasswordEncoder().encode(signupRequest.getPassword()));
user.setUserRole(UserRole.EMPLOYEE);
userRepository.save(user);
return new ResponseEntity(new StandardResponse(201,"User account added"), HttpStatus.CREATED);
}else {
return new ResponseEntity(new StandardResponse(400,"This user account already added"), HttpStatus.BAD_REQUEST);
}
}catch (Exception e){
return new ResponseEntity(new StandardResponse(400,"Error occurred while adding new user"+e.getMessage()), HttpStatus.BAD_REQUEST);
}
}
вывод ошибки
"Произошла ошибка при добавлении новых ошибок сопоставления userModelMapper:\n\n1) Converter org.modelmapper.internal.converter.NumberConverter@d35d185 не удалось преобразовать java.lang.String в java.lang.Long.\n\n1 ошибка"
Как исправить эту ошибку и какие ошибки есть в моем коде< /п>
Подробнее здесь: https://stackoverflow.com/questions/787 ... rs-mapping
Мобильная версия