Springboot-theymeleaf获取controller的model值

阅读 109

2022-06-27

theymeleaf 获取controller中的model值

  第一种方式:直接在html样式中获取

 

<span th:text="${name}"></span>



  • 例子


@RequestMapping(value = "/index", method=RequestMethod.GET)
public ModelAndView loginSuccess( @RequestParam(value="username", required = true) String username, ModelAndView model) {
model.setViewName("/index");
model.getModel().put("username", username);
return model;
}
  • index.html


<span th:text="${username}" style="color:red; font-weight:bold;"></span>

第二种方式:js中直接获取



var msg = [[${msg}]];



精彩评论(0)

0 0 举报