简体   繁体   English

给出错误的注释 RequestMapping()

[英]Annotation RequestMapping() giving the error

I am starting with Spring Boot and trying to make a Rest service.我从 Spring Boot 开始并尝试创建一个 Rest 服务。 I am writing a controller where there are RequestMappings to 3 methods.我正在编写一个控制器,其中有 3 个方法的 RequestMappings。 Two of them are working fine while the thirl annotation is giving this error while writing the code.其中两个工作正常,而 thirl 注释在编写代码时出现此错误。

Multiple markers at this line - Syntax error, insert "enum Identifier" to complete EnumHeader - Syntax error, insert "EnumBody" to complete EnumDeclaration此行有多个标记 - 语法错误,插入“enum Identifier”以完成 EnumHeader - 语法错误,插入“EnumBody”以完成 EnumDeclaration

I tried everything from other answers but cant seem to find out the issue.我尝试了其他答案中的所有内容,但似乎无法找出问题所在。 Here is my code for the Controller-这是我的控制器代码-

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")

} }

The error is coming in the last line ie last Requestmapping().错误出现在最后一行,即最后一个 Requestmapping()。

A bit late but for those that are just finding this issue: You need to type in the actual method under the @RequestMapping.有点晚了,但对于那些刚刚发现这个问题的人:您需要在@RequestMapping 下输入实际方法。 Eclipse gives an issue when you stop at this stage but once you write your method, you are good to go.当您在此阶段停止时 Eclipse 会出现问题,但是一旦您编写了您的方法,您就可以开始了。 At least that is what worked for me.至少这对我有用。

So:所以:

@RequestMapping(method=RequestMethod.POST,value="/topics")
public ... {
//your method
}

您正在为两种方法编写 /topics URL,一种用于 GET,一种用于 POST,Spring 不支持此配置,您可以更改两种不同方法的 url,也可以编写具有 url /topics 和 HttpMethod 数组的单个方法,例如方法 = { RequestMethod.GET, RequestMethod.POST }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM