Thymeleaf:无法传递隐藏 th:field 的预定义值

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)

N4z*_*oth 5

我遇到了与隐藏输入相同的问题,但没有找到解决方案,但没有使用 th:field,而是手动设置字段的 'id' 和 'name' 属性并省略 th:field。