【问题标题】:Getting Json response in Spring MVC using pebble template使用 pebble 模板在 Spring MVC 中获取 Json 响应
【发布时间】:2020-01-21 17:58:34
【问题描述】:

我正在为我的 Spring MVC 应用程序使用 pebble 模板。对于特定的 API 调用,有没有办法将 JSON 响应对象而不是 HTML 模板返回给客户端?

当我尝试发送 JSON 对象时,出现以下异常。

com.mitchellbosecke.pebble.error.LoaderException: Could not find template "templates/test/1.html" (?:?)
        at com.mitchellbosecke.pebble.loader.ClasspathLoader.getReader(ClasspathLoader.java:74)
        at com.mitchellbosecke.pebble.loader.ClasspathLoader.getReader(ClasspathLoader.java:26)
....
....
Caused by 
org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation

【问题讨论】:

    标签: spring spring-mvc thymeleaf spring-restcontroller


    【解决方案1】:

    我只需要在我的方法中添加 @ResponseBody 即可解决问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-28
      • 2017-07-27
      • 2011-05-11
      • 2014-12-23
      • 1970-01-01
      • 2012-07-02
      • 1970-01-01
      • 2014-07-02
      相关资源
      最近更新 更多