• 常用辅助类


    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);
    	}
    }
    

      

  • 相关阅读:
    ajax请求
    easyui相关问题
    linux解压命令
    angular2 中文学习资料整理
    在angular2服务中注入服务
    Angular 2模板语法
    登录,注册流程(基于token的身份验证)
    Node Js与JavaScript的区别及nodejs优缺点。
    yarn包管理网站
    浅谈Cookie,Session,WebStorage区别,应用场景
  • 原文地址:https://www.cnblogs.com/swtjavaspace/p/9837790.html
Copyright © 2020-2023  润新知