Home > Net >  Why lombok do not create the setters and getters?
Why lombok do not create the setters and getters?

Time:10-13

I am new to Spring Boot framework and lombok.

I defined my entity like that:

@Entity
@Table(name = "student")
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class Student implements Serializable{
    
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private int id;
    private String firstName;    
    private String lastName;
    private String email;
}

I also create a controller where I add the following:

 @PostMapping(path="/add") // Map ONLY POST Requests
      public @ResponseBody String addNewUser (@RequestParam String name
          , @RequestParam String email) {
        // @ResponseBody means the returned String is the response, not a view name
        // @RequestParam means it is a parameter from the GET or POST request

    Student st = new Student();
    st.setFirstName(name);
    st.setEmail(email);
    //studentservice.save(st);
    return "Saved";
  }

I dont know why I have a red line under setFirstName. They ask me to create this function in the student class.

I am using eclipse.

CodePudding user response:

please follow the steps as below:

check pom.xml for lombok dependency

    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.20</version>
        <scope>provided</scope>
    </dependency>

Now you can check your IDE, I hope, it helps!

CodePudding user response:

I use Intellij and it has the same error. But when you build the jar file, either run or debug it, it still runs normally without error.

  • Related