0

I am new to java and am still trying to wrap around my mind around many of its concepts.

Right now in my application that pulls in data from an external api. I am trying to hardcode a path, for now, to make sure that I am getting the response I am expecting (this is a temporary interaction as eventually, I want the app to be stateless. If I pass a hardcoded value for @PathVariable in my controller with the variable defined above the code doesn't read the value.

Where should I be placing the hard-coded value and am I defining it the correct way?

Code:

String identificationCode ="abcd";
@RequestMapping(value ="/download/{identificationCode}", method = RequestMethod.GET)
String downloadDocument(@PathVariable(value="identificationCode") String identificationCode) {
     .
     .
     .
}
1
  • Dont you mix up server and client here? Commented Jul 27, 2018 at 10:11

3 Answers 3

0

value is a alias for name. That means that @PathVariable(value="identificationCode") specifies name of variable for this parameter, but not value. See

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

Comments

0

Here "/download/{identificationCode}"

identificationCode is not interpolated by the value of the String declared there :

String identificationCode ="abcd";

It will just produce the String : "/download/{identificationCode}".

You could write it :

@RequestMapping(value ="/download/"+identificationCode, method = RequestMethod.GET)

but it will not work either as identificationCode is not a constant expression.

So what you want is just :

@RequestMapping(value ="/download/abc", method = RequestMethod.GET)

Use this way if you don't need to reference the String somewhere else.

Otherwise as alternative declare identificationCode as a constant expression (and you can also do this static by the way) :

final static String identificationCode ="abcd";

And you could so use it :

@RequestMapping(value ="/download/"+identificationCode, method = RequestMethod.GET)

Comments

0

Replace {identificationCode} with your hard code value in @RequestMapping(value ="/download/{identificationCode}". Later, when you want the dynamic nature of path, you can go as you have currently coded.

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.