the form is submitted with the picture. Save the picture first. After saving the picture, save the path to the database to get the id, and then assign the id to the form object entity.
if after the picture is saved, the sql of the saved form needs to be rolled back, and sql can roll back. How do I delete the previously uploaded file?
@Transactional(rollbackFor = Exception.class)
public int insert(Form form, MultipartFile file) throws IOException {
if (!file.isEmpty()) {
//
form.setImage(sysFileService.upLoad(file).getId());
}
return mapper.insert(form);
}
when an exception occurs, you can specify the exception handling class manually. Can I rewrite an exception handling class, send some path information after the file is uploaded, and then delete the file?