Reputation: 321
I have a bunch of controllers where I include the following
public class AController{
@GetMapping
public List<A> getallA() {...}
@GetMapping("/{index}")
public A getA(Long index){...}
}
and then that is repeated
public class BController{
@GetMapping
public List<B> getallB() {...}
@GetMapping("/{index}")
public B getB(Long index){...}
}
Is there a way to remove the repeated code through a custom annotation? Perhaps, a generic implementation? I have never done this so the help would be very helpful. Ideally it would be something like
@GetFunctions(A.something)
public class AController{
}
Upvotes: 0
Views: 487
Reputation: 360
Yes you can do something like pass name of the parameter as a path variable it will work try like the below example, Removing duplication from Spring controllers
If you want to have @RequestMappings with multiple values of attributes,
@RequestMapping({ "/index", "/contact" })
you can use like the above code snippet
Upvotes: 1