2015-08-18 46 views
0

工作,我有以下控制器:RequestParam標註沒有用POST

@RequestMapping(value = { "/member/uploadExternalImage", 
      "/member/uploadExternalImage" }, method = RequestMethod.POST) 
    public String handleFileUpload(@RequestParam("url") String url, 
      Principal principal) throws IOException { 
     File file = restTemplate.getForObject("url", File.class); 
     file.toString(); 
     return null; 
    } 

和我有以下的ajax:

 $.ajax({ 
      url: 'uploadExternalImage', //Server script to process data 
      type: 'POST', 
      success: function() { 

      }, 
      complete:function(){ 
       $.fancybox.hideLoading(); 
      }, 

      // Form data 
      data: {url: files[0].link}, 

      cache: false, 
      contentType: false, 
      processData: false 
     }); 

春天日誌我看到

org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter 'url' is not present 

如果我用GET更改ajax方法:

$.ajax({ 
       url: 'uploadExternalImage?url=123', //Server script to process data 
       type: 'POST', 
       success: function() { 

       }, 
       complete:function(){ 
        $.fancybox.hideLoading(); 
       }, 
       error: function (data) { 

       }, 

       cache: false, 
       contentType: false, 
       processData: false 
      }); 

它正常工作

如何正確配置彈簧?

回答

0

http POST能夠用於請求主體請求參數。但是你試圖以不同的方式使用它。如果您想要的請求體,然後使用@RequestBody

+0

是的,這個工作

 $.ajax({ type: 'POST', url: "uploadExternalImage?url=BLABLA", data: text, success: function (data) { // } }); 

試試這個。但我想要通過身體內的數據 – gstackoverflow

+0

請參閱我的編輯請 –

+0

看看這裏:https://spring.io/guides/gs/handling-form-submission/ – ACV

相關問題