一、Jquery獲取Model中的數據
1、將model中的值賦給hidden,然后Js獲取隱藏域的值。
后台的實現:
@RequestMapping("/QEditorMod1") public String QEditorMod1(ModelMap model){ model.addAttribute("staff_name","cxx" ); return "questionEditorTemplate/QEditorMod1"; }
前端值的獲取
//將值賦給hidden域 <input type="hidden" th:value="${staff_name}" id="staff_name2"/> //Js 獲取hidden的隱藏域 var staff_name2=$("#staff_name2").val();
二、Thymeleaf 獲取model中的值
2、訪問model中的數據
//通過“${}”訪問model中的屬性 <div class="panel-body"> <span th:text="${singlePerson.name}"></span> </div>
3、在javascript中訪問model 目前沒有發現此種方法的應用場景
<script th:inline="javascript"> var single = [[${singlePerson}]];
//或(如果第一種方式不行使用第二種)
//var single = '[[${singlePerson.name}]]'; console.log(single.name+"/"+single.age) </script>
來源1:https://my.oschina.net/u/3421984/blog/1604188/
來源2:https://blog.csdn.net/qq_29072049/article/details/88642146