【发布时间】:2018-08-06 13:16:03
【问题描述】:
我从 Spring Boot 开始并尝试提供 Rest 服务。 我正在编写一个控制器,其中有 3 种方法的 RequestMappings。 其中两个工作正常,而 thirl 注释在编写代码时出现此错误。
此行有多个标记 - 语法错误,插入“枚举标识符”以完成 EnumHeader - 语法错误,插入“EnumBody”来完成EnumDeclaration
我尝试了其他答案中的所有内容,但似乎无法找出问题所在。这是我的控制器代码-
package io.springboot.topics;
import java.util.Arrays;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TopicsController {
@Autowired
private TopicSrvice topicService;
@RequestMapping("/topics")
public List<Topic> getAllTopics() {
return topicService.getAllTopics();
}
@RequestMapping("/topics/{id}")
public Topic getTopic(@PathVariable String id) {
return topicService.getTopic(id);
}
@RequestMapping(method=RequestMethod.POST,value="/topics")
}
错误出现在最后一行,即最后一个 Requestmapping()。
【问题讨论】:
-
最后一个
RequestMapping的方法在哪里? -
您是否尝试过使用 GetMapping 和 PostMapping 而不是 RequestMapping 来注释方法?
-
是的。我尝试过这个。那也行不通。我不明白,如果它适用于上述两种情况,为什么它会在第三种情况下给出这个编辑器错误?我是否缺少某些语法或其他内容?
-
请将该方法添加到您的问题中。你显然忘了添加它。
-
您是否也遇到任何运行时或编译时错误?
标签: java spring rest spring-mvc spring-boot