0

I'm reading up on Spring MVC and trying some tutorials and came up with a quick question about the @RequestMapping annotation.

Let's assume I have a project with hundreds of mappings, like below (assume they are all within their own Controller class)

@RequestMapping("/front")
@RequestMapping("/away")
@RequestMapping("/behind")
@RequestMapping("/side")

I could see this getting quite messy to maintain at some point in an enterprise sized application. Does anyone know if there's a way to "map" all the request paths in a user friendly way? Are there any best practices when dealing with these annotation based mappings?

1
  • Modularizing the application is the best way to organize the request Mappings. Segregate all the mappings under different modules and this will the more user friendly approach for developing large complex applications Commented Jun 28, 2016 at 12:44

2 Answers 2

1

You need to collect every mapping into appropriate controller meaningfully.

For example: CustomerController

Class level mapping:

  • @RequestMapping("/customer")

Method level mapping:

  • @RequestMapping("/create")
  • @RequestMapping("/delete")
  • @RequestMapping("/get")

Of course there are lots of mapping in an enterprise sized application but if you can collection them in a meaningful controllers, It is going to be easy to maintain them.

Sign up to request clarification or add additional context in comments.

1 Comment

That makes sense. At the time of posting I didn't realize that RequestMappings could be done at the method level. Thanks for the explanation!
1

Let suppose your application is about shopping cart. And it performs following actions.

  1. Create/Edit/Delete Order.
  2. Add/Remove/Update Cart. and so on.

From this things you can extract two controller like @Controller @RequestMapping("/order") public class OrderController{

inside this controller you can add all methods related to order like @RequestMapping(value = "/{orderNumber}",method = RequestMethod.GET) - for order details @RequestMapping(value = "/{orderNumber}",method = RequestMethod.PUT) - for update and so on.. In short you can add all order related functions under order controller

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.