0
点赞
收藏
分享

微信扫一扫

Springboot-theymeleaf获取controller的model值

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 条评论