spring - 使用 pebble 模板在 Spring MVC 中获取 Json 响应
问题描述
我正在为我的 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
解决方案
我只需要添加@ResponseBody
我的方法即可解决问题。
推荐阅读
- java - 将“while”循环转换为“for”和“do while”
- ios - Twilio caller name on receive programmable voice call in ios application
- c++ - 检查数组的2个元素
- php - 无法在弹出式联系表单中输入内容
- java - 无法构建我的应用
- java - 在java中添加两个char数据类型
- c - 移动数据块——memcpy 还是 memmove?
- javascript - 用于重用的 Javascript 字符串模板
- ios - 如何使 Alamofire 中的会话无效?
- javascript - Nuxt.js 开发脚本失败