0

i have a method which has a task to save a entity that contains the file location and other fields to save to the data base. it save up a picture in the local folder than insert the file location and description to the data base. as you can see on the code i am using a lombok ,springboot ,jpa .the method works fine! and i am able to store my file location and description on the database but what makes problem is that Image.builder() is red and when i click on it it says ( create the method bulider in the image class ). image is my entity class and even if i create the bulider method on the image it dose not solve the problem. need to slove the error on the bulider

image entity

@Entity
@Table(name = "IMAGE")
@Data
@AllArgsConstructor
@Builder
public class Image {

    public Image(){
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    private int id;
    @Column(name = "name")
    private String name;
    @Column(name = "path")
    private String path;
    @Column(name = "description")
    private String description;
    @Column(name = "url")
    private String url;

}

imageServic

@Service
@Builder

public class ImageServic {

    @Value("${image.path}")
    private String path;
    @Value("${image.url}")
    private String url;
    @Autowired
    private ImageRepository repository;

    public Image saveImage(MultipartFile file, String description) {
        try {
            byte[] bytes = file.getBytes();
            Path pathImage = Paths.get(path + file.getOriginalFilename());
            Files.write(pathImage, bytes);
        } catch (IOException e) {
            e.printStackTrace();
        }
        file.getOriginalFilename();
        Image image = Image.builder()  // here .builder() is red
                .name(file.getOriginalFilename())
                .description(description)
                .path(path)
                .url(url + file.getOriginalFilename())
                .build();
        repository.save(image);
        return image;
    }

    public List<Image> findAllImageUrl() {
        return repository.findAll();
    }

    public byte[] downloaderImage(String imageName) throws Exception {
        InputStream in = new FileInputStream(path + imageName);
        return IOUtils.toByteArray(in);
    }
}
pooya
  • 115
  • 3
  • 13
  • 3
    Are you using an IDE, such as Eclipse, Netbeans or IntelliJ Idea? If so, have you installed Lombok in it? For example, [here](https://projectlombok.org/setup/eclipse) are the instructions for Eclipse. – JustAnotherDeveloper Aug 29 '20 at 14:44
  • What is `Image`? – Andreas Aug 29 '20 at 14:45
  • @JustAnotherDeveloper you gave me a idea. i didn't have Lombok plugin on my IDE so after installing that now i din't have a red line on the `builder()` . thank you – pooya Aug 29 '20 at 14:56

0 Answers0