null值从angularjs前端传递到jersey后端

时间:2017-05-10 09:35:39

标签: angularjs jersey

我使用角度前端和java jersey作为后端。当我从表单提交数据时,传递空值而不是实际的表单数据。这是我的表格

<div id="main">
<h1>Create Leave</h1>
<form class="form-horizontal" >
   <div class="form-group">
      <label for="employeeName" class="col-sm-3 control-label">Employee Name</label>
      <div class="col-sm-6">
         <input type="text" id="num" class="form-control" ng-model="num" />
      </div>
      <div class="col-sm-3"></div>
   </div>
   <div class="form-group">
      <label for="leaveType" class="col-sm-3 control-label">Leave Type</label>
      <div class="col-sm-2">
         <select id="leaveType" class="form-control" ng-model="leaveType">
            <option value="hospital">Hospital</option>
            <option value="l1">leave type 2</option>
            <option value="l2">leave type 3</option>
            <option value="l3">leave type 4</option>
            <option value="l4">leave type 5</option>
            <option value="l5">leave type 6</option>
         </select>
      </div>
      <div class="col-sm-7"></div>
   </div>
   <div class="form-group">
      <label for="leaveStartDate" class="col-sm-3 control-label">Leave Start Date</label>
      <div class="col-sm-2">
         <input type="date" id="startDate" class="form-control" ng-model="startDate" />
      </div>
      <div class="col-sm-7"></div>
   </div>
   <div class="form-group">
      <label for="leaveEndDate" class="col-sm-3 control-label">Leave End Date</label>
      <div class="col-sm-2">
         <input type="date" id="endDate" class="form-control" ng-model="endDate" />
      </div>
      <div class="col-sm-7"></div>
   </div>
   <div class="form-group">
      <div class="col-sm-3"></div>
      <div class="col-sm-2">
         <span><b>Is Half Day leave</b></span>
         <div class="radio">
            <label><input value="Yes" type="radio" name="halfDay" ng-model="isHalfDay" />Yes</label>
         </div>
         <div class="radio">
            <label><input value="No" type="radio" name="halfDay" ng-model="isHalfDay" />No</label>
         </div>
      </div>
   </div>
   <button ng-click="add()" class="btn btn-primary">Submit</button> 
   <button ng-click="resetForm()" class="btn">Reset</button>
</form>

这是控制器

app.controller("MyAddController", function($scope, $http) {
	//$scope.test = {};
    $scope.add = function() {
    //	console.log("------------>"+JSON.stringify($scope.test));
        $http.post("webapi/blog/create", {
            params: {
                signum: $scope.num,
                leaveType: $scope.leaveType,
                startDate: $scope.startDate,
                endDate: $scope.endDate,
                isHalfDay: $scope.isHalfDay

            }
        }).success(function(data, status, headers, config) {
            if (data) {
                $scope.data = data;
                alert("success");
            }
        }).error(function(data, status, headers, config) {
            alert("error");
        })
    }
});

和球衣代码

	@POST
	@Path("create")
	@Produces({ "application/json" })
	public String create(@BeanParam LeaveDetails ld) {
		System.out.println("Entered here");
		System.out.println(ld.getIsHalfDay());
		System.out.println(ld.getNum());
		System.out.println(ld.getEndDate());
		System.out.println(ld.getStartdate());
		System.out.println(ld.getLeaveType());
		new AddLeaveDao().addDetails(ld);
		System.out.println("Returned  here");
		return "{}";
	}

请帮忙

0 个答案:

没有答案