1.描述
Java WEB项目 部署linux环境 获取本机的 ip 端口,截取替换请求 IP 端口
2 . 方法
public static String IpAddress() {
String strResult = "";
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder
.getRequestAttributes()).getRequest();
StringBuffer strBuf = new StringBuffer();
strBuf.append(request.getScheme() + "://");// 请求 http://
strBuf.append(request.getServerName() + ":"); //IP http://192.168.0.0:
strBuf.append(request.getServerPort() + "");//端口 http://192.168.0.0:8080
strBuf.append(request.getContextPath() + "/");//文件夹名 http://192.168.0.0:8080/PHRPLAT/
strResult = strBuf.toString();
return strResult; // 返回结果 http://192.168.0.0:8080/PHEPLAT
}
public static String split(String fileName) {
// 入参 String fileName = "http://192.168.0.1:48080/lis-api/static/pdf/200/2022/03/08/25e1f0a217c4c2f38afc749f161c947f.pdf";
String newFileName="/"+fileName.substring(fileName.indexOf("/", fileName.indexOf("/", fileName.indexOf("/", 0)+1)+1)+1,fileName.length());
// 出参 /lis-api/static/pdf/200/2022/03/08/25e1f0a217c4c2f38afc749f161c947f.pdf
return newFileName;
}
3 . 注意
此方法 不能使用main方法测试