代码对应的工程路径图: 1、获取当前项目工程下静态资源图片路径,以下两种方法皆可: /** * 方法一 */ String path = this.getClass().getResource("/static/img/logo.png").getPath(); System.err.println("path:" + path); // path:C:/Users/Administrator/Desktop/wechat-project/demo/target/classes/static/img/logo.png /** * 方法二 */ String path2 = this.getClass().getClassLoader().getResource("static/img/logo.png").getPath(); System.err.println("path2:" + path2); // path2:/C:/Users/Administrator/Desktop/wechat-project/demo/target/classes/static/img/