现在的web开发中有些工程会觉得实体bean的架构会比较重,现在的持久层的框架的特点也层出不穷,核心思想的ORM在此基础上,提供了很多便捷操作,mybatis,jfinal(内部持久层框架)之类的也诞生了很多工具,包括官方的也不乏很多国产的,说这么多。。。表达一个意思很多框架都提供map形式的入库,说说Jersey 这个RESTful 框架怎么处理前端对象转为map的吧。
一、前端静态页面
<body>
<input type="text" name="name" ng-model="user.name">
<input type="text" name="age" ng-model="user.age">
<input type="button" value="保存" ng-click="save()">
</body>
二、http请求
<script type="text/javascript">
var app = angular.module("app", []);
app.controller("ctrl", function($scope, $http) {
$scope.user = {};
$scope.save = function() {
$http({
method : 'post',
url : "/Jersey/api/1.0/my/MultivaluedMap",
data : "json=" + angular.toJson($scope.user),
headers : {
'Content-Type' : 'application/x-www-form-urlencoded'
}
}).success(function(data) {
alert(data)
});
};
});
</script>
三、后端接收
@SuppressWarnings("unchecked")
@POST
@Path("/MultivaluedMap")
@Consumes("application/x-www-form-urlencoded")
@Produces({ MediaType.APPLICATION_JSON + ";charset=UTF-8" })
public String bean(MultivaluedMap<String, String> viParams) {
//得到viParams转换为json
System.out.println(viParams.getFirst("json"));
//转为map便于入库
System.out.println((Map<String, String>)JSON.parse(viParams.getFirst("json")));
return viParams.getFirst("json");
}
分享到:
相关推荐
NULL 博文链接:https://1197581932.iteye.com/blog/2400218
NULL 博文链接:https://1197581932.iteye.com/blog/2400927
jersey restful webservice最新版资源共享,欢迎下载!
NULL 博文链接:https://1197581932.iteye.com/blog/2409545
Restful Jersey webservice:包括Jersey实现的Restful webservice工程,这是一个比较实用的实例项目,在Tomcat中能实际正常运行起来。
NULL 博文链接:https://liangyingying1117.iteye.com/blog/2061846
jersey-1.1.2 restful webservice
Jersey和Tomcat构建RESTful WebService及其调用
基于REST的软件体系结构风格(Software Architecture Style)称之...按照REST原则设计的软件、体系结构,通常被称为“REST式的”(RESTful),在本文中以下称之为 RESTful Web服务,以便于和基于SOAP的Web服务区别。
在Eclipse中使用Jersey和Tomcat构建RESTful WebService及其调用
一个使用Jersey和Tomcat搭建的RESTful WebService,实现了使用Get,POST,PUT,DELETE方法来操作资源,极具构建RESTful WebService的参考价值。
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集成
NULL 博文链接:https://royal2xiaose.iteye.com/blog/1489649
Web Service 必看之书,采用Restful风格开发
使用restlet实现了最简单的restful webservice,可以直接部署运行。可以作为restful webservice开发的基础环境。
很少有的关于restful webservice视频,希望对大家有点帮助,最近下载资料有些频繁,赚点学分。
使用eclipse创建restful webservice 工程.d
开发RESTful WebService 示例