使用Pebble模板在Spring MVC中获取Json响应

问题描述 投票:0回答:1

我正在为我的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个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.