0
在Spring Boot網絡應用程序中,User
想重置他的密碼,因此他輸入Reset password
頁面。現在我想讓他鍵入他的電子郵件地址,按Reset
,我想重定向到myapp/resetPassword?email=HIS_EMAIL
以處理密碼重置。請求參數與thymeleaf
我的代碼:
@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:/";
}
我怎樣才能實現呢我thymeleaf網頁上?我試過這樣的:
<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>
不幸的是我的email
總是空。有人可以幫忙嗎?
'錯誤400':'必需的字符串參數'電子郵件'不存在' – crooked
抱歉,我的錯。我編輯了@RequestParam。現在它應該工作。 – benkuly
Yeaa,現在我明白了:)感謝您的幫助!順便說一句。我的代碼實際上很糟糕:) – crooked