thymeleaf遍历map集合输出key+value

     
 

blogId,key---->命名规范改为blogId,blogIdStat  

list,treemap一样可以用current得到当前遍历的元素的各种索引和key value 甚至集合大小。 还有index,count等等属性 keysMap是mv对象带过来的hashmap. 其他如session servletcontext是需要前缀的 session,application,如果使用thymeleaf内置对象httpRequest则需要使用# 。

blogIdStat相等于foreach的变量【该变量在thymeleaf中有默认值是varStat,但是也可以向我这样随便取个名字,就是为了自己方便,知道意思】,current表示thymeleaf中指向当前正在遍历的元素的node(节点)。value是该节点的值,key是键 

${blogIdStat.current.value}" 即表示获取当前元素的值,key.current.key是当前元素的键【这里因为我的集合是hashmap,所以有这个key】

blogIdStat就是这个key,我这个名字意思是我代表关键字的, 容易引起混乱,命名还是规范点用blogIdStat

 th:each="blogId,blogIdStat: ${keysMap}"

4月15日

该代码功能是存储存档(hashmap),显示存档信息,且与文章id相关联

 

你可能感兴趣的:(JavaEE,SpringBoot)