搜尋

首頁  >  問答  >  主體

java - thymeleaf和spring集成后Spring EL表达式无效

表达式无法被解析的原因是什么?
Controller

页面标签

显示内容

PHPzPHPz2889 天前464

全部回覆(1)我來回復

  • 巴扎黑

    巴扎黑2017-04-17 17:50:31

    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倉庫裡。

    回覆
    0
  • 取消回覆