Java 如何使用 Spring Boot 和 IntelliJ Idea 从数据库生成实体类?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36995670/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 18:53:44 来源:igfitidea点击:
How can I generate entities classes from database using Spring Boot and IntelliJ Idea?
提问by Lucas León
I trying to make a project using the Spring Initializr wizard and I already have a database, so I want to generate entities classes using Spring Boot and IntelliJ Idea.
我尝试使用 Spring Initializr 向导创建一个项目,并且我已经有了一个数据库,所以我想使用 Spring Boot 和 IntelliJ Idea 生成实体类。
采纳答案by rapasoft
Prerequisites are:
先决条件是:
- You have your Spring Boot project initialized correctly in IDEA
- JPA persistence.xml file or similar has been generated correctly
- 您已在 IDEA 中正确初始化了 Spring Boot 项目
- 已正确生成 JPA persistence.xml 文件或类似文件
Then you have to do these things:
然后你必须做这些事情:
- Create a DataSource- here you will add a simple DataSource that will connect to your database. The setup should be intuitive - you only provide connection details and add DB drivers (IDEA can download them for you)
- Add JPA/Hibernate facet. You can do it like thisor this.
- Now you should be able to generate entities using IDEA. What you want to do here is choose
Generate by Database Schema
. The dialog will let you select the tables you want to use, the rest should be up to you.
- 创建一个数据源- 在这里您将添加一个将连接到您的数据库的简单数据源。设置应该是直观的 - 您只需提供连接详细信息并添加数据库驱动程序(IDEA 可以为您下载)
- 添加 JPA/Hibernate 方面。你可以像这样或这样。
- 现在您应该能够使用 IDEA 生成实体。您在这里要做的是选择
Generate by Database Schema
。该对话框将让您选择要使用的表,其余的由您决定。