我遇到RedirectAttributes没有保存的问题(我认为)。这是我的代码:
@RequestMapping(path = "/job_offers", method = RequestMethod.POST)
public String createJobOffer(@Valid @ModelAttribute("jobOfferForm") JobOfferForm jobOfferForm,
final BindingResult binding, RedirectAttributes attr) {
attr.addFlashAttribute("org.springframework.validation.BindingResult.jobOfferForm", binding);
attr.addFlashAttribute("jobOfferForm", jobOfferForm);
return "redirect:/job_offers";
}
@RequestMapping(path = "/job_offers", method = RequestMethod.GET)
public ModelAndView jobOffers(@RequestParam(required = false, value = "skill_id") final Long skillId,
@ModelAttribute("jobOfferForm") JobOfferForm jobOfferForm, final BindingResult binding) {
ModelAndView mav = new ModelAndView("job_offers/index");
mav.addAllObjects(getJobOffersMap(skillId));
mav.addObject("jobOfferForm", jobOfferForm);
return mav;
}
如果我在POST方法中打印我的绑定它有错误,但是当我通过重定向调用GET方法时,绑定变为空!和Spring没有显示表单上的错误反馈
有什么想法吗? 谢谢!
答案 0 :(得分:0)
试试这个: 在你的POST中
swagger: '2.0'
info:
version: 1.0.0
title: Form data API
description: Using form data body parameters
paths:
/examples:
post:
consumes:
- application/x-www-form-urlencoded
parameters:
- name: grant_type
type: string
in: formData
- name: client_id
type: string
in: formData
- name: client_secret
type: string
in: formData
responses:
200:
description: OK
在GET中
attr.addFlashAttribute("bindignResultForJobOfferForm", binding);