沒有與隱藏的值字段的表單:Thymeleaf:不能通過隱藏理論值的預定義的值:字段
<input type = "hidden" th:field="*{key}" value="keyapp" />
<input type = "hidden" th:field="*{secret}" value="supersecret" />
的問題是,這些字段爲控制器空通過。有沒有一種方法可以通過預定義的HTML值傳遞thymeleaf字段?
感謝和親切的問候, Deniss
更新時間:
th:object
定義:
<form th:action="@{..//do-login}" method="POST" modelAttribute="authEntity" th:object="${authEntity}">
AuthEntity.class
public class AuthEntity {
private String key;
private String secret;
private String scope;
private String grantType;
private String username;
private String password;
... // getters & setters omitted // ...
* Controller.class
@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());
您如何定義表單?你定義了什麼'th:object'?而且這個對象有一個'key'和'secret'屬性?如果你已經把這些值放入ModelMap中,那麼你應該用'$ {key}'和'$ {secret}'引用它們' –
@ThomasPawlitzki看到上面的帖子已經更新。另請注意,所有其他參數只需使用'th:field'即可正確傳遞。 –
您是否設置了字段'key'和'secret'?你如何嘗試檢索MVC Handler中的值? –