2015-06-07 46 views
2

我在使用Spring MVC 4.這裏是我的控制器代碼:HTTP狀態400 - 需要短參數「分數」是不存在的,Spring MVC的REST

@RestController 
public class NewValueController 
{ 
    @RequestMapping(value="/receiveUpdatedScore",method=RequestMethod.POST,produces={"application/json"}) 
    public NewValue receiveUpdateScore(@RequestParam(value="score") short score, 
           @RequestParam(value="user_id") String user_id, 
           @RequestParam(value="device_model") String device_model, 
           @RequestParam(value="api_key") String api_key, 
           @RequestParam(value="gen_t") long gen_t, 
           Model model) 
    { 
    int newScore = (int) score; 
    NewValue algorithm=new NewValue(); 
    NewValue newvalue=algorithm.getNextValue(newScore); 
    return newvalue; 
    } 
} 

我公司採用先進其餘客戶提出這個要求(也試過在同一個郵差):

{"score":"50","user_id":"zyz","device_model":"xiami","api_key":"sasa5454","gen_t":"545666"} 

但我收到以下錯誤

錯誤:

HTTP Status 400 - Required Short parameter 'score' is not present 

message: Required Short parameter 'score' is not present 

description: The request sent by the client was syntactically incorrect. 

什麼是我在這裏無法檢測到的錯誤。請幫我解決它。

+0

嘗試使用這個'@RequestParam(「分數」)的URL的一部分,而不是一些JSON'而不是 –

+0

@Akash Rajbanshi:是的,我現在嘗試。但仍然是同樣的錯誤。 「所需的短參數」分數「不存在」:( – Chandz

+0

將所有參數的類型更改爲字符串... –

回答

0

我想這是因爲分數預計爲您發佈

+0

在「高級休息客戶端」中,我認爲我們必須將Json本身的所有請求參數傳遞給它。在「Post Man」中,我們有用於輸入Key-Value對的UI。我對麼? – Chandz

+0

說實話我不知道這兩個程序。如果您在瀏覽器中打開網址會發生什麼? – Marged

+0

在URL中輸入如此多的參數非常繁瑣,localhost:8080/TestApp/receiveUpdateScore?score = 50&user_id = zyz&device_model = xiami&api_key = sasa5454&gen_t = 545666 – Chandz

相關問題