2015-06-07 27 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

相关问题