【问题标题】:Spring MVC GetMapping does not take effectSpring MVC GetMapping 不生效
【发布时间】:2018-08-08 15:17:35
【问题描述】:

我正在尝试 Spring MVC,我尝试了 @RequestMapping 和 @GetMampping 注释。有一些东西连线@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 不工作,请帮助我,谢谢!

【问题讨论】:

    标签: spring model-view-controller


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      使用value 代替path。例如:@GetMapping(value="/test2")

      【讨论】:

      • 你能用下面的代码吗?我认为这对你有用。 @GetMapping("/test2")
      猜你喜欢
      • 1970-01-01
      • 2021-04-22
      • 1970-01-01
      • 1970-01-01
      • 2020-07-30
      • 2020-05-07
      • 1970-01-01
      • 1970-01-01
      • 2021-01-06
      相关资源
      最近更新 更多