一、前端静态页面
<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"); }