Jersey RESTful WebService框架学习(二)使用@PathParam_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > Jersey RESTful WebService框架学习(二)使用@PathParam

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

 2017/11/21 16:04:26  柳絮飞祭奠  程序员俱乐部  我要评论(0)
  • 摘要:@PathParamuri路径参数写在方法的参数中,获得请求路径参数。比如:@PathParam("username")StringuserName前端请求:<!DOCTYPEhtml><htmlng-controller="PathParam"><head><title>@PathParam</title><metahttp-equiv="keywords"content="keyword1,keyword2
  • 标签:Web Service 学习 使用 Webservice
@PathParamuri路径参数写在方法的参数中,获得请求路径参数。比如:@PathParam("username") String userName

前端请求:
class="java" name="code"><!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
  • 查看图片附件
发表评论
用户名: 匿名