场景:在spring web项目中获取WEB-INF/classes目录与WEB-INF/目录
1.获取WEB-INF/classes 目录
/**1.获取WEB-INF/classes 目录 **/
public static String getWebRootPath() {
String webRootPath = CommonConfigUtils.class.getResource("/").getPath();
return webRootPath;
}
2.获取WEB-INF/
/**2.获取WEB-INF/ 目录*/
public static String getWebInfPath() {
String webRootPath = CommonConfigUtils.class.getResource("/").getPath();
String webInfPath = webRootPath.substring(0,webRootPath.indexOf("classes"));
return webInfPath;
}
以上,TKS.
本文介绍了在SpringWeb项目中如何获取WEB-INF/classes目录及WEB-INF/目录的路径。通过CommonConfigUtils类的方法,详细展示了获取这些路径的具体实现,便于开发者在项目中进行资源定位。
2823

被折叠的 条评论
为什么被折叠?



