话不多说,直接说重点。
request.getRequestURL();
request.getRequestURI();
request.getContextPath();
request.getServletPath();
对应的路径分别是:
http://localhost:8081/yangquan/ManagerSystem/SystemManager/UserManager/User/uploadPhoto/d8e2669b-69ca-4490-80f4-f68e51529357
/yangquan/ManagerSystem/SystemManager/UserManager/User/uploadPhoto/d8e2669b-69ca-4490-80f4-f68e51529357
/yangquan
/ManagerSystem/SystemManager/UserManager/User/uploadPhoto/d8e2669b-69ca-4490-80f4-f68e51529357
注意我的.yml是这么配置的
server:
port: 8081
servlet:
context-path: /yangquan
由此可见
request.getRequestURL(); //获取全路径 获取的是请求路径中的ip和端口号
request.getRequestURI(); //获取端口号之后的路径
request.getContextPath(); //获取.yml配置中的获取上下文路径(context-path)的名称
request.getServletPath(); //获取.yml配置中context-path之后的路径
在说明一点
public static String getUploadPath() {
return System.getProperty("user.dir").replaceAll("\\\\", "/") +
"/src/main/webapp/static/upload/";
}
//得到结果
//C:/Users/yangquan/Desktop/ceshi/src/main/webapp/static/upload/
//项目所在的文件夹 在拼接 /src/main/webapp/static/upload/ 路径
这辈子坚持与不坚持都不可怕,怕的是独自走在坚持的道路上!!! | |
---|---|
欢迎加入技术群聊