Shellong
Shellong

Reputation: 381

Spring MVC GetMapping does not take effect

I'm trying Spring MVC,I tried @RequestMapping and @GetMampping annotation. There is something wired that @GetMapping doest not take effect. Below is the code:

@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";
    }
}

While I visit /service/hello or /service/hello2 it works, but /service/test1 or /service/test2 does not work, please help me, thanks!

Upvotes: 2

Views: 1053

Answers (2)

Berthol Yvano
Berthol Yvano

Reputation: 336

In RequestMapping you can use parameter path but not in GetMapping. You can do like this: GetMapping("/test1") or GetMapping(value="/test1")

Upvotes: 3

Frighi
Frighi

Reputation: 466

Use value instead path. EG: @GetMapping(value="/test2")

Upvotes: 1

Related Questions