在Spring Boot Web应用程序中,User想要重置密码,因此他进入Reset password页面.现在我想让他输入他的电子邮件地址,推送Reset,我想重定向myapp/resetPassword?email=HIS_EMAIL到处理密码重置.
我的代码:
@RequestMapping(value = "/resetPassword", method = RequestMethod.GET)
public String resetPasswordForm(Model model){
model.addAttribute("email", new String());
return "resetPassword";
}
@RequestMapping(value = "/resetPassword", method = RequestMethod.POST)
public String resetPassword(@RequestParam("email") String email) {
User user = userService.findUserByEmail(email);
//playing with logic
return "redirect:/";
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能在我的百里叶页面上实现它?我试过这样的事情:
<form th:action="@{/resetPassword(email=${email})}" method="post">
<input type="email" th:field="${email}" th:placeholder="Email" />
<div class="clearfix">
<button type="submit">Reset</button>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
不幸的是我email的总是空的.有人可以帮忙吗?
"th:field"仅适用于Entity-Beans.这应该工作:
@GetMapping(value = "/resetPassword")
public String resetPassword(@RequestParam(value="email",required=false) String email) {
if(email==null)
return "resetPassword";
User user = userService.findUserByEmail(email);
//playing with logic
return "redirect:/";
}
<form th:action="@{/resetPassword}" method="get">
<input type="email" th:name="email" th:placeholder="Email" />
<div class="clearfix">
<button type="submit">Reset</button>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
不要忘记:Thymeleaf不是Javascript.它在服务器上呈现.想想@{/resetPassword(email=${email})}会输出例如/resetPassword?email=anValueYouAddedToModelInController
| 归档时间: |
|
| 查看次数: |
11923 次 |
| 最近记录: |