开发者

spring mvc request mapping conventions

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 isn开发者_如何学编程t 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


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.


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() {

    }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜