Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring MVC GetMapping未生效_Spring_Model View Controller - Fatal编程技术网

Spring MVC GetMapping未生效

Spring MVC GetMapping未生效,spring,model-view-controller,Spring,Model View Controller,我正在尝试SpringMVC,我尝试了@RequestMapping和@GetMaMapping注释。有一点是@GetMapping无法生效的。 代码如下: @Controller @RequestMapping(path="/service") public class ServiceEntry { @RequestMapping(path="/hello") @ResponseBody public String mainPage(){ return

我正在尝试SpringMVC,我尝试了@RequestMapping和@GetMaMapping注释。有一点是@GetMapping无法生效的。 代码如下:

@Controller
@RequestMapping(path="/service")
public class ServiceEntry {

    @RequestMapping(path="/hello")
    @ResponseBody
    public String mainPage(){
        return "Hello,Information";
    }

    @RequestMapping(path="/hello2", method = RequestMethod.GET)
    @ResponseBody
    public String page2(){
        return "hello2!";
    }

    @GetMapping(path="/test1")
    @ResponseBody
    public String page_test1(){
        return "Get method 1";
    }

    @GetMapping(path="/test2")
    @ResponseBody
    public String page_test2(){
        return "Get method 2";
    }
}

当我访问/service/hello或/service/hello2时,它工作,但是/service/test1或/service/test2不工作,请帮助我,谢谢

使用
代替
路径
。例如:
@GetMapping(value=“/test2”)

RequestMapping
中,可以使用参数
path
,但不能在
GetMapping
。您可以这样做:
GetMapping(“/test1”)
GetMapping(value=“/test1”)


你能使用下面的代码吗。我想这对你会有用的@GetMapping(“/test2”)