本文整理汇总了Java中org.springframework.validation.Errors.hasErrors方法的典型用法代码示例。如果您正苦于以下问题:Java Errors.hasErrors方法的具体用法?Java Errors.hasErrors怎么用?Java Errors.hasErrors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.validation.Errors
的用法示例。
在下文中一共展示了Errors.hasErrors方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validate
import org.springframework.validation.Errors; //导入方法依赖的package包/类
public void validate(Object target, Errors errors) {
CustomerInfo custInfo = (CustomerInfo) target;
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "fName", "NotEmpty.customerForm.fName");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lName", "NotEmpty.customerForm.lName");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "NotEmpty.customerForm.email");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "address", "NotEmpty.customerForm.address");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "phone", "NotEmpty.customerForm.phone");
if(!errors.hasErrors() && custInfo.getPhone().length()!=10){
errors.rejectValue("phone","Length.greater.phone");
}
if(!errors.hasErrors() && custInfo.getPhone().contains("[0-9]+")){
errors.rejectValue("phone","NoCharacater.cusomerForm.phone");
}
if (!errors.hasErrors() && !emailValidator.isValid(custInfo.getEmail())) {
errors.rejectValue("email", "NotValid.customer.email");
}
}
示例2: register
import org.springframework.validation.Errors; //导入方法依赖的package包/类
@RequestMapping(value = "/register", method = RequestMethod.POST)
public String register(@ModelAttribute @Valid RegisterForm form, Errors errors, HttpServletRequest request) {
if (errors.hasErrors()) {
return "register";
}
User existingUser = userDao.findByUsername(form.getUsername());
if (existingUser != null) {
errors.rejectValue("username", "username.alreadyexists", "A user with that username already exists");
return "register";
}
User newUser = new User(form.getUsername(), form.getPassword());
userDao.save(newUser);
setUserInSession(request.getSession(), newUser);
return "redirect:";
}
示例3: login
import org.springframework.validation.Errors; //导入方法依赖的package包/类
@RequestMapping(value = "/login", method = RequestMethod.POST)
public String login(@ModelAttribute @Valid LoginForm form, Errors errors, HttpServletRequest request) {
if (errors.hasErrors()) {
return "login";
}
User theUser = userDao.findByUsername(form.getUsername());
String password = form.getPassword();
if (theUser == null) {
errors.rejectValue("username", "user.invalid", "The given username does not exist");
return "login";
}
if (!theUser.isMatchingPassword(password)) {
errors.rejectValue("password", "password.invalid", "Invalid password");
return "login";
}
setUserInSession(request.getSession(), theUser);
return "redirect:";
}
示例4: ProcessAdd
import org.springframework.validation.Errors; //导入方法依赖的package包/类
@RequestMapping(value = "add", method = RequestMethod.POST)
public String ProcessAdd(@ModelAttribute @Valid hike newHike, Errors errors, Model model) {
if (errors.hasErrors()) {
model.addAttribute("title", "Share A Hike");
model.addAttribute(new hike());
return "home/add";
}
hikeDao.save(newHike);
int newHikeId = newHike.getId();
return "redirect:view/" + newHikeId;
}
示例5: updateHousehold
import org.springframework.validation.Errors; //导入方法依赖的package包/类
/**
* Updates the househole information
* @param updateHouseholdDTO the user information to update
* @param errors an error container
* @return the udpated user
*/
@RequestMapping(method = RequestMethod.PUT, value = "/", produces = "application/json")
public ResponseEntity updateHousehold(@RequestBody UpdateHouseholdDTO updateHouseholdDTO, Errors errors) {
UpdateHouseholdValidator houseValidator = new UpdateHouseholdValidator();
houseValidator.validate(updateHouseholdDTO, errors);
ValidationError validationError = ValidationErrorBuilder.fromBindErrors(errors);
if(errors.hasErrors()) {
throw new IllegalRequestFormatException("Could not update household.", "/household", validationError);
}
Household updatedHousehold= this.householdService.updateHousehold(updateHouseholdDTO);
return ResponseEntity.ok(updatedHousehold);
}
示例6: usersPost
import org.springframework.validation.Errors; //导入方法依赖的package包/类
@Override
@PreAuthorize("hasAuthority('admin')")
public ResponseEntity<Object> usersPost(@ApiParam(value = "The user to save") @Valid @RequestBody UserReg user, Errors errors) throws ApiException, Exception {
if (errors.hasErrors()) { //Check for validation error from UserReg class(package:model)
Error error = new Error();
error.setError("400");
error.setMessage("Validation Failed");
System.out.println("" + errors.getAllErrors());
return new ResponseEntity<>(error, HttpStatus.BAD_REQUEST);
}
//Call method for save user in database from class UsersService.
com.jrtechnologies.yum.data.entity.User userEntity = userService.usersPost(user);
//After created return id of new user.
return new ResponseEntity<>(userEntity.getId(), HttpStatus.CREATED);
}
示例7: updateService
import org.springframework.validation.Errors; //导入方法依赖的package包/类
/**
* Updates the user information
* @param updateServiceDTO the user information to update
* @param errors an error container
* @return the udpated user
*/
@RequestMapping(method = RequestMethod.PUT, value = "/", produces = "application/json")
public ResponseEntity updateService(@RequestBody UpdateServiceDTO updateServiceDTO, Errors errors) {
UpdateServiceValidator userValidator = new UpdateServiceValidator();
userValidator.validate(updateServiceDTO, errors);
ValidationError validationError = ValidationErrorBuilder.fromBindErrors(errors);
if(errors.hasErrors()) {
throw new IllegalRequestFormatException("Could not update service.", "/services", validationError);
}
Service updatedService = this.serviceService.updateService(updateServiceDTO);
return ResponseEntity.ok(updatedService);
}
示例8: validate
import org.springframework.validation.Errors; //导入方法依赖的package包/类
/**
* Validates the input
* @param object the user to validate
* @param errors the errors
*/
public void validate(Object object, Errors errors) {
UserDTO user = (UserDTO) object;
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "googleId", "field.required",
"googleId must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "fullName", "field.required",
"User Full Name must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "givenName", "field.required",
"User Given Name must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "familyName", "field.required",
"User Family Name must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "imageURL", "field.required",
"User Image URL must not be empty.");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "field.required",
"User Email must not be empty");
ValidationUtils.rejectIfEmpty(errors, "role", "field.required",
"User Role must not be empty.");
// doing specific input validaiton, so we need to make sure all of the fields are there
if(!errors.hasErrors()) {
if(user.getRole() < 0 || user.getRole() > 1) {
errors.rejectValue("role", "field.invalid", "User Role must be 0 or 1");
}
if(!EmailValidator.getInstance().isValid(user.getEmail())) {
errors.rejectValue("email", "field.invalid", "User Email must be a valid email address.");
}
if(!UrlValidator.getInstance().isValid(user.getImageURL())) {
errors.rejectValue("imageURL", "field.invalid", "User Image URl must be a valid web address.");
}
}
}
示例9: updateUser
import org.springframework.validation.Errors; //导入方法依赖的package包/类
/**
* Updates the user information
* @param updateUserDTO the user information to update
* @param errors an error container
* @return the udpated user
*/
@RequestMapping(method = RequestMethod.PUT, value = "/", produces = "application/json")
public ResponseEntity updateUser(@RequestBody UpdateUserDTO updateUserDTO, Errors errors) {
UpdateUserValidator userValidator = new UpdateUserValidator();
userValidator.validate(updateUserDTO, errors);
ValidationError validationError = ValidationErrorBuilder.fromBindErrors(errors);
if(errors.hasErrors()) {
throw new IllegalRequestFormatException("Could not update user.", "/users", validationError);
}
User updatedUser = this.userService.updateUser(updateUserDTO);
return ResponseEntity.ok(updatedUser);
}
示例10: validate
import org.springframework.validation.Errors; //导入方法依赖的package包/类
@Override
public void validate(Object object, Errors errors) {
WeatherLocationDTO weatherLocationDTO = (WeatherLocationDTO) object;
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userId", "field.required",
"User Id must not be empty");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "city", "field.required",
"City must not be empty");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "state", "field.required",
"State must not be empty");
if(!errors.hasErrors()) {
if(weatherLocationDTO.getState().length() != 2) {
errors.rejectValue("state", "filed.invalid",
"State must be length 2. Did you forget to use state code?");
}
}
}
示例11: addTags
import org.springframework.validation.Errors; //导入方法依赖的package包/类
@RequestMapping(value = "add-tags/{hikeId}", method = RequestMethod.POST)
public String addTags (Model model, @ModelAttribute @Valid AddTagForm form, Errors errors) {
if (errors.hasErrors()) {
model.addAttribute("form", form);
return "home/add-tags/";
}
tags newTag = tagsDao.findOne(form.getTagsId());
hike newHike = hikeDao.findOne(form.getHikeId());
newHike.addTag(newTag);
hikeDao.save(newHike);
return "home/add-tags/" + newHike.getId();
}
示例12: thymeleafFormPost
import org.springframework.validation.Errors; //导入方法依赖的package包/类
@RequestMapping(value = "thymeleafForm", method = RequestMethod.POST)
public String thymeleafFormPost(@Valid ThymeleafForm form, Errors errors) {
System.out.println(form);
if (errors.hasErrors()) {
return "form";
}
return "redirect:/test/pathGet/1/1";
}
示例13: authChangepwdPut
import org.springframework.validation.Errors; //导入方法依赖的package包/类
@Override
public ResponseEntity<Error> authChangepwdPut(@ApiParam(value = "token/password" ,required=true ) @RequestBody ResetPwd body, Errors errors) throws ApiException {
if (errors.hasErrors()) {
Error error = new Error();
error.setError("400");
error.setMessage("Validation Failed");
System.out.println("" + errors.getAllErrors());
return new ResponseEntity<>(error, HttpStatus.BAD_REQUEST);
}
authService.authChangepwdPut(body);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
示例14: ordersIdPut
import org.springframework.validation.Errors; //导入方法依赖的package包/类
@Override
@PreAuthorize("hasAuthority('hungry')")
public ResponseEntity<Object> ordersIdPut(@ApiParam(value = "", required = true) @PathVariable("id") Long id,
@ApiParam(value = "") @RequestParam(value = "userid", required = false, defaultValue = "0") Long userid,
@ApiParam(value = "The order items to modify") @RequestBody UpdateOrderItems updateOrderItems, Errors errors) throws ApiException {
if (errors.hasErrors()) {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
try {
//OrderUpdate orderUpdate = ordersService.ordersIdPut(id, updateOrderItems, userid);
return new ResponseEntity<>(ordersService.ordersIdPut(id, updateOrderItems, userid), HttpStatus.OK);
} catch (OptimisticLockException ex) {
try {
DailyOrder dailyOrder = ordersService.ordersIdGet(id,updateOrderItems.getDailyMenuId(),updateOrderItems.getDailyMenuVersion(), updateOrderItems.getDailyMenuDate(), userid );
throw new ConcurrentModificationException(409, "Concurrent modification error.", dailyOrder);
} catch (ConcurrentDeletionException e) {
int exCode = e.getCode();
return new ResponseEntity<>(e.getResponseDTO() ,HttpStatus.valueOf(exCode));
} catch (ApiException ex1) {
Logger.getLogger(OrdersApiController.class.getName()).log(Level.SEVERE, null, ex1);
throw new ApiException(500, "Concurrent modification exception: internal error");
}
}
}
示例15: ordersPost
import org.springframework.validation.Errors; //导入方法依赖的package包/类
@Override
@PreAuthorize("hasAuthority('hungry')")
public ResponseEntity<Object> ordersPost(@ApiParam(value = "The order to place") @RequestBody Order order,
@ApiParam(value = "") @RequestParam(value = "userid", required = false, defaultValue = "0") Long userid, Errors errors) throws ApiException {
if (errors.hasErrors()) {
Error error = new Error();
error.setError("400");
error.setMessage("Validation Failed");
return new ResponseEntity<>(error, HttpStatus.BAD_REQUEST);
}
return new ResponseEntity<>(ordersService.ordersPost(order, userid), HttpStatus.OK);
}