我正在用 intelliJ-IDEA 编写 Spring Boot 应用程序,并且在 MySQL 服务器上有包含许多表的数据库。我从数据库(Hibernate)生成了实体类。
有没有办法从实体类生成 Repository 类,然后从 Repository 类生成 RestController 类?
或者有没有办法直接从实体类或数据库生成 RestController 类?
我不想为整个数据库编写所有 RestController 类。
最佳答案
Telosys 代码生成器 ( http://www.telosys.org ) 做这种工作。
它使用数据库模式创建用于生成 Java 代码的轻量级模型。
GitHub ( https://github.com/telosys-templates-v3 ) 上有一些预定义的模板,可用于 JPA、POJO、REST Controller 、Spring MVC 等。优点是一切都是用一个工具生成的。
您可以使用命令行工具 ( http://www.telosys.org/cli.html ) 或 Eclipse 插件 ( http://marketplace.eclipse.org/content/telosys-tools )
一些关于使用 Telosys 生成代码的有趣文章:
关于hibernate - 如何生成 RestController 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49396612/