Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
角柱未通过长轮询将有效负载传递给java spring_Java_Spring_Angularjs_Long Polling - Fatal编程技术网

角柱未通过长轮询将有效负载传递给java spring

角柱未通过长轮询将有效负载传递给java spring,java,spring,angularjs,long-polling,Java,Spring,Angularjs,Long Polling,我正在尝试使用post将变量传递给JavaSpring。执行java post函数,但所有参数均为null var CreditCard = $resource("http://:host::port/" + context + "/agent/creditCard", {host: "localhost", port: 8080 }, {getTestPost2: {method:'POST', params:{charge:true, jsonPost:"1234"}} });

我正在尝试使用post将变量传递给JavaSpring。执行java post函数,但所有参数均为null

var CreditCard = $resource("http://:host::port/" + context + "/agent/creditCard",
{host: "localhost", port: 8080 }, 
   {getTestPost2: {method:'POST', params:{charge:true, jsonPost:"1234"}}
  });
var newCard = new CreditCard({number:'0123'});
newCard.name = "Mike Smith";
newCard.$save();
我检查了我的网络状态显示200 OK

Request Payloadview source
{number:0123, name:Mike Smith}
name: "Mike Smith"
number: "0123"
爪哇

输出:

jsonPost null
name null
charge false
number null
爪哇


我添加了params和ResponseBody,您可以试试。

您应该编写一个
CreditCard
类来用作参数类型。用
@RequestBody
注释它,让
HttpMessageConverter
将JSON正文转换为所需的对象

@ResponseBody
@RequestMapping(
        value="/agent/creditCard",
        method = RequestMethod.POST,
        consumes = MediaType.APPLICATION_JSON_VALUE) 
public void postCreditCard(@RequestBody CreditCard creditCard) {
    // process data...
}

嗨@smallg,我试过你的答案,但没用。post调用没有得到execute,我得到了一个400头错误。虽然我不熟悉Angular,但我愿意打赌您在那里的保存方法不是发布表单数据,而是发布其他内容(可能是JSON),而Spring控制器显然设置为接受表单参数hanks@Bart,我将尝试这个方法。我刚刚搜索了“HttpMessageConverter”,似乎我必须在Spring中实现很多,然后才能看到这个调用正在执行。这不是真的。只需将Jackson 2+添加到类路径,一个
MappingJackson2HttpMessageConverter
将自动添加到
RequestMappingHandlerAdapter
。再简单不过了。谢谢@Bart,它很管用!。我也参考。
@RequestMapping(
            value="/agent/creditCard",
            method = RequestMethod.POST,
            params = { "jsonPost", "charge", "name", "number"}
            produces = MediaType.APPLICATION_JSON_VALUE) 
@ResponseBody
    public @ResponseBody void getTestPost2( 
                    @PathVariable String clientId, 
                    @RequestParam(value="jsonPost", required=false) String jsonPost, 
                    @RequestParam(value="charge", required=false) boolean charge,               
                    @RequestParam(value="name", required=false) String name,
                    @RequestParam(value="number", required=false) String number
            ){

        logger.debug("jsonPost " + jsonPost);
        logger.debug("name " + name);
        logger.debug("charge " + charge);
        logger.debug("number " + number);

    }
@ResponseBody
@RequestMapping(
        value="/agent/creditCard",
        method = RequestMethod.POST,
        consumes = MediaType.APPLICATION_JSON_VALUE) 
public void postCreditCard(@RequestBody CreditCard creditCard) {
    // process data...
}