[英]How to access List inside Map in Thymeleaf?
Consider the following map, 考虑以下地图,
Map<String, List<String>> map=new HashMap<>();
I would like to put values into this map using thymeleaf. 我想使用百里香在此地图中添加值。 Now, how to insert list items into the map in thymeleaf. 现在,如何在百里香中将列表项插入到地图中。
For, Map<String,String>
we would write something like map['key']=val;
对于Map<String,String>
我们将编写类似于map['key']=val;
How to do it for lists? 如何做清单? One way, I thought was keeping the List<String>
in a class. 我认为一种方法是将List<String>
保留在一个类中。 For example, 例如,
class ListWrapper
{
public List<String> list=new ArrayList<>();
// setter and getter methods
}
and then write the map as 然后将地图写为
Map<String, ListWrapper> map=new HashMap<>();
and insert like this.. 然后像这样插入
map['key'].list[0]='item 1';
map['key'].list[1]='item 2';
Is there any direct way, instead of writing a class unnecessarily? 有什么直接的方法,而不是不必要地编写类?
Thanks in advance. 提前致谢。
You don't need to write a class - you can use Guava's ListMulitMap . 您不需要编写类-您可以使用Guava的ListMulitMap 。 Check out these examples . 查看这些示例 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.