Skip to content

Latest commit

 

History

History
93 lines (57 loc) · 5.79 KB

README_EN.md

File metadata and controls

93 lines (57 loc) · 5.79 KB

BeanMappingKey

GitHub Stars GitHub Forks GitHub Watchers

简体中文 | English

One-click generation of field mapping code between two entity classes, which is used to replace tools such as BeanUtil and MapStruct.


Installation Guide

  • Using IDE built-in plugin system on Windows:
    • File > Settings > Plugins > Browse repositories... > Search for "BeanMappingKey" > Install Plugin
  • Using IDE built-in plugin system on MacOs:
    • Preferences > Settings > Plugins > Browse repositories... > Search for "BeanMappingKey" > Install Plugin
  • Manually:
    • Download the latest release and install it manually using Preferences > Plugins > Install plugin from disk...

PS: For the time being, only versions above 2020 are supported, no need to restart ide after installation.


Start Guide

In the process of Java development, many packaging objects such as BO, VO, DTO are often used, and there are often only two or three field differences between them.

Converting them to each other is a time-consuming and labor-intensive physical activity, so tools such as BeanUtil and MapStruct are derived from the Java ecosystem.

However, BeanUtil cannot view the details of object conversion, and MapStruct sometimes encounters unsatisfactory object conversion, so you still need to manually write object conversion code.

BeanMappingKey was developed to solve this type of demand. It (temporarily) has three usages:

  • Select a method with return value and parameters, use the shortcut key Ctrl+M or right click on BeanMappingKey, The relevant conversion code can be inserted automatically.

  • Select a variable and use the shortcut key Ctrl+M or right-click on BeanMappingKey to automatically generate the conversion code to the pasteboard.

  • Select a class and use the shortcut key Ctrl+M or right-click on BeanMappingKey to automatically generate the conversion code to the pasteboard.

In the above generation logic, if there is a Builder internal class, the Builder code will be generated first, and then the Set type code will be generated.

Tip: In the latest 2.X version, it can even generate nested objects, such as a User object contains an Address object, Then it will generate both objects and assign them automatically.

Code Generation Guide

Carefully read the code generation guide to help you understand the logic of the code generated by this plugin. If you encounter problems in use, you can better judge whether it is a plugin problem or a usage problem.

Q1: How to judge whether a class will generate Builder code or Set code?

A: If there is an inner class ending with Builder in this class, Builder code will be generated, if not, Set type code will be generated, Set type code is determined by looking for methods in the class that start with SetXXX.

If the generated class is a nested object, please make sure that the parent object and the child object are both Builder code or Set type code, because only the parent object will be judged when judging, If the parent object is a Builder code and the child object is a Set type code, some error codes will appear when generating the child object code. If this situation cannot be avoided, you can delete the generated error code, and then click the child object class to separate generate.

Q2: When generating code from method parameters and return values, what logic is used for matching?

A: First, I will get all the method parameters, take out their variable names in turn, and then match the variable names of the return value, so the matching is done by variable names.

Q3: The plugin does not respond during use, what is the problem?

A: At this time, you can pay attention to the bubble prompt in the lower right corner of IDEA. If the prompt is green, it means that you have successfully generated. If it is red and you can see the prompt at the beginning of BeanMapping, it means that the selected object does not support generation. If you see a red bubble but there is no prompt at the beginning of BeanMapping but an occurred error, it means that there is a problem with my plugin, you can send me Issues.

Tip: When the code is not compiled or IDEA is not ready, it is also possible to get an error when using the plugin, because the plugin depends on the context inside IDEA.

Q4: Does the plugin support other languages besides Java?

A: As of version 2.0, this plugin only supports Java.


Issues Guide

If you encounter any problems or have good usage suggestions during use, you can tell me by submitting issues, Before submitting issues, please organize your language and be as detailed as possible. If it is an issue of issues, you need to attach the IDEA version.

Finally, welcome Star.