Den*_* M. 2 java spring-mvc thymeleaf
有一个带有隐藏值字段的表单:
<input type = "hidden" th:field="*{key}" value="keyapp" />
<input type = "hidden" th:field="*{secret}" value="supersecret" />
Run Code Online (Sandbox Code Playgroud)
问题是这些字段在控制器中作为空传递。有没有办法通过 HTML 中预定义的值传递 thymeleaf 字段?
谢谢和亲切的问候,丹尼斯
更新:
th:object 定义:
<form th:action="@{..//do-login}" method="POST" modelAttribute="authEntity" th:object="${authEntity}">
Run Code Online (Sandbox Code Playgroud)
AuthEntity 类
public class AuthEntity {
private String key;
private String secret;
private String scope;
private String grantType;
private String username;
private String password;
// getters & setters omitted //
}
Run Code Online (Sandbox Code Playgroud)
控制器类
@RequestMapping(value = "/do-login", method = RequestMethod.POST, produces = "application/json")
public void doLogin(@ModelAttribute("authEntity") final AuthEntity authEntity,
final Model model, HttpServletResponse servletResponse,
HttpSession httpSession) throws IOException {
log.info("Application Key: {}, Secret: {}", authEntity.getKey(), authEntity.getSecret());
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1855 次 |
| 最近记录: |