java - 如何将 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>
让我再解释一下代码:
th:field="*{s1Schema}"
: 应为 typeSchemaDto
。我想将它存储在会话中,以便在处理模式时选择和编辑器不会丢失。th:each="schema : ${schemas}"
是类型SchemaDto
,其中${schemas}
是List<SchemaDto>
th:value="${schema}"
:我想获取架构,SchemaDto
但是它schema.toString()
在传递给th:field
.
我实际上需要SchemaDto
. 和用于在选择中显示模式,并且date
应该加载到 ace 编辑器。note
json
/**
* 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);
}
我很乐意为您提供任何帮助!:)
解决方案
虽然我仍然不知道这是否可能,但我现在正在使用 Ajax 以避免重新加载。
推荐阅读
- c# - 使用 Find in Awake 缓存脚本引用,在 Start 中不起作用
- android - 如何在 JsonArray 中存储多行?
- python - 无法使用 pip 安装 blist
- c# - 当我提取元素时,c# List 的数组是否被移动?
- java - Map<> 中 entrySet() 上的 add() 方法
- python - 如何在Python中计算给定语料库的复数和单数数量
- c++11 - 类内初始化器到底是什么?
- php - WooCommerce 自定义字段 PHP 7 工作 PHP 7.1 和 7.2 不工作
- android - 向下滚动时 RecyclerView 列表消失了
- java - PhantomJS webdriver 无法加载 url