idea中使用thymeleaf 模板 th:each(th:each=“user:${users} 报错Cannot resolve ‘user‘

一、 报错信息

这时候检查
检查:

.html文件中的users是否和Controller文件对应(users)
如果上述还没问题 users下面会有一个小的波浪线
但是运行时候还无影响
可以尝试关闭thymeleaf的提示

二 、可能原因是:

idea 对 thymeleaf 模板校验问题。
在这里插入图片描述

三、另一类错误

在Spring boot项目中,整合Thymeleaf模板引擎,在html文件中使用th:text="${msg}"属性标签时,提示报错“无法解析msg”。

th:text="${msg}"

加下面写的注释就可以取消掉msg下面红色的波浪线
在这里插入图片描述
或者还可以把String改成Object

@Controller
public class ThymeleafController {
    @GetMapping("/home")
    public String test1(Model model){
        model.addAttribute("msg", "Welcome to home page! Enjoy yourself,please!");
        return "home";
    }
}  

改成这个样子

@Controller
public class ThymeleafController {
    @GetMapping("/home")
    public Object test1(Model model){
        model.addAttribute("msg", "Welcome to home page! Enjoy yourself,please!");
        return "home";
    }
}

posted @   依嘫  阅读(155)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示