将json传递给thymleaf

时间:2018-06-20 09:18:19

标签: spring thymeleaf

我在Spring中使用thymeleaf,并希望在视图端传递JSON。

@GetMapping(value = "/initiate/{teamplateName}")
ModelAndView
        index(@PathVariable("teamplateName") String templateName) {
    ModelAndView mav = new ModelAndView(templateName);
    System.out.println("Running this");
    System.out.println("Teample name is " + templateName);
    mav.addObject("data", "{ \"dy_t1\": \"This is the text 2\" , \"dy_Lorem\":\"This is the lorem text\"}");
    return mav;
}

在视图端点,我试图提取为{data.dy.t1},但显示错误。如何将JSON直接推入模板以读取值?

0 个答案:

没有答案