一:获取一个类所在的jar包的绝对路径
String jarPath = XXXXX.class.getProtectionDomain().getCodeSource().getLocation().getFile();
try {
jarPath = java.net.URLDecoder.decode(jarPath, "UTF-8");
} catch (Exception e) {
e.printStackTrace();
}
二:javaWeb项目获取ApplicationContext对象
private static WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();
三:获取IP地址
InetAddress address = InetAddress.getLocalHost();
ipAddress = address.getHostAddress().toString();
四:在基类中获取子类传入的泛型类型
import java.lang.reflect.Type;
import java.lang.reflect.ParameterizedType;
public class BaseDao<T> {
public BaseDao(){
Type type=getClass().getGenericSuperclass();
Type[]param=((ParameterizedType)type).getActualTypeArguments();
Class entiyClass=(Class) param[0];
}
}
五: