1

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.

bib
  • 944
  • 3
  • 15
  • 32

1 Answers1

0

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!

Shyam Patel
  • 381
  • 2
  • 13
  • When I configured Spring Boot projet I added lombok. So in my Pom.xml I have the following: org.projectlombok lombok true – bib Oct 12 '22 at 13:47