1 回答

TA貢獻(xiàn)1777條經(jīng)驗(yàn) 獲得超10個(gè)贊
我有適合您的解決方案,請(qǐng)檢查@ModelAttribute請(qǐng)Spring-boot
檢查以下示例
使用 getter setter 創(chuàng)建類并為所有不同的關(guān)鍵參數(shù)添加數(shù)據(jù)成員,請(qǐng)參考下面的示例
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 發(fā)布請(qǐng)求
@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);
? ?}
}? ??
你可以參考這個(gè)鏈接示例@ModelAttributewith spring-bootwithangular
希望對(duì)你有用
添加回答
舉報(bào)