5

How to pass String value in Spring-Boot @RequestMapping("/test").

I want to pass String str ="/test" as String value in RequestMapping(str), please suggest how to read String value in Request Mapping.

1
  • 1
    could you validate the response? could be useful for other members, Thanks! Commented Nov 4, 2016 at 11:13

2 Answers 2

14

This should work @RequestMapping("${test.str.value}") and in your application.proprties/yml test.str.value = /test

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

Comments

4

You can use mainly 2 opions:

Option 1:

@RequestMapping("/{pathVariable}/yourUrl")
public void yourRequestMethod(@PathVariable("pathVariable")String pathVariable){...}

And you should build the request like this:

/yourValue/yourUrl

Option 2:

@RequestMapping("/yourUrl")
public void yourRequestMethod(@RequestParam("test")String test){...}

And you should build the request like this:

/yourUrl?test=yourValue

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.