In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you an introduction and usage of lombok, a tool necessary to improve development efficiency in springboot. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.
The benefits of using the lombok plug-in
We often have some routine and repetitive work in the java development process. For example:
Generate get and set methods based on member variables
Generate the constructor of a class based on member variables
Override the toString () and hashCode methods
The log framework logFactory is introduced to print logs.
The above are some repetitive actions, template code. Manual generation each time is a waste of time and adds a lot of redundant code. We can use the lombok plug-in to solve this problem. Our coding efficiency has been greatly improved!
How to install the lombok plug-in
The author takes InelliJ IDEA as an example to install the lombok plug-in. Open the File- > Settings panel of IDEA, select the Plugins option, and then click "Browse repositories". Type "lombok" in the search box, find lombok in the results, click install, and then restart IDEA.
We will also add the following dependencies to the pom.xml, and the plug-ins will take effect.
Org.projectlombok lombok true
There is no need to add a version number to the Spring Boot project, the spring Boot parent project will be managed on its behalf. If it is another project, please add your own version number!
Using lombok annotations to simplify the development of 4.1 Data annotations
Using the @ Data annotation on the java class will automatically generate for us at compile time
Get and set methods of member variables
Equals method
CanEqual method
HashCode method
ToString method
The left side of the image above is annotated with Data using lombok, and on the right is the decompilation result of the java bytecode class file.
4.2 Slf4j comments
The Logger log constant will be introduced automatically at compile time, and we can print the log directly using log.info or log.debug in our code. The red code in the following figure can be replaced with Slf4j annotations.
4.3 Builder comments
After using Builder annotations on the Java class, we can assign values to object properties using the following code
LombokPOJO lombokPOJO = LombokPOJO.builder () .name ("kobe") .age (39) .build ()
4.4 AllArgsConstructor comments
The AllArgsConstructor annotation will be automatically generated for us at compile time: the all-parameter constructor. If there are all-parameter constructor annotations, naturally there will be nonparametric constructor annotations: NoArgsConstructor comments.
Lombok has a lot of useful notes, so here are a few of them that are often used. For more usage, refer to github (plug-in installation diagram, with github connection, yellow area above)
The above is the introduction and usage of lombok, a tool necessary to improve development efficiency in springboot, which is shared by Xiaobi. if you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
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.