ResponseBody 无法解析为类型
我正在尝试在我的控制器中编写此方法:
@ResponseBody
@RequestMapping(value = {"/getTeams"}, method = RequestMethod.GET)
public void getMaxRequestSize(HttpServletResponse response) {
String autoCompleteList = null;
List<Team> teams = atService.getAllTeams();
Iterator itr = teams.iterator();
while (itr.hasNext()) {
autoCompleteList += itr.next().toString() + "\n";
}
response.setContentType("text/html");
PrintWriter writer;
try {
writer = response.getWriter();
writer.write(autoCompleteList);
} catch (IOException e) {
e.printStackTrace();
}
}
出于某种原因,我总是在 ResponseBody 注释上收到错误(= 无法解析为类型)。我用谷歌搜索了很长一段时间,没有找到解决方案。我确信这是愚蠢的事情。我可以毫无问题地使用所有其他注释......
I'm trying to write this method in my controller:
@ResponseBody
@RequestMapping(value = {"/getTeams"}, method = RequestMethod.GET)
public void getMaxRequestSize(HttpServletResponse response) {
String autoCompleteList = null;
List<Team> teams = atService.getAllTeams();
Iterator itr = teams.iterator();
while (itr.hasNext()) {
autoCompleteList += itr.next().toString() + "\n";
}
response.setContentType("text/html");
PrintWriter writer;
try {
writer = response.getWriter();
writer.write(autoCompleteList);
} catch (IOException e) {
e.printStackTrace();
}
}
For some reason I always get an error on the ResponseBody annotation (= cannot be resolved to a type). I googled for quite a while and didn't find a solution. I'm sure it's something silly. I can use all the other annotations without any problems...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个 Maven 项目吗?您的 war 文件中可能会出现旧的 Spring 2.5.6 jar,而不是 Spring 3。Eclipse 的 POM 编辑器的 Dependency Hierarchy 选项卡可以帮助您确定是否是这种情况。
Is this a Maven project? You might be ending up with the old Spring 2.5.6 jars in your war file instead of Spring 3. Eclipse's POM editor's Dependency Hierarchy tab can help you figure out if that's the case.