我已经成功创建了一个实体并可以发布到它。我希望能够使用 blob 文件更新表的列。当我发出发布请求时,我得到了成功响应,但是该行没有更新
这是实体
@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Service
public class Category {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long categoryId;
@NotNull
@Column(unique=true)
@Size(min = 5, max = 20)
private String categoryName;
@Column(columnDefinition = "MEDIUMBLOB")
private byte[] categoryImage;
@NotNull
@Size(min = 10, max = 50)
private String categoryDescription;
}
图片上传的 PUT 请求
@PutMapping("/categories/{categoryId}/upload")
public ResponseEntity<ResponseMessage> uploadImage(@PathVariable("categoryId") long catID,
@RequestParam() MultipartFile file) {
Optional<Category> category = catService.listCategoryById(catID);
if (category.isPresent()) {
try {
Category _category = category.get();
_category.setCategoryImage(imgService.storeImage(file));
return new ResponseEntity<>(
new ResponseMessage("Uploaded " + file.getOriginalFilename() + " successfully!"),
HttpStatus.CREATED);
} catch (Exception e) {
return new ResponseEntity<>(new ResponseMessage("Failed to upload " + file.getOriginalFilename() + "!"),
HttpStatus.EXPECTATION_FAILED);
}
} else {
return new ResponseEntity<>(new ResponseMessage("Category Does not exist"), HttpStatus.NOT_FOUND);
}
}
影像服务
@Service
public class ImageService {
public byte[] storeImage(MultipartFile file) throws IOException {
return file.getBytes();
}
}
当我执行 PUT 请求时,我得到了这个

但是数据库没有更新。图像列保持为空

你知道为什么吗?