我是 Spring 新手,如何从特定路径显示 PDF 文件?PDF 文件在本地可用,我想在object
HTML 的标签中显示它。我看过一些我真的不明白的教程。
代码是这样的。我不太确定这是否真的是我正在寻找的东西。
@RequestMapping( value = "/files/{file_name}", method = RequestMethod.GET )
public void getFile( @PathVariable( "file_name" )
String fileName, HttpServletResponse response )
{
try
{
// get your file as InputStream
InputStream is = ...
// copy it to response's OutputStream
IOUtils.copy( is, response.getOutputStream() );
response.flushBuffer();
}
catch( IOException ex )
{
log.info( "Error writing file to output stream. Filename was '" + fileName + "'" );
throw new RuntimeException( "IOError writing file to output stream" );
}
}
请求映射的值对我来说似乎很像EL
。我不太确定。我InputStream
应该放在那里。对不起一个菜鸟问题