我能够验证表单并使用 Spring 表单标记显示 Spring 验证错误。我如何使用 jQuery Noty 插件显示这些错误,而不是显示为 HTML 标记?
控制器:
@RequestMapping(value = "/Register", method = RequestMethod.POST)
public ModelAndView Registeruser(@ModelAttribute("registerBean") @Valid RegisterBean registerBean, BindingResult bindingResult) {
ModelAndView mv = new ModelAndView();
if (bindingResult.hasErrors()) {
mv.setViewName("index");
mv.addObject(registerBean);
} else {
boolean registered = userservice.RegisterUser(registerBean);
if (registered) {
List<SimpleGrantedAuthority> authList = new ArrayList<SimpleGrantedAuthority>(1);
authList.add(new SimpleGrantedAuthority("ROLE_USER"));
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(registerBean.getEmail(), registerBean.getPassword(), authList);
SecurityContextHolder.getContext().setAuthentication(auth);
mv.setViewName("auth/Home");
} else {
mv.setViewName("index");
}
}
return mv;
}