0

I would like to set for each user's own profile link.
Like this:

   @RequestMapping(value = "/{userlogin}", method = RequestMethod.GET)
    public String page(@PathVariable("userlogin") String userlogin, ModelMap model) {
        System.out.println(userlogin);
        return "user";
    }

But static pages get this expression too..
Like this:

@RequestMapping(value = "/hello", method = RequestMethod.GET)
public String hello() {
    System.out.println("hello mapping");
    return "hello";
}

That is when I request GET request "hello" that calls both controllers.
I would like to do that, user controller calls only if other methods not called.

Console, when I calls localhost:8080/123:

123

Console, when I calls localhost:8080/hello:

hello 
hello mapping

or

hello mapping
hello 

I want to get only

hello mapping

when calls localhost:8080/hello

Who knows how it can be implemented?

3
  • Just call one method with path variable with it i.e. requestMapping(value="/hello/{userLogin}") Commented Oct 27, 2014 at 18:17
  • Thank you for response. But it not what i want.. I changed the post to a more intuitive Commented Oct 27, 2014 at 18:42
  • I advise to look in the direction of filters, which will redirect to other path for localhost:8080/hello and how result to other controller. For example, you may look this link: stackoverflow.com/questions/3125296/… Commented Oct 27, 2014 at 19:14

1 Answer 1

1

Spring MVC can use URI Template Patterns with Regular Expressions. Provided :

  • userlogin only contain digits
  • others URL immediately under root contains at least one non digit character

you can use that in your @RequestMapping :

@RequestMapping(value = "/{userlogin:\\d+}", method = RequestMethod.GET)
public String page(@PathVariable("userlogin") String userlogin, ModelMap model) {
    //...
}

If the separation between userlogin and other URL is different from what I imagined, it can be easy to adapt.

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

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.