`

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

阅读更多
介绍:@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+"\"}";
	}


效果:



  • 大小: 6.9 KB
2
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics