Jersey RESTful WebService框架学习(二)使用@PathParam

@PathParamuri路径参数写在方法的参数中,获得请求路径参数。比如:@PathParam("username") String userName

[size=large]前端请求:[/size]
<!DOCTYPE html>
<html ng-controller="PathParam">
<head>
<title>@PathParam</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("@PathParam.html", []).controller("PathParam",
function($scope, $http) {
$scope.init = function() {
$http({
method : 'get',
//拼装uri路径参数
url : "/Jersey/api/1.0/my/first/1"
}).success(function(data) {
alert(angular.toJson(data));
});
};
});
angular.bootstrap(document, ['@PathParam.html']);
</script>
</html>


[size=large]后端接收:[/size]
package com.lx.api;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

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


效果:

[img]http://dl2.iteye.com/upload/attachment/0127/8777/d9ee0bff-7586-3746-a52f-931573406e72.png[/img]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值