能@Component,@Repository并@Service注释互换在Spring中,还是他们提供任何特殊的功能,除了作为一个符号设备?
换句话说,如果我有一个Service类并且我将注释更改@Service为@Component,它仍然会以相同的方式运行吗?
或者注释是否也会影响类的行为和功能?
我在春天value = "/redirect/{id}"的@RequestMapping注释中一直看到这种格拉姆.我一直想知道{id}这里有什么?这是某种Expression Language吗?
我看到的示例代码:
@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" );
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是{id}映射中的内容是什么,它与@PathVariable …