我正在创建一个带有标签的表单,它看起来是这样的:<form th:object="${version}" method="post" class="form-horizontal"> ... <div class="control-group" th:classappend="${#fields.hasErrors('product')} ? 'error'"> <label class="control-label" for="product" th:text="#{version.product}">Product</label> <div class="controls"> <select id="product" th:field="*{product}"> <option value="" th:text="#{common.select.prompt}"></option> <option th:each="p : ${productList}" th:value="${p.id}" th:text="${p.name}"></option> </select> <span class="help-inline" th:errors="*{product}"></span> </div> </div> ... </form> Spring Data JPA 的 DomainClassConverter 类有助于在提交表单时将选定的 id 自动转换为实体 Product。同时,product 字段应该不为空(我在 Version 类中使用了 @NotNull 注解)。我的问题是:当我回来编辑数据时,Product 没有被选中。如果我像这样修改 select (使用了 th:field 和 th:errors):<-- p.s. 不是悲伤的笑容 <select id="product" th:field="*{product.id}"> <option value="" th:text="#{common.select.prompt}"></option> <option th:each="p : ${productList}" th:value="${p.id}" th:text="${p.name}"></option> </select> <span class="help-inline" th:errors="*{product.id}"></span> 当我重新编辑时,它会变成所选状态,但验证器不起作用(product总是被实例化,即使选定的id为null)。 看起来像是一个非常常见的情况(从列表中选择实体),但我找不到任何好看的例子。请分享秘密知识。