图片路径转发

This commit is contained in:
wuweida 2022-05-19 18:17:00 +08:00
parent 7d7ccce242
commit a863c372fc
2 changed files with 55 additions and 0 deletions

View File

@ -17,6 +17,7 @@ import org.springframework.web.bind.annotation.RestController;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
@ -143,6 +144,7 @@ public class EventController {
@GetMapping("selectEvent")
@ApiOperation("查询所有事件")
public Result selectEvent(){
List<Event> events = eventMapper.selectEvent();
Result success = Result.success(events);

View File

@ -0,0 +1,53 @@
package com.hisense.monitormanage.controller;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
@Controller
public class FordController {
@GetMapping("components/**")
@ApiOperation("查询所有事件")
public void ford(HttpServletRequest request, HttpServletResponse response)throws Exception{
String imageDomain = "http://10.132.191.48:30080";
String uri = request.getRequestURI();
String fordUrl = imageDomain + uri;
URLConnection con = null;
try {
URL url = new URL(fordUrl);
con = url.openConnection();
//允许写出
con.setDoOutput(true);
//允许读入
con.setDoInput(true);
//不使用缓存
con.setUseCaches(false);
//得到响应流
InputStream inputStream = con.getInputStream();
ServletOutputStream outputStream = response.getOutputStream();
byte[] buffer = new byte[1024];
int len = inputStream.read(buffer);
while (len != -1) {
outputStream.write(buffer, 0, len);
len = inputStream.read(buffer);
}
}catch(Exception e) {
e.printStackTrace();
}
}
}