1. Install
First click on File-> Settings-> Plugins, then search EasyCode, as follows:
After successful installation, reboot the IDEA.
2. Create a project
Then I will give you a demonstration of how to use EasyCode in Spring Boot in. First we create a SpringBoot project in IDEA, create a process I do not say, if you do not, I can reply in public springboot number backstage, a detailed tutorial.
3. Add a data source
Since this project is based on IDEA Database Tools developed, so we must first Database data source connection via the IDEA.
Next, configure your database connection information, if not detected the appropriate database Driver, clicking on the left automatically downloaded:
After a successful connection, click OK. By default, the database does not show in the connection, we need to manually check, for example, I have here want to connect vhr database, as follows:
4. The generated code
Done in front of three steps, ready to work even if OK, the next step is to generate the code. For example, I want to generate entity classes vhr All code, DAO layer, and service layer, as follows:
First of all tables are selected, then right-click and select Easy Code-> Generate Code, as follows:
When first added, if there is no corresponding Java type of database type, there will be prompt, this based on its guide to add a mapping relationship can be, for example, when I add, that out of a prompt:
Click Yes, and then to add your own type mappings:
After successfully added, then do code generation, which under it:
Here, if the project is a multi-module project, you can choose Module code generation, code generation and then set the package, the last check code template to be generated from below, you can click OK.
❝
In the process of code generation, if not detected package following a service, dao and entity and other packages, the tool will automatically create a prompt, you can click Yes.
❞
Finally generated code is as follows:
At this point, the layers of code basically generated. Most small partners might use this step on OK.
Of course, if you feel EasyCode automatically generated templates enough, or difficult to use, we can also customize the template.
5. Custom Template
For example, I think in the generated code dao layer, does not require any additional add a condition, all the data acquisition method (the default template does not generate this method).
点击 File->Settings->Easy Code->Template Setting:
Reference can define your own way, we are now in the first dao.java, add the following method:
It was then added to give a method of supporting mapper.xml, open mapper.xml, add the following method:
After configuration is complete, click OK.
Then go to regenerate the code, you can see the method generated more than one way, the definition of other code similar to this template, I will not go into details.