0

I am trying to make spring boot application & swagger. Application is for REST service provide. I have made application running each page. I have made a simple controller that have RequestMapping("/group/user/contact").

Which is working fine.

I am trying to do something like RequestMapping("/group/{type}/contact") at class level.

So my question is that is it possible ? If yes then just want some basic guidance. and if no then fine.

My all request working fine. All request came from CORS filter class.

1 Answer 1

1

You can do this, the handler method should look something like

@Controller
@RequestMapping("/group/{type}/contact")
public class ClassLevelPathVariableController {

    @ResponseBody
    @RequestMapping(method = RequestMethod.GET)
    public String classLevelMapping(@PathVariable String type) {
        return type;
    }

}

In this setup a GET request like e.g. /group/test/contact would be handled by the classLevelMapping method and the type variable will be populated with the value "test"

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

4 Comments

thank you for the answer but sorry still i don't understand what you want to say. will u elaborate it.
add a complete class example, should be more understandable now
and I want to trace each request before request came to here. based on it i am going to set the base database. suppose type is teacher then teacher database will be selected.
well that's a completely different question, and a much broader topic, so I advise you to post it as a separate question. Still, to provide some hints, you should implement spring mvc interceptor for tracking and for dynamic DB switchining you can lean on spring's AbstractRoutingDataSource howtodoinjava.com/2013/12/28/…

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.