1. 程式人生 > >js獲取後臺Spring MVC資料

js獲取後臺Spring MVC資料

後臺Controller:

 @HtmlTitle(title = "Statistic")
    @RequestMapping("/statistic")
    public String statistic(Model model){
        List<SGo> sGos = sGoRepository.findAll();
        model.addAttribute("sGos",sGos);
        return "statistic/index-statistic";
    }

js程式碼:

<script th:inline="javascript"> 
        var GoEggNogNum = [[${sGos.get(0).nums}]];
        var GoNum = [[${sGos.get(1).nums}]];   
</script>