我目前正在将许多.jsp
页面转换为HTML
使用Thymeleaf
. 我已经成功转换了其中一些,但是在检查带有表单标签的任何页面时,我收到以下错误:
Attribute name cannot be null or empty during the initial page load.
查看代码
<!-- Registration Form -->
<form action="#" th:action="@{/register/processRegistrationForm}" th:object="${user}" method="POST" class="form-horizontal">
<!-- User name -->
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input type="text" th:field:="*{userName}" placeholder="Username (*)" class="form-control" />
</div>
<!-- Password -->
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
<input type="text" th:field:="*{password}" placeholder="First Name (*)" class="form-control" />
</div>
控制器代码
@GetMapping("/showRegistrationForm")
public String showMyRegistrationPage(
Model theModel) {
theModel.addAttribute("user", new UserRegistrationDto());
return "Login/registration-form";
}
@PostMapping("/processRegistrationForm")
public String processRegistrationForm(
@Valid @ModelAttribute ("user") UserRegistrationDto userDto,
BindingResult theBindingResult,
Model theModel) {
String userName = userDto.getUserName();
logger.info("Processing registration form for: " + userName);
// form validation
if (theBindingResult.hasErrors()){
return "Login/registration-form";
}
森栏
杨__羊羊
繁星coding
相关分类