首页 > 解决方案 > 如何将 DTO 存储在 thymeleaf th:value 中?(春天,Java)

问题描述

我有这个 DTO 和各自的 getter 和 setter。

/** This class encapsulates the attributes of a JSON Schema database object. */ 
public class SchemaDto {

  /** The JSON String representation. */
  private String json;

  /** The note of the schema. */
  private String note;

  /** The date of the schema. */
  private LocalDate date;

...

  /** Returns a unique string representation of the schema. */
  @Override
  public String toString() {
    return date.format(DateTimeFormatter.ofPattern("dd.MM.yyyy")) + " - " + note;
  }
}

在我的 HTML 页面上,我想将数据库中的所有模式加载到 a 中<select />,并让用户按日期和注释选择模式,编辑模式并处理它。日期和注释组合起来是独一无二的。

<select th:field="*{s1Schema}"
        th:onchange="|setEditorText('s1-editor', '*{s1Schema.json}')|" >
    <option th:each="schema : ${schemas}"
            th:value="${schema}"
            th:text="${schema.toString()}"></option>
</select>

让我再解释一下代码:

我实际上需要SchemaDto. 和用于在选择中显示模式,并且date应该加载到 ace 编辑器。notejson

    /**
     * Sets the editor text.
     *
     * @param id The editor's id.
     * @param text The text to set.
     */
    const setEditorText = (id, text) => {
        let editor = ace.edit(id);
        editor.setValue(text, 1);
    }

我很乐意为您提供任何帮助!:)

标签: javahtmlspringthymeleafdto

解决方案


虽然我仍然不知道这是否可能,但我现在正在使用 Ajax 以避免重新加载。


推荐阅读