【发布时间】:2017-10-23 08:10:32
【问题描述】:
我无法将数据从 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");
})
}});
<body ng-app="myApp" ng-controller="mycon">
<center>
<h2> Login Here! </h2>
<hr/>
<form >
<table>
<tr>
<td>Signum Id:</td>
<td><input type="text" ng-model="test.sig"/></td>
</tr>
<tr>
<button class="btn waves-effect waves-light" type="submit" ng-click="add()" name="action"> Submit <i class="material-icons right">send</i>
</tr>
</table>
</form>
</center>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.5/js/materialize.min.js"></script>
</body>
其余代码放在这里:
@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;
}
我希望表单中的符号字段作为参数传递给 rest 方法。 我得到的输出为空。
【问题讨论】:
-
你
return null在你的后端函数中 -
conole.log 语句的输出是什么?
标签: javascript java angularjs rest