有一个带有隐藏值字段的表单:
<input type = "hidden" th:field="*{key}" value="keyapp" />
<input type = "hidden" th:field="*{secret}" value="supersecret" />
问题是这些字段在控制器中作为空传递。有没有办法通过预定义的HTML值传递百万美元字段?
谢谢和亲切的问候, Deniss
更新
th:object
定义:
<form th:action="@{..//do-login}" method="POST" modelAttribute="authEntity" th:object="${authEntity}">
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 //
}
控制器类
@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());
}
答案 0 :(得分:4)
我遇到了与隐藏输入相同的问题并找不到解决方案但是,不是使用th:field,而是手动设置字段的'id'和'name'属性并省略th:field。