2017-01-16 542 views
0

这里是我的形式,输入字段电子邮件&密码Thymeleaf th:href获取其他输入字段值?

<form class="form-signin" th:action="@{/login}" method="post"> 
    <input type="email" name="email" id="inputEmail" class="form-control" placeholder="Email address" required="required" autofocus="autofocus" /> 
    <input type="password" name="password" id="inputPassword" class="form-control" placeholder="Password" required="required" /> 
    <button class="btn btn-lg btn-primary btn-block btn-signin" type="submit">Sign in</button> 
</form> 

我想尝试Thymeleaf th:href发送带参数的GET请求,

这里是我的代码:

<a href="#" th:href="@{/user/forgot_password{email}(email=$(inputEmail).val())}" class="forgot-password"> Forgot the password? </a> 

我弹簧启动控制器如下:

@RequestMapping(value = "/forgot_password", params = {"email!="}, method = RequestMethod.GET) 
public @ResponseBody RespCommon forgotPassword(
    @RequestParam(value = "email", required = true) String email) { 
    userService.forgotPassword(email); 
    return new RespCommon(ResultCode.SUCCESS, "Send forget password mail succeed"); 
} 

但是看起来不行,可以分享一下如何获得其他输入字段值,非常感谢!

回答

0

使用恢复密码的链接(因此使用GET方法)对我来说看起来不太好。例如,浏览器或电子邮件客户端可能会遵循它。

相反,我建议使用看起来像链接的表单(使用POST方法)。您可以将电子邮件放在hidden字段中,并将btn btn-link类添加到提交按钮。要填充电子邮件值,可以使用Model.addAttribute()从控制器导出值。

+0

是的,我也同意Slava Semushin ...电子邮件是一个机密问题,应该为任何外部获取请求进行加密,例如“取消订阅电子邮件”链接。即使你应该使用一个带有发布请求的表单,而不是获得方法@Tommy Yeh – Johir