parent
d5399a7677
commit
ed01815caf
|
@ -15,25 +15,28 @@ import com.baeldung.spring.servicevalidation.domain.UserAccount;
|
||||||
@Service
|
@Service
|
||||||
public class UserAccountService {
|
public class UserAccountService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private Validator validator;
|
private Validator validator;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private UserAccountDao dao;
|
|
||||||
|
|
||||||
public String addUserAccount(UserAccount useraccount) {
|
|
||||||
|
|
||||||
Set<ConstraintViolation<UserAccount>> violations = validator.validate(useraccount);
|
|
||||||
|
|
||||||
if (!violations.isEmpty()) {
|
@Autowired
|
||||||
StringBuilder sb = new StringBuilder();
|
private UserAccountDao dao;
|
||||||
for (ConstraintViolation<UserAccount> constraintViolation : violations) {
|
|
||||||
sb.append(constraintViolation.getMessage());
|
public String addUserAccount(UserAccount useraccount) {
|
||||||
}
|
|
||||||
throw new ConstraintViolationException("Error occurred: " + sb.toString(), violations);
|
Set<ConstraintViolation<UserAccount>> violations = validator.validate(useraccount);
|
||||||
}
|
|
||||||
dao.addUserAccount(useraccount);
|
if (!violations.isEmpty()) {
|
||||||
return "Account for " + useraccount.getName() + " Added!";
|
StringBuilder sb = new StringBuilder();
|
||||||
}
|
for (ConstraintViolation<UserAccount> constraintViolation : violations) {
|
||||||
|
sb.append(constraintViolation.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
dao.addUserAccount(useraccount);
|
||||||
|
|
||||||
|
throw new ConstraintViolationException("Error occurred: " + sb.toString(), violations);
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Account for " + useraccount.getName() + " Added!";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue