I keep seeing this kind of param value = "/redirect/{id}"
in a @RequestMapping
annotation of the Spring. I keep wondering what is {id}
here? Is this some sort of Expression Language
?
Sample code of what I have seen:
@RequestMapping( value = "/files/{id}", method = RequestMethod.GET )
public void getFile( @PathVariable( "id" )
String fileName, HttpServletResponse response )
{
try
{
// get your file as InputStream
InputStream is = new FileInputStream("/pathToFile/"+ fileName);
// copy it to response's OutputStream
IOUtils.copy( is, response.getOutputStream() );
response.flushBuffer();
}
catch( IOException ex )
{
throw new RuntimeException( "IOError writing file to output stream" );
}
}
My question is what is the {id}
in the mapping and what is its relationship with the @PathVariable
annotation and how to use it? I red some info from the web but I will much more appreciate it to hear much more clearer explanation from you guys.