1 回答

TA貢獻1777條經驗 獲得超10個贊
我有適合您的解決方案,請檢查@ModelAttribute請Spring-boot
檢查以下示例
使用 getter setter 創建類并為所有不同的關鍵參數添加數據成員,請參考下面的示例
class FileUploadRequest? {
? ?private MultipartFile profileImage;
? ?private MultipartFile addressImage;
? ?private MultipartFile[] images; // you can use list or array
? ?private String requestData; // you can use another pojo or Jsonobject
? ?// add getter setter here...
}
在您的休息控制器中使用@ModelAttribute 并使用 MULTIPART_FORM_DATA_VALUE使用您的 HTTP 發布請求
@PostMapping(value = "/saveDetails", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public void saveDetails(@ModelAttribute FileUploadRequest uploadRequest) {
? try {
? ? ? if(CommonUtils.isObjectNullOrEmpty(uploadRequest.getRequestData()) || CommonUtils.isObjectNullOrEmpty(uploadRequest.getProfileImage()) || CommonUtils.isObjectNullOrEmpty(uploadRequest.getAddressImage())){
? ? ? ? ? logger.warn("Data Should not be null ==>");
? ? ? } else {
? ? ? ? ? detailSaveService.saveOrUpdateDetails(uploadRequest.getProfileImage()), uploadRequest.getAddressImage()),uploadRequest.getRequestData()));
? ? ? }
? ?} catch (Exception e) {
? ? ? ?logger.error("Error while saving profile Details ==>", e);
? ?}
}? ??
你可以參考這個鏈接示例@ModelAttributewith spring-bootwithangular
希望對你有用
添加回答
舉報