- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要将 comment 元素发送到 HTML。
没有comment DTO
,它实际上是TaskComment
。我在 Task 类中定义了这样的
@ElementCollection
private Set<TaskComment> comments;
在taskcomment
中,因为是model
类,所以有一些属性,例如:
private String message;
public String getUser() {
return user;
}
private ZonedDateTime createdAt = ZonedDateTime.now();
private String createdAtString;
我像这样定义params
Map<String, Object> params = prepareParams(task);
我将评论放入其中,如下所示:
params.put("commentsAdded", Collections.singletonList(comment));
没有任何问题,我可以看到我的 html,如下所示:
<tbody>
<tr th:each="addedComment : ${commentsAdded}">
<td th:text="${addedComment.user}">user...</td>
<td th:text="${addedComment.message}">message ...</td>
</tr> </tbody>
我不知道为什么我们要使用每个评论对象,只有一个评论对象。
但是当我想放置comment
的elementcollection时,它给出了错误。
@ElementCollection
private Set<TaskComment> comments;
我试过了
params.put("commentsInTask",new ArrayList(Arrays.asList(task.getComments())));
但在 html 中
<tr th:each="addedComment : ${commentsInTask}">
<td th:text="${addedComment.user}">user...</td>
<td th:text="${addedComment.message}">message ...</td>
对于
<td th:text="${addedComment.user}">user...</td>
该行给出了错误。我认为它在错误后停止了,可能也会给其他林带来错误。
我尝试放入singletonMap
,但它不是 HashMap 。这是 Collection 。
我试图把
params.put("commentsInTaskk",new ArrayList(Arrays.asList(task.getComments())));
但我无法让它工作。我认为这会起作用。或者我做错了。
你有什么建议?
我使用 spring boot + intellij。
例如,当我在 html 中使用它时
<tr th:each="addedComment : ${commentsInTask}">
<td th:text="${addedComment.key}">key ...</td>
<td th:text="${addedComment.value.user}">value.user...</td>
错误是:
org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "addedComment.key" (task_comment_cta:29)
最佳答案
我确实喜欢这个并且工作
<tr th:each="allComments : ${commentsInTask}">
<tr th:each="comment : ${allComments}">
<td th:text="${comment.user}">user ...</td>
关于java - 在 singletonlist 中发送 elementcollection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40100816/
在Java中,Collections.SingletonList()有什么用处?我知道它返回一个只有一个元素的列表。为什么我要有一个单独的方法来做这件事呢?不变性在这里起到了怎样的作用?。这个方法有什
与 Collections.singletonList(something) 相比,使用 Arrays.asList(something) 来制作一个列表是否有优势(或有很大的不同)?后者也使返回的列
我需要将 comment 元素发送到 HTML。 没有comment DTO,它实际上是TaskComment。我在 Task 类中定义了这样的 @ElementCollection priv
我有一个相当大的流管道,因此想保持它的清洁。我有以下部分更大的管道 Integer defaultInt; //... Stream ints; ints.filter(/* predicate_go
如何将 java.util.Collections$UnmodifiableRandomAccessList 转换为 Collections.singletonList?为了在两个服务之间存储 ses
Java 9 引入了工厂方法以使用 List.of 创建不可变列表。 哪个更适合创建一个元素的不可变列表? List immutableList1 = List.of("one");
据我所知,这两种 Collection 方法都提供对返回列表的只读访问并在修改时抛出异常。 我需要了解两者的用例,以便何时使用 singletonList 和 unmodifiableList。 这可
假设我有这个代码: String[] left = { "1", "2" }; String[] leftNew = Collections.emptyList().toArray(left); Sy
我不明白为什么lombok使用singletonList,这里有一个演示: @Cleanup FileInputStream fos = new FileInputStream("aa.txt");
我知道如果我有元素,我想得到 List/Set/Map 我可以调用这个元素: Collections.singleton()/Collections.singletonList()/Collectio
给定集合: Collection expected = Collections.singletonList(new MyObject); Collection actual = Collections
我是一名优秀的程序员,十分优秀!