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

本文介绍了如何利用@QueryParam注解来处理HTTP请求中的URI参数。前端通过AngularJS发起带有参数的GET请求,而后端使用Java Jersey框架接收并处理这些参数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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


效果:


42d2d015-c7bb-3201-a654-1aa4db0f0aff.png

转载于:https://www.cnblogs.com/baryon/p/9611406.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值