zoukankan      html  css  js  c++  java
  • 常用辅助类

    public class ClassHelper {
    
    	/**
    	 * 获取当前正在执行的方法名
    	 * 
    	 * @return
    	 */
    	public static String getCurrentThreadMethodName() {
    		StackTraceElement[] stack = Thread.currentThread().getStackTrace();
    		StackTraceElement stackTraceElement = stack[2];
    		String className = stackTraceElement.getClassName();
    		String methodName = stackTraceElement.getMethodName();
    		String s = className + "." + methodName;
    		return s;
    	}
    
    	/**
    	 * 获取类路径
    	 * 
    	 * @return
    	 */
    	public static String getClassPath() {
    		String path = Thread.currentThread().getContextClassLoader().getResource("").getPath();
    		return path.replace("\", "/");
    	}
    
    	/**
    	 * 获取当前应用的根目录,不含最后的斜线
    	 * 
    	 * @return
    	 */
    	public static String getBasePath() {
    		String classPath = getClassPath();
    		int webInfoIndex = classPath.indexOf("/WEB-INF");
    		if (webInfoIndex > -1) {
    			return classPath.substring(0, webInfoIndex);
    		} else {
    			return classPath.substring(0, classPath.indexOf("/target/classes"));
    		}
    	}
    
    	/**
    	 * 获取当前应用的名字
    	 * 
    	 * @return
    	 */
    	public static String getAppName() {
    		String basePath = getBasePath();
    		int index = basePath.lastIndexOf("/") + 1;
    		return getBasePath().substring(index);
    	}
    }
    

      

  • 相关阅读:
    [离散数学]集合3.1、3.2、3.3
    Hadoop YARN ResourceManager 未授权访问漏洞复现
    dns域传送漏洞
    文件包含漏洞详解
    XXE漏洞详解
    常见cms
    IP地址详解
    帧详解
    IP包头内容详解
    SSRF漏洞详解
  • 原文地址:https://www.cnblogs.com/swtjavaspace/p/9837790.html
Copyright © 2011-2022 走看看