5

I am trying to come with a good convention to do request mappings in my application

right now i have

RegistrationController {
   @RequestMapping(value="/registerMerchant")
   ...
   @RequestMapping(value="/registerUser")
   ...
}

but this isnt ideal since by looking at the url you might not know to look in RegistrationController for the code.

Is there a way i can programmitically prepend the controller name of those mappings making them:

/registration/registerMerchant
/registration/registerUser

2 Answers 2

8

Not programmatically, but this sort of pattern I've seen working:

@Controller
@RequestMapping(value="/registration/**")
RegistrationController {
   @RequestMapping(value="**/registerMerchant")
   ...
   @RequestMapping(value="**/registerUser")
   ...
}

Having said that, in the past I've found this inordinately hard to get working in the way I'd expect. It can be made to work, though.

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

3 Comments

you found the above pattern hard to use? why? also, i am not married to this convention yet, can you recommend some other sane way to do request mappings?
@mkoryak: It's easy to understand, but Spring MVC isn't great at letting you diagnose it when you get it even slightly wrong. it's the best pattern I've come across, though.
I agree that this can be a little painful. The key here is, after using a class-level @RequestMapping, making sure that your method level annotations do not begin with /.
6

I think **/ at the method level is too much noise. On a different note, the URI could be made more REST like with more nouns and less verbs.

@Controller
@RequestMapping("/services")
public class RegistrationController {

    @RequestMapping(value = "/merchant/register")
    public void processMerchantRegistration() {

    }

    @RequestMapping(value = "/user/register")
    public void processUserRegistration() {

    }

}

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.