Java文件里
File f1 = new File ( this . getClass ( ) . getResource ( "/" ) . getPath ( ) ) ;
File f2 = new File ( this . getClass ( ) . getResource ( "" ) . getPath ( ) ) ;
String f3 = request. getRealPath ( "/" ) ;
D : \tomcat\apache- tomcat- 6.0 .39 \webapps\scm37\WEB- INF\classes
D : \tomcat\apache- tomcat- 6.0 .39 \webapps\scm37\WEB- INF\classes\cn\it\action
D : \tomcat\apache- tomcat- 6.0 .39 \webapps\scm37\
String str1 = this . getClass ( ) . getResource ( "/" ) . getPath ( ) ;
String str2 = this . getClass ( ) . getResource ( "" ) . getPath ( ) ;
String str3 = this . getClass ( ) . getClassLoader ( ) . getResource ( "" ) . getFile ( ) ;
/ D : / idea/ project/ practice/ read- spring/ target/ test- classes/
/ D : / idea/ project/ practice/ read- spring/ target/ test- classes/
/ D : / idea/ project/ practice/ read- spring/ target/ test- classes/
获取当前项目路径
File file = new File ( "" ) ;
try {
String filePath = file. getCanonicalPath ( ) ;
System . out. println ( filePath) ;
} catch ( IOException e) {
e. printStackTrace ( ) ;
}
读取springboot项目resources文件夹下的mapper文件下的所有mapper. xml文件
private void loadMappersInfo ( ) {
URL mapper = this . getClass. getClassLoader ( ) . getResource ( "mapper" ) ;
File fileDirectory = new File ( mapper. getFile ( ) ) ;
if ( fileDirectory. isDirectory ( ) ) {
File [ ] mapperFiles = fileDirectory. listFiles ( ) ;
for ( File file : mapperFiles) {
}
}
}
Jsp文件里
< Img src= "<%=request.getContextPath()%>/image/421.png" / >