In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to achieve code one-click generation in IntelliJ IDEA". In daily operation, I believe that many people have doubts about how to achieve code one-click generation in IntelliJ IDEA. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how to achieve code one-click generation in IntelliJ IDEA". Next, please follow the editor to study!
1. Installation
First click File- > Settings- > Plugins, and then search for EasyCode, as follows:
After the installation is successful, restart IDEA.
two。 Create a project
Next I'll show you how to use EasyCode in Spring Boot. First of all, let's create a SpringBoot project in IDEA. I won't say much about the creation process. If you don't know it, you can reply to springboot in my official account. There are detailed tutorials.
3. Add data source
Since this project is based on Database Tools on IDEA, we first need to connect to the data source through Database on IDEA.
Next, configure your database connection information. If no appropriate database Driver is detected, click the lower left corner to download it automatically:
When the connection is successful, click OK. The database under the connection is not displayed by default, so we need to check it manually. For example, I want to connect to the vhr database here, as follows:
4. Generate code
After the first three steps, the preparatory work is called OK, and the next step is to generate the code. For example, I want to generate entity classes, dao layers, and service layers for all the code in vhr as follows:
First select all the tables, then right-click and select Easy Code- > Generate Code, as follows:
When you add a database type for the first time, you will be prompted if there is no corresponding Java type. You can add the mapping relationship according to its guidance. For example, when I add it, I give this prompt:
Click Yes, and then add your own type mapping:
After the addition is successful, then do the code generation, which is fine:
Here, if the project is a multi-module project, you can first select the Module generated by the code, then set the package generated by the code, and finally check the code template to be generated below, and click OK.
❝
In the process of code generation, if you do not detect service, dao, entity and other packages under package, the tool will prompt for automatic creation, and click Yes.
❞
The resulting code is as follows:
At this point, the code for each layer is basically generated. Most of my friends may be OK when they use this step.
Of course, if you think the template automatically generated by EasyCode is not enough or not easy to use, we can also customize the template.
5. Custom template
For example, I want to add an additional method to the generated dao layer code that gets all the data without any conditions (this method is not available in the default generation template).
Click File- > Settings- > Easy Code- > Template Setting:
You can refer to the definition method of the tool itself. Let's add the following methods in dao.java:
/ * *
* query all data
*
* @ param $! tool.firstLowerCase ($! {tableInfo.name}) instance object
* @ return object list
, /
List getAll ()
Then add a matching method in mapper.xml, open mapper.xml, and add the following method:
Select
# allSqlColumn ()
From $! {tableInfo.obj.parent.name}. $! tableInfo.obj.name
When the configuration is complete, click OK.
At this point, the study on "how to achieve one-click code generation in IntelliJ IDEA" is over. I hope to be able to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.