Controller层
@GetMapping(value = "/query/map")
@ApiOperation("根据经纬度查询是否存在格点")
public void queryMap(@RequestParam("service") String service,
@RequestParam("version") String version,
@RequestParam("request") String request,
@RequestParam("format") String format,
@RequestParam("transparent") String transparent,
@RequestParam("layers") String layers,
@RequestParam("srs") String srs,
@RequestParam("styles") String styles,
@RequestParam("width") String width,
@RequestParam("height") String height,
@RequestParam("bbox") String bbox,HttpServletResponse response
)
throws IOException {
String url="SERVICE"+"="+service+"&"+
"VERSION"+"="+version+"&"+
"REQUEST"+"="+request+"&"+
"FORMAT"+"="+format+"&"+
"TRANSPARENT"+"="+transparent+"&"+
"LAYERS"+"="+layers+"&"+
"SRS"+"="+srs+"&"+
"STYLES"+"="+styles+"&"+
"WIDTH"+"="+width+"&"+
"HEIGHT"+"="+height+"&"+
"BBOX"+"="+bbox;
contentService.queryMap(url,response);
controller层改用map类型接收参数
public void queryMap(@RequestParam Map<String,String> paramsMap, HttpServletResponse response
) throws IOException {
StringBuilder url = new StringBuilder();
for (Map.Entry<String, String> m : paramsMap.entrySet()) {
url.append(m.getKey()).append("=").append(m.getValue()).append("&");
}
contentService.queryMap(url.toString(),response);
}
Service
@Override
public void queryMap(String url,HttpServletResponse response) throws IOException {
System.out.println(url);
GetUtil.sendGut("被调用方根目录?"+url,response);
}
Util
public class GetUtil {
public static void sendGut(String url, HttpServletResponse response) throws IOException {
InputStream is = null;
URL urls = new URL(url);
//打开和url之间的连接
HttpURLConnection conn = (HttpURLConnection) urls.openConnection();
//请求方式
conn.setRequestMethod("GET");
//获取URLConnection对象对应的输出流
conn.connect();
//获取URLConnection对象对应的输入流
is = conn.getInputStream();
OutputStream out = null;
try {
out = response.getOutputStream();
int len = 0;
byte[] b = new byte[1024];
while ((len = is.read(b)) != -1) {
out.write(b, 0, len);
}
out.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (out != null) {
out.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}