@PathParamuri路径参数写在方法的参数中,获得请求路径参数。比如:@PathParam("username") String userName
前端请求:
<!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>
后端接收:
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+"\"}";
}
效果:
- 大小: 9.1 KB
分享到:
相关推荐
NULL 博文链接:https://1197581932.iteye.com/blog/2400218
NULL 博文链接:https://1197581932.iteye.com/blog/2400927
jersey restful webservice最新版资源共享,欢迎下载!
NULL 博文链接:https://1197581932.iteye.com/blog/2409545
NULL 博文链接:https://liangyingying1117.iteye.com/blog/2061846
Restful Jersey webservice:包括Jersey实现的Restful webservice工程,这是一个比较实用的实例项目,在Tomcat中能实际正常运行起来。
一个使用Jersey和Tomcat搭建的RESTful WebService,实现了使用Get,POST,PUT,DELETE方法来操作资源,极具构建RESTful WebService的参考价值。
jersey-1.1.2 restful webservice
Jersey和Tomcat构建RESTful WebService及其调用
在Eclipse中使用Jersey和Tomcat构建RESTful WebService及其调用
基于REST的软件体系结构风格(Software Architecture Style)称之...按照REST原则设计的软件、体系结构,通常被称为“REST式的”(RESTful),在本文中以下称之为 RESTful Web服务,以便于和基于SOAP的Web服务区别。
RESTful WebService是比基于SOAP消息的WebService简单的多的一种轻量级Web服务,RESTful WebService是没有状态的,发布和调用都非常的轻松容易。 下面写一个最简单的Hello World例子,以便对RESTful WebService有...
Java restful和webservice接口, WebService有两种方式,一是SOAP方式,二是REST方式。SOAP是基于XML的交互,WSDL也是一个XML文档,可以使用WSDL作为SOAP的描述文件;REST是基于HTTP协议的交互,支持JSON、XML等交互...
Restful WebService与Spring集成
使用eclipse创建restful webservice 工程.d
NULL 博文链接:https://royal2xiaose.iteye.com/blog/1489649
使用restlet实现了最简单的restful webservice,可以直接部署运行。可以作为restful webservice开发的基础环境。
Web Service 必看之书,采用Restful风格开发
很少有的关于restful webservice视频,希望对大家有点帮助,最近下载资料有些频繁,赚点学分。
使用cxf、spring构建的rest风格webservice,其他相关技术springmvc、mybatis、druid等。代码中使用的数据库为sybase,请根据实际环境更改,需修改pom中引用的数据库驱动,依照entity类的属性建对应表,并修改config....