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);
}
}