angular - Spring,Angular.js 415 不支持的媒体类型错误
问题描述
这个简单的请求遇到了 415 Unsupported Media Type 错误。
http://localhost:8080/semantic/api/getLastfmGraph/1
这是我的控制器代码:
@RequestMapping(value = "/getLastfmGraph/{userId}", method = RequestMethod.GET, consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
public
@ResponseBody
Object getLastfmGraph(@PathVariable Long userId) throws Exception {
User user = semanticGraphDao.findUserById(userId);
List<Node> nodes = lastfm.topArtistsByUser(user.getLastfmUsername());
List<Link> links = new ArrayList<>();
for (Node n : nodes) {
for (Node n2 : nodes) {
if(!StringUtils.equals(n.getName(),n2.getName()))
links.add(new Link(n, n2, 1.0));
}
}
return new Graph(nodes,links);
}
解决方案
我通过删除 consumes='application/json' 解决了这个问题。
推荐阅读
- django - Django - 在使用表单的调查应用程序中是否有必要使用表单集?
- node.js - 如何获取Nodejs中单个表单中多个按钮的值
- angular - 升级 Angular Universal SSR 项目:AppServerModuleNgFactory 未定义
- c++ - 为什么我得到一个 Expression is not assignable 错误
- sql-server - 使用python从linux服务器访问MSsql服务器
- python - 如何使用 Vegalite 对区域和文本图表进行分层?
- python - 使用时间戳对 pandas 数据帧进行索引会产生值错误
- python - 如何将 TfIdfvectorizer 与其余列结合起来
- java - 用于构建以下方阵的 Java 函数
- c++ - ofstream 具有自定义名称和路径