2

If you have two classes, both with "" (nothing) mapped to the class level, and there are several @RequestMapping annotated methods in each, but none of the methods' mappings conflict with each other, will it work? If not, how could you achieve the desired result with two controllers?

@Controller
@RequestMapping()
public class Controller1 {

   @RequestMapping("pageA")
   public void someMethodA() {
       // do something later
   }

   @RequestMapping("pageC")
   public void someMethodC() {
       // do something later
   }

}

@Controller
@RequestMapping()
public class Controller2 {

   @RequestMapping("pageB")
   public void someMethodB() {
       // do something later
   }

   @RequestMapping("pageE")
   public void someMethodE() {
           // do something later
       }

}
David Neuschulz
  • 113
  • 1
  • 8

1 Answers1

3

If you have two classes, both with "" (nothing) mapped to the class level, and there are several @RequestMapping annotated methods in each, but none of the methods' mappings conflict with each other, will it work?

Yes it will work.

If you want same url pattern for all your endpoint (let's just say @RequestMapping(path = "/item-service/v1") ) another option is to add that as a context path instead of adding it to every Controller.

so-random-dude
  • 15,277
  • 10
  • 68
  • 113