利用反射原理中的getSimpleName()方法和字符串操作获取
package demo;
import com.yy.erp.auth.emp.vo.EmpModel;
public class Test1 {
@SuppressWarnings("rawtypes")
public Test1(Class clazz) throws Exception {
dataInit(clazz);
}
@SuppressWarnings("rawtypes")
private void dataInit(Class clazz) {
String className = clazz.getSimpleName();// 获取类名
String big = className.substring(0, 1);// 获取首字母(类名首字母大写)
String small = big.toLowerCase();// 将首字母变为小写
String smallName = small + className.substring(1);// 获得已小写字母开头的类名
System.out.println(className);
System.out.println(smallName);
}
public static void main(String[] args) throws Exception {
new Test1(EmpModel.class);
}
}