在Thymeleaf中执行Java方法

在Thymeleaf中执行Java方法

可以在${....}中对后端传入的对象直接使用属于它的方法即可。

使用map的size()方法:

 @GetMapping("/en")
    public String en(ModelMap map) {
         HashMap<String, Integer> hashMap = new HashMap<>();
         hashMap.put("aa", 2);
         hashMap.put("a", 1);
         hashMap.put("aaa", 3);
         hashMap.put("aaaa", 4);
         map.addAttribute("words",hashMap);
...
<th th:text="|单词(${words.size()})|"></th>

 

 

posted @ 2020-05-10 04:08  假程序猿  阅读(1975)  评论(0)    收藏  举报