我知道这个问题被问了一百万遍了,但是我浏览了很多,似乎没有什么帮助,所以我问自己一个。我正在尝试注册新用户,如spring.io指南中所示,但我收到此错误。 我的控制器:
@Controller
@RequestMapping("/registration")
public class UserRegistrationController {
private static final Logger logger = Logger.getLogger(UserRegistrationController.class);
@Autowired
private UserService userService;
@Autowired
private SecurityService securityService;
@Autowired
private UserValidator userValidator;
@RequestMapping(method = RequestMethod.GET)
public ModelAndView registration() {
logger.info("registration page shown");
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("userForm", new User());
modelAndView.setViewName("registration");
return modelAndView;
}
@RequestMapping(value = "/registration", method = RequestMethod.POST)
public String registration(@ModelAttribute("userForm") User userForm, BindingResult bindingResult) {
userValidator.validate(userForm, bindingResult);
if (bindingResult.hasErrors()) {
return "registration";
}
userService.save(userForm);
securityService.autoLogin(userForm.getUsername(), userForm.getPassword());
return "redirect:/welcome";
}
}
我的html:
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<h1>Registration</h1>
<form th:action="@{/registration}" th:object="${userForm}" method="post" class="form-signin">
<h2 class="form-signin-heading">Create your account</h2>
<div class="form-group ${status.error ? 'has-error' : ''}">
<input type="text" th:field="*{username}" class="form-control" placeholder="Username"
autofocus="true"/>
</div>
<div class="form-group ${status.error ? 'has-error' : ''}">
<input type="password" th:field="*{password}" class="form-control" placeholder="Password"/>
</div>
<div class="form-group ${status.error ? 'has-error' : ''}">
<input type="password" th:field="*{confirmPassword}" class="form-control"
placeholder="Confirm your password"/>
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit">Submit</button>
</form:form>
</form>
</div>
</div>
</div>
任何建议都会被理解