@RequestMapping(value = "/getImageByUrl")
public voidgetImageByUrl(HttpServletRequest request, HttpServletResponseresponse) throws IOException {
BufferedInputStream bis = null;
request.setCharacterEncoding("UTF-8");
String fname =request.getParameter("path");
String path = "";
if(fname!=null&&fname.startsWith("/CusZiYuan/jialujin")){
fname = fname.replaceAll("/CusZiYuan/jialujin","");
}
//
if(fname!=null&&fname.startsWith("/")){
path = Constant.resourcePath+fname;
}else{
path = Constant.resourcePath+"/"+fname;
}
System.out.println(path);
//改绝对路径
OutputStream out = response.getOutputStream();
if(path!=null&&fname!=null&&(!"".equals(fname))){
File file = new File(path);
if(file.canRead()){
response.setCharacterEncoding("UTF-8");
response.setContentLength((int)file.length());
bis = new BufferedInputStream(new FileInputStream(file));
byte[] data = new byte[1024];
int len = 0;
while((len=bis.read(data))>0){
out.write(data, 0,len);
}
bis.close();
out.close();
}else{
}
}
}
图片路径显示问题
最新推荐文章于 2022-11-25 22:12:21 发布