當前位置: 首頁>>代碼示例>>Java>>正文


Java BindingResult.hasErrors方法代碼示例

本文整理匯總了Java中org.springframework.validation.BindingResult.hasErrors方法的典型用法代碼示例。如果您正苦於以下問題:Java BindingResult.hasErrors方法的具體用法?Java BindingResult.hasErrors怎麽用?Java BindingResult.hasErrors使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.validation.BindingResult的用法示例。


在下文中一共展示了BindingResult.hasErrors方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createEvent

import org.springframework.validation.BindingResult; //導入方法依賴的package包/類
@RequestMapping(value = "/new", method = RequestMethod.POST)
public String createEvent(@Valid CreateEventForm createEventForm, BindingResult result,
        RedirectAttributes redirectAttributes) {
    if (result.hasErrors()) {
        return "events/create";
    }
    CalendarUser attendee = calendarService.findUserByEmail(createEventForm.getAttendeeEmail());
    if (attendee == null) {
        result.rejectValue("attendeeEmail", "attendeeEmail.missing",
                "Could not find a user for the provided Attendee Email");
    }
    if (result.hasErrors()) {
        return "events/create";
    }
    Event event = new Event();
    event.setAttendee(attendee);
    event.setDescription(createEventForm.getDescription());
    event.setOwner(userContext.getCurrentUser());
    event.setSummary(createEventForm.getSummary());
    event.setWhen(createEventForm.getWhen());
    calendarService.createEvent(event);
    redirectAttributes.addFlashAttribute("message", "Successfully added the new event");
    return "redirect:/events/my";
}
 
開發者ID:PacktPublishing,項目名稱:Spring-Security-Third-Edition,代碼行數:25,代碼來源:EventsController.java

示例2: signup

import org.springframework.validation.BindingResult; //導入方法依賴的package包/類
@RequestMapping(value="/signup/new",method=RequestMethod.POST)
public String signup(@Valid SignupForm signupForm, BindingResult result, RedirectAttributes redirectAttributes) {
    if(result.hasErrors()) {
        return "signup/form";
    }

    String email = signupForm.getEmail();
    if(calendarService.findUserByEmail(email) != null) {
        result.rejectValue("email", "errors.signup.email", "Email address is already in use.");
        return "signup/form";
    }

    CalendarUser user = new CalendarUser();
    user.setEmail(email);
    user.setFirstName(signupForm.getFirstName());
    user.setLastName(signupForm.getLastName());
    user.setPassword(signupForm.getPassword());

    int id = calendarService.createUser(user);
    user.setId(id);
    userContext.setCurrentUser(user);

    redirectAttributes.addFlashAttribute("message", "You have successfully signed up and logged in.");
    return "redirect:/";
}
 
開發者ID:PacktPublishing,項目名稱:Spring-Security-Third-Edition,代碼行數:26,代碼來源:SignupController.java

示例3: addCategory

import org.springframework.validation.BindingResult; //導入方法依賴的package包/類
@RequestMapping(value = "/categories/new", method = RequestMethod.POST)
public String addCategory(@Valid CategoryDTO categoryDTO,
                          BindingResult result,
                          SessionStatus status,
                          RedirectAttributes attributes) {
    if (result.hasErrors()) {
        return ADMIN_CATEGORIES_VIEW;
    } else {

        Category category = postService.createCategory(categoryDTO);
        logger.info("Category Added: {}", category.getCategoryValue());
        status.setComplete();

        webUI.addFeedbackMessage(attributes, FEEDBACK_MESSAGE_CATEGORY_ADDED, category.getCategoryValue());
        return "redirect:/admin/posts/categories";
    }
}
 
開發者ID:mintster,項目名稱:nixmash-blog,代碼行數:18,代碼來源:AdminPostsController.java

示例4: saveConnection

import org.springframework.validation.BindingResult; //導入方法依賴的package包/類
/**
 * 保存連接信息
 * @param form
 * @param bindingResult
 * @param session
 * @return
 */
@RequestMapping("connection/save.json")
@ResponseBody
public Map<String,Object> saveConnection(@Valid ZookeeperConnectForm form, BindingResult bindingResult, HttpSession session){
    if(bindingResult.hasErrors()){
        return Result.formErrorWrapper(bindingResult.getFieldError().getField(),bindingResult.getFieldError().getDefaultMessage());
    }
    ConnectionInfo connInfo = new ConnectionInfo();
    connInfo.setConnectUrl(form.getConnectString());
    connInfo.setAcl(form.getAcl());
    connInfo.setOwner(ShiroUtils.getCurrUser().getLoginName());
    connInfo.setRemark(form.getRemark()==null?"未命名":form.getRemark());
    connInfo.setSessionTimeout(form.getSessionTimeout());
    try {
        coreService.saveConnection(connInfo);
    } catch (DataExistException e) {
        return Result.errorWrapper(e.getMessage());
    }

    return Result.SIMPLE_SUCCESS;
}
 
開發者ID:liaojiacan,項目名稱:zkAdmin,代碼行數:28,代碼來源:CoreController.java

示例5: createUser

import org.springframework.validation.BindingResult; //導入方法依賴的package包/類
@PostMapping("/create")
public String createUser(@Valid CreateUserForm form,
                         BindingResult bindingResult,
                         RedirectAttributes redirectAttributes) {
    if (bindingResult.hasErrors()) {
        redirectAttributes.addFlashAttribute("flashMessage", "admin.users.create.error." + bindingResult.getFieldError().getField());

        return "redirect:/admin/users";
    }
    boolean error = false;
    try{
    	userCreationService.create(form.toUisUser());
    }catch(ValidationException e){
    	error = true;
        redirectAttributes.addFlashAttribute("flashMessage", "admin.users.create.error.email");
    }
    if(!error){
    	redirectAttributes.addFlashAttribute("flashMessage", "admin.users.create.success");
    }
    
    return "redirect:/admin/users";
}
 
開發者ID:university-information-system,項目名稱:uis,代碼行數:23,代碼來源:AdminUsersController.java

示例6: addUser

import org.springframework.validation.BindingResult; //導入方法依賴的package包/類
@RequestMapping(value = "/users/new", method = RequestMethod.POST)
public String addUser(@Valid UserDTO userDTO,
                      BindingResult result, SessionStatus status, Model model,
                      RedirectAttributes attributes) {
    if (result.hasErrors()) {
        model.addAttribute("authorities", userService.getRoles());
        return ADMIN_USERFORM_VIEW;
    } else {
        userDTO.setSignInProvider(SignInProvider.SITE);
        User added = userService.create(userDTO);
        logger.info("Added user with information: {}", added);
        status.setComplete();

        webUI.addFeedbackMessage(attributes, FEEDBACK_MESSAGE_KEY_USER_ADDED, added.getFirstName(),
                added.getLastName());

        return "redirect:/admin/users";
    }
}
 
開發者ID:mintster,項目名稱:nixmash-blog,代碼行數:20,代碼來源:AdminController.java

示例7: comprar

import org.springframework.validation.BindingResult; //導入方法依賴的package包/類
@RequestMapping(value = "/FinalizarCompraSegura")
public String comprar(Model model, @Valid Pedido pedido, HttpSession session, BindingResult result) {
	
	Cliente cliente = (Cliente) session.getAttribute("clienteLogado");
	Carrinho carrinho = (Carrinho) session.getAttribute("carrinho");
	
	// Gerar numero randomico
	int min = 100000000;//na vdd s�o 14 campos
	int max = 999999999;
	int numb_ped = ThreadLocalRandom.current().nextInt(min, max + 1);
	
	pedido.setNumero_ped(numb_ped);
	
	if(result.hasErrors()) {
	    return "forward:forma_de_pagamento";
	} else {
		carrinho.removeAll();
		session.setAttribute("carrinho", carrinho);
		Long id = dao.create(pedido, carrinho, cliente);
		return "redirect:boleto/"+id;
	}
}
 
開發者ID:iurigodoy,項目名稱:Monsters_Portal,代碼行數:23,代碼來源:ComprarController.java

示例8: createEvent

import org.springframework.validation.BindingResult; //導入方法依賴的package包/類
@PostMapping(value = "/new")
public String createEvent(@Valid CreateEventForm createEventForm, BindingResult result,
        RedirectAttributes redirectAttributes) {
    if (result.hasErrors()) {
        return "events/create";
    }
    CalendarUser attendee = calendarService.findUserByEmail(createEventForm.getAttendeeEmail());
    if (attendee == null) {
        result.rejectValue("attendeeEmail", "attendeeEmail.missing",
                "Could not find a user for the provided Attendee Email");
    }
    if (result.hasErrors()) {
        return "events/create";
    }
    Event event = new Event();
    event.setAttendee(attendee);
    event.setDescription(createEventForm.getDescription());
    event.setOwner(userContext.getCurrentUser());
    event.setSummary(createEventForm.getSummary());
    event.setWhen(createEventForm.getWhen());
    calendarService.createEvent(event);
    redirectAttributes.addFlashAttribute("message", "Successfully added the new event");
    return "redirect:/events/my";
}
 
開發者ID:PacktPublishing,項目名稱:Spring-Security-Third-Edition,代碼行數:25,代碼來源:EventsController.java

示例9: signup

import org.springframework.validation.BindingResult; //導入方法依賴的package包/類
@RequestMapping(value="/signup/new",method=RequestMethod.POST)
public String signup(@Valid SignupForm signupForm, BindingResult result, RedirectAttributes redirectAttributes) {
    if(result.hasErrors()) {
        return "signup/form";
    }

    String email = signupForm.getEmail();
    if(calendarService.findUserByEmail(email) != null) {
        result.rejectValue("email", "errors.signup.email", "Email address is already in use.");
        return "signup/form";
    }

    CalendarUser user = new CalendarUser();
    user.setEmail(email);
    user.setFirstName(signupForm.getFirstName());
    user.setLastName(signupForm.getLastName());
    user.setPassword(signupForm.getPassword());

    logger.info("CalendarUser: {}", user);

    int id = calendarService.createUser(user);
    user.setId(id);
    userContext.setCurrentUser(user);

    redirectAttributes.addFlashAttribute("message", "You have successfully signed up and logged in.");
    return "redirect:/";
}
 
開發者ID:PacktPublishing,項目名稱:Spring-Security-Third-Edition,代碼行數:28,代碼來源:SignupController.java

示例10: signup

import org.springframework.validation.BindingResult; //導入方法依賴的package包/類
@PostMapping(value="/signup/new")
public String signup(@Valid SignupForm signupForm, BindingResult result, RedirectAttributes redirectAttributes) {
    if(result.hasErrors()) {
        return "signup/form";
    }

    String email = signupForm.getEmail();
    if(calendarService.findUserByEmail(email) != null) {
        result.rejectValue("email", "errors.signup.email", "Email address is already in use.");
        return "signup/form";
    }

    CalendarUser user = new CalendarUser();
    user.setEmail(email);
    user.setFirstName(signupForm.getFirstName());
    user.setLastName(signupForm.getLastName());
    user.setPassword(signupForm.getPassword());

    logger.info("CalendarUser: {}", user);

    int id = calendarService.createUser(user);
    user.setId(id);
    userContext.setCurrentUser(user);

    redirectAttributes.addFlashAttribute("message", "You have successfully signed up and logged in.");
    return "redirect:/";
}
 
開發者ID:PacktPublishing,項目名稱:Spring-Security-Third-Edition,代碼行數:28,代碼來源:SignupController.java

示例11: postUser

import org.springframework.validation.BindingResult; //導入方法依賴的package包/類
/**
 *  創建用戶
 *    處理 "/users" 的 POST 請求,用來獲取用戶列表
 *    通過 @ModelAttribute 綁定參數,也通過 @RequestParam 從頁麵中傳遞參數
 */
@RequestMapping(value = "/create", method = RequestMethod.POST)
public String postUser(ModelMap map,
                       @ModelAttribute @Valid User user,
                       BindingResult bindingResult) {

    if (bindingResult.hasErrors()) {
        map.addAttribute("action", "create");
        return "userForm";
    }

    userService.insertByUser(user);

    return "redirect:/users/";
}
 
開發者ID:JeffLi1993,項目名稱:springboot-learning-example,代碼行數:20,代碼來源:UserController.java

示例12: submitForm

import org.springframework.validation.BindingResult; //導入方法依賴的package包/類
@RequestMapping(method=RequestMethod.POST)
public String submitForm(Model model, @ModelAttribute("employeeForm") @Validated EmployeeForm employeeForm, BindingResult result ){
	model.addAttribute("employeeForm", employeeForm);
	validator.validate(employeeForm, result);
	if(result.hasErrors()){
		return "form_page";
	}
	return "success_page";
}
 
開發者ID:PacktPublishing,項目名稱:Spring-5.0-Cookbook,代碼行數:10,代碼來源:FormController.java

示例13: create

import org.springframework.validation.BindingResult; //導入方法依賴的package包/類
@RequestMapping("Admin/CreateBanner")
public String create(HttpSession session, @Valid Banner banner, BindingResult result) {
	if(Permissoes.checar(session, EnumMetodo.CRIAR, entidade)){				//	Checar Permissão
		if(result.hasErrors()) {											//	Se houver erro na validação
		    return "forward:banner";										//	Volte para a página de adição
		} else {
			dao.create(banner);												//	Ação no banco
			relatorio.gerarRelatorio(session, EnumMetodo.CRIAR, entidade);	//	Relatório
			return "redirect:banner";										//	Retorna para o método Read
		}
	}
	return "403";
}
 
開發者ID:iurigodoy,項目名稱:Monsters_Portal,代碼行數:14,代碼來源:BannerController.java

示例14: update

import org.springframework.validation.BindingResult; //導入方法依賴的package包/類
@RequestMapping("Admin/Updateimagem")
public String update(@Valid Imagem imagem, BindingResult result) {

	if(result.hasErrors()) {												//	Se houver erro na validação
	    return "forward:Produto";											//	Volte
	} else {
		dao.update(imagem);													//	Ação no banco
		return "redirect:Produto";											//	Retorna para o método Read
	}
}
 
開發者ID:iurigodoy,項目名稱:Monsters_Portal,代碼行數:11,代碼來源:ImagemController.java

示例15: addArticle

import org.springframework.validation.BindingResult; //導入方法依賴的package包/類
@ApiOperation(value="admin-新增文章")
@PostMapping
public RestResponse addArticle(@RequestBody @Valid AddArticleParam param, BindingResult result) {
    if (result.hasErrors()) {
       return buildErrors(result.getAllErrors());
    }
    return RestResponse.success(articleService.addArticle(param));
}
 
開發者ID:fku233,項目名稱:Plum,代碼行數:9,代碼來源:AdminArticleController.java


注:本文中的org.springframework.validation.BindingResult.hasErrors方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。