Javascript 从HTML表单获取值时返回Null和REST

Javascript 从HTML表单获取值时返回Null和REST,javascript,java,angularjs,rest,Javascript,Java,Angularjs,Rest,我无法将数据作为参数从html表单获取到java rest方法。 以下是我的html和angular代码: var app=angular.module("myApp",[]); app.controller("mycon",function($scope,$http){ console.log("entered here1"); $scope.test={}; $scope.add = function() { console.log("entered

我无法将数据作为参数从html表单获取到java rest方法。 以下是我的html和angular代码:

var app=angular.module("myApp",[]);
app.controller("mycon",function($scope,$http){
    console.log("entered here1");
    $scope.test={};
    $scope.add = function() {
        console.log("entered here2");

    var json=JSON.stringify($scope.test);
    console.log($scope.test);
    console.log(json);

   $http.get("rest/xyz/role", 
           {
                data:json
           }
   ).success(function(data, status, headers, config) {
        $scope.data = data;
    }).error(function(data, status, headers, config) {
        alert("error");
    })





}});

登录这里!

签名Id: 提交发送
Rest代码如下所示:

@GET
@Path("/role")
@Consumes({ MediaType.APPLICATION_JSON})
//@Consumes("text/plain")
@Produces({ "application/json" })
public String list(String s) {
    System.out.print("Entered here ");

    System.out.print(s);

    return null;
}
我希望表单中的signum字段作为rest方法中的参数传递。 我得到的输出为空

使用http.post:

 $http.post("rest/xyz/role", {
                data:json
           } ...

您在后端函数中
返回null
conole.log语句的输出是什么?如果OP应该使用
$http.post
他/她还必须更改后端侧的注释当然可以,因为get请求无法获取json数据。我现在正在获取json数据。但它是字符串格式的,如何访问该json数据的sig字段。请使用json.parse()。例如,var obj=JSON.parse('{“name”:“John”,“age”:30,“city”:“newyork”}');如何将数据作为字符串从表单传递到rest服务。我希望传递值。字符串s具有json格式的数据