java - thymeleaf和spring集成后Spring EL表达式无效
本文介绍了java - thymeleaf和spring集成后Spring EL表达式无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
表达式无法被解析的原因是什么?
Controller
页面标签
显示内容
解决方案
Spring的Controller方法里面 Model是通过方法参数注入进去的
类似于这样:
@RequestMapping("welcome")
public String welcome(Model model) {
model.addAttribute("whatever", new SomeObject());
return "welcome";
}
如果使用ModelAndView 要这样
@RequestMapping("welcome")
public ModelAndView welcome() {
ModelAndView mv = new ModelAndView("welcome");
mv.addObject("whatever", new SomeObject());
return mv;
}
另外View里难道不是应该这样写嘛
<tr>
<th th:text="#{whatever}">Name</th>
<th th:text="#{whatever}">Price</th>
</tr>
建议以后问问题 代码不要截图 用文本 最好附带完整源码放在git仓库里。
这篇关于java - thymeleaf和spring集成后Spring EL表达式无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文