import java.io.IOException;
import java.lang.annotation.Annotation;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
public class Test {
public static void main(String[] args) throws IOException, ClassNotFoundException {
//包名
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
MetadataReaderFactory metaReader = new CachingMetadataReaderFactory();
Resource[] resources = resolver.getResources("classpath*:com/rx/weixinauto/*/*/*.class");
ClassLoader loader = ClassLoader.getSystemClassLoader();
for (Resource resource : resources) {
MetadataReader reader = metaReader.getMetadataReader(resource);
String className = reader.getClassMetadata().getClassName();
Class<?> clazz = loader.loadClass(className);
Annotation[] ans = clazz.getAnnotations();
if(ans!=null&&ans.length>0){
for(Annotation an:ans){
if(an.annotationType().getName().equals("javax.persistence.Table")){
System.out.println("<class>"+clazz.getName()+"</class>");
}
}
}
}
}
}
使用spring的类 获取包下面的@Table实体类
最新推荐文章于 2022-07-26 15:47:48 发布