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

      

  • 相关阅读:
    PHP常量
    jquery中的几种常用总结
    jquery中的ajax
    常用的jquery一些总结
    js验证手机号邮箱号用户名
    PHP优化杂烩
    一个php开发的用于路由器的小功能
    HTML <form>
    window.open
    try&catch
  • 原文地址:https://www.cnblogs.com/swtjavaspace/p/9837790.html
Copyright © 2011-2022 走看看