IDEA code generation plugin CodeMaker

foreword

In the process of Java development, it is often encountered to write repetitive code by hand. For example, when writing domain classes and persistent classes, most of the time their variable names and types are the same. When writing domain classes, it is often necessary to repeatedly write similar code. Therefore, a code generation plug-in for IDEA was developed, which supports custom code templates to generate code through Velocity.

Project address : CodeMaker

The main function

  1. Support for adding custom code templates (Velocity)
  2. Support for selecting multiple classes as context for code templates

Install

Download the plugin: CodeMaker.zip

  1. Open Settings and select "Plugin"
  2. Click "Install plugin from disk" in the box on the right
  3. Select "CodeMaker.zip" downloaded above
  4. Click "Apply", then restart IDEA.

use

Right-click "Generate" in the Java class editing interface, and select the corresponding template to automatically generate the code to the package of the current class, then modify it, and move it to the appropriate location.

If the code template requires a class other than the current class as context, it can be selected through the class selection box.

There are currently two templates:

  1. Model : Generate a class with similar properties based on the current class to automatically generate the domain class corresponding to the persistent class
  2. Converter : This template requires two classes as an input context, which is used to automatically generate the conversion class of the domain class and the persistent class.

The above two templates are commonly used templates in my own work. You can refer to their writing methods and define new code templates by yourself.

Template configuration

  1. Add template : After clicking "Add Template", fill in the relevant configuration (neither can be empty), click Save and restart IDEA to take effect.
  2. Delete template : Click "Delete Template" to delete the template, which also needs to be restarted to take effect.
  1. Template Name : The name displayed in the generation menu, named in English
  2. Class Number:该模板需要的输入上下文类的数量,例如:如果为 1,,将当前的类作为输入:$class0;如果为 2,需要用户再选择一个类作为输入:$class0, $class1
  3. Class Name:生成的类的名称,支持通过 Velocity 进行配置,上下文为跟代码模板的相同。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326125731&siteId=291194637