Spring MVC GetMapping未生效
我正在尝试SpringMVC,我尝试了@RequestMapping和@GetMaMapping注释。有一点是@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
@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”)