介绍:@QueryParamuri路径请求参数写在方法的参数中,获得请求路径附带的参数。比如:@QueryParam("desc") String desc





前端控制

<!DOCTYPE html>
<html ng-controller="QueryParam">
<head>
<title>@QueryParam</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="../plugins/angular/angular.js"></script>
</head>
<body>
<div ng-click="init()">获取数据</div>
<br>
</body>
<script type="text/javascript">
angular.module("@QueryParam.html", []).controller("QueryParam",
function($scope, $http) {
$scope.init = function() {
$http({
method : 'get',
//拼装uri路径参数
url : "/Jersey/api/1.0/my/first?id=123"
}).success(function(data) {
alert(angular.toJson(data));
});
};
});
angular.bootstrap(document, ['@QueryParam.html']);
</script>
</html>

后端取值

	@GET
@Path("/first")
@Produces({ MediaType.APPLICATION_JSON + ";charset=UTF-8" })
public String QueryParam(@QueryParam(value = "id") String id) {
System.out.println("我的第一个jersey程序");
return "{\"id\":\""+id+"\"}";
}

效果:



Jersey RESTful WebService框架学习(三)使用@QueryParam-LMLPHP

05-11 11:30