需求介紹
這個方法主要是服務於有對字節碼操作的需求的人。
代碼演示
@Test
public void test_path(){
// 獲取當前類所在的
String classPath = V2Test.class.getResource("/").getPath();
System.out.println(classPath);
// 將路徑中的.替換成/
String mapperPath = "com.edu.mqs.mebatis.v2_test".replace(".", File.separator);
System.out.println(mapperPath);
// 拼接成.class文件所在的路徑
String path = StringUtils.join(classPath, mapperPath);
System.out.println(path);
// BigDecimal.ZERO 替換 new BigDecimal(0)方法
System.out.println(BigDecimal.ZERO);
}
運行結果
/Users/fenke/newMineWorkspace/mebatis/target/test-classes/
com/edu/mqs/mebatis/v2_test
/Users/fenke/newMineWorkspace/mebatis/target/test-classes/com/edu/mqs/mebatis/v2_test
驗證結果