java - Spring Java 包中的实体列表

标签 java spring-mvc spring-boot spring-data-jpa thymeleaf

我正在寻找一种方法来获取项目包之一中的实体列表(仅字符串值)。不是全部,只是指定的包。

有什么办法可以做到这一点吗?它们也在 mysql 数据库中,但没有在那里排序。

最佳答案

您可以为此使用反射:

Reflections ref = new Reflections("com.your.package");
Set<String> entities = 
ref.getTypesAnnotatedWith(javax.persistence.Entity.class).stream().map(Class::getName).collect(Collectors.toSet());

关于java - Spring Java 包中的实体列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52578159/

相关文章:

Java AI - boolean 数组的最佳传递

java - 错误: cannot find symbol of Parser

mysql - Spring Boot、Spring Security、MySQL - CustomUserDetailsS​​ervice 始终导致错误 "Invalid Username or Password"

spring - 无法导入Spring RepositoryRestResource

Spring启动非 fatal error ClassNotFoundException

java - DatePicker:如何自定义

java - 总是同一个线程获得 CPU 时间

mysql - Spring Petclinic (Spring Boot) 中的数据库连接问题

rest - Spring Boot 微服务 REST API 安全

java - 如何在运行时编辑 application.properties(供下次使用)