Getter is not created in lombok@Data?

Asked 1 years ago, Updated 1 years ago, 271 views

I am studying java at SpringToolSuite4.
I am trying to automatically add Getter, Setter, etc. using lombok@Data.
However, the controller does not digest Getter, so

Enter a description of the image here

Even if I access it directly from the browser, I still get an error.
Unresolved compilation problem:Method getName() is undefined for type User

The class definition specifies @Data in the following code:

package com.example.demo.models;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import lombok.Data;

@ Data
@Entity
@Table(name="user")
public class User implements Serializable {
    private static final long serialVersionUID=-6647247658748349084L;

    @Id
    @GeneratedValue (strategy=GenerationType.IDENTITY)
    private long id;

    @NotBlank
    @Size(min=3,max=10)
    private String name;

    @NotBlank
    @ Email
    private String mail;

    @Size (max=400)
    private String introduction;
    
    @NotBlank
    @Size(min=3,max=20)
    private String nickname;

    public void clear() {
        name = null;
        mail = null;
        introduction=null;
        nickname = null; 
    }
}

The main controller is called as follows:

@GetMapping("/form3")
    public String form 3 (User user) {
        String nameString=user.getName();
        // Abbreviated
        return "root/form3";
    }

Looking at the official page of Lombok, the above settings seem good.
https://projectlombok.org/features/Data

Could you tell me what the problem is?
Thank you for your cooperation.

[Additional note: 2022-06-23]
I added Getter and Setter of the same Lombok part as below.
Import has also been added.

@NotBlank
    @Getter
    @Setter
    @Size(min=3,max=10)
    private String name;

However, if you look at the controller, it does not appear.
This seems to be because IDE or rombook is not working properly.

As I mentioned in the comment in the answer, the lombok reinstallation has already been performed.
Enter a description of the image here
*Getter and setter are not displayed in the available methods

記Additional note: 2022-06-24 br
When I wrote the code as follows, I was warned that it was undefined, but
It ran without errors as well as the compiler.
That means getter and setter have been made.
Enter a description of the image here

Strangely enough, however, if you step in with debugging
Move to a place where there is no code at all.
Enter a description of the image here
Should I think that spring tool suite is not working properly?

java spring-boot

2022-09-30 22:04

2 Answers

If you are using gradle,
If you add the following to the dependencies in build.gradle, it will work.

compileOnly'org.projectlombok:lombok'
announcementProcessor 'org.projectlombok:lombok'

*We used IntelliJ IDEA for operation verification.


2022-09-30 22:04

You must install rombok on SpringToolSuite4 (STS).

official site, if lombok is installed, it will appear on the About Spring Tool Suite 4 of the STS.
Please check to see if this is output as expected.

It is generally wrong to give @Data to @Entity (if you need gette/setter, @Getter, @Setter should be used).


2022-09-30 22:04

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.