Commit aba400d3 by 吴学德

图片加载功能

parent 56afdc89
package com.winsun.controller;
import com.winsun.constant.FilePath;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
/**
* @Author xuede
* @Date 2020/3/6 16:44
* @Version 1.0
*/
@Slf4j
@RestController
public class ImgController {
//menuname = "图片路径" 只支持jpeg 和 png
@RequestMapping( value = "/images/**",produces ={MediaType.IMAGE_JPEG_VALUE,MediaType.IMAGE_PNG_VALUE} )
public byte[] getbackground(HttpServletRequest request) {
byte[] bytes=new byte[10];
request.getServletPath();
String imgurl= FilePath.BACKGROUNDIMG.getValue()+"/"+request.getServletPath();
imgurl = imgurl.replace("//", "/");
File file = new File(imgurl);
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
bytes = new byte[inputStream.available()];
} catch (IOException e) {
e.printStackTrace();
}
try {
inputStream.read(bytes, 0, inputStream.available());
} catch (IOException e) {
e.printStackTrace();
}
return bytes;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment