Tag Archives: Lombok

Halo blog system reports log error when idea is running

The solution of importing idea: cannot resolve symbol ‘log’ when running someone else’s project (halo blog system)

When importing other people’s projects, the log will report an error and prompt cannot resolve symbol ‘log’. After online query, you can install the Lombok plug-in. Here’s what the Lombok plug-in does.

The official introduction is as follows:

Project Lombok makes java a spicier language by adding 'handlers' that know how to build and compile simple, boilerplate-free, not-quite-java code.

Lombok can make Java concise and fast by adding some “handlers”.

About Lombok:

Lombok can simplify java code in the form of simple annotations and improve the development efficiency of developers. For example, JavaBeans often need to be written in development. They need to spend time to add corresponding getter/setter, and maybe also need to write constructor, equals and other methods. Moreover, they need to be maintained. When there are many attributes, there will be a large number of getter/setter methods, which are very lengthy and not too technical. Once the attributes are modified, it is easy to forget to modify the corresponding methods.

Lombok can automatically generate constructor, getter/setter, equals, hashcode and toString methods for attributes at compile time through annotation. The magic is that there are no getter and setter methods in the source code, but there are getter and setter methods in the bytecode file generated by compilation. This saves the trouble of manually rebuilding the code and makes it look simpler.

terms of settlement:

1.1ctrl + Alt + s open Settings

Search or directly select plugins and search Lombok installation in the marketplace

After installation, as shown in the figure

After recompiling, you can run the project, and the log error disappears

Error reporting when Lombok @ data and @ builder are used together

Lombok @data and @builder are used together
Lombok often uses annotations

error
Sometimes @Builder annotation is added to PO class in order to make the code more elegant when constructing PO class. However, because @Builder and @Data will be used together, the class’s no-argument constructor will be overwritten. As a result, some framework can not successfully assign Data to PO class when operating the database, such as MyBatis.
The solution
Override the no-argument constructor in the class to prevent conflict with Lombok’s annotation, and add the @tolerate annotation on the no-argument constructor
Such as:

@Data
@Builder
public class DataBuilder implements Serializable {

    @Tolerate
    public DataBuilder (){}

}

Lombok uses annotations
A lot of online lecture Here I think a good link
https://www.cnblogs.com/heyonggang/p/8638374.html

Brief introduction of idea Lombok and solutions for reporting red and wrong

idea lombok
Introduction of lombok
Lombok is a Java library that automatically switches on editors and build tools. For simple Java objects, you can substitute getters and Setter methods in code with annotations such as @setter @getter. Lombok uses annotations, but instead of using reflection, it dynamically replaces annotations with concrete code at compile time. So the actual code that the JVM runs is the same as the classes that we write manually that contain the various tool methods.
Lombok annotations
Val: final declares a variable in fianl just like a dynamic language does. Var: with JDK10 @ Data: annotation on the class, will provide all of the attributes of the class to add the get and set methods, and add, equals, canEquals @ Setter, hashCode, and toString method: annotation on the class, add a set method for all attribute, comments on the property for the attribute set method @ Getter: annotation on the class, add the get method to all of the properties, comments on the attribute of the attribute provides the get method @ NotNull: When used in the parameter, if pass the null values when the call, will be thrown null pointer exception @ Synchronized to method, can lock the specified object, if not specified, the default to create an object locking @ the Log function in the class, create a Log properties @ Builder: using the Builder pattern to create objects @ NoArgsConstructor: create a a no-parameter constructor @ AllArgsConstructor: create a full constructor @ ToString refs: Create a ToString method @accessors (chain = true) that uses the chain setting property. The set method returns this object. @RequiredArgConstructor (StaticName = “of”) creates and generates a static method @UtilityClass: Utility class @ExtensionMethod: Sets parent class @FieldDefaults: Sets the scope of properties, such as private, public, etc., and can also set whether properties are final modified. @cleanup: Close streams, join points. @equalSandHashCode: Overrides the equals and hashCode methods. @toString: Create the toString method. @cleanup: Can be used for streams etc without needing to close the use of stream objects.
Lombok error resolution:
1. Use compiler to select javac
2. Enable Annotation Processing

. After installation, restart IDEA. Gives effect to the plugin
4. Maven versions do not agree with the idea lombok version


4. Idea2018 version
IntelliJ idea 2018.1.5 \ plugins \ android \ lib \ templates \ gradle \ wrapper \ gradle \ wrapper
idea under the install directory
ideaVersion=2018.1
start idea then manually install Lombok plugins and restart again