2014-04-16 66 views
0

我有WebService,它檢查電子郵件是否已經存在於數據庫中。客戶端發送的請求在使用AngularJS通過休息調用WebService時在語法上不正確

@RequestMapping(value = "/checkPersonEmail/{jClientSessionId}/{jClientSessionId}/{email}", method = RequestMethod.GET) 
public boolean checkName(@PathVariable String jUserSessionId, 
     @PathVariable String jClientSessionId, @PathVariable String email) 
     throws Exception { 
    String decryptedClientKey = EncryptContetns 
      .getDecryptedvalue(jClientSessionId); 
    List<String> emailIds = dimPersonManager 
      .getEmailIdsByClientKey(Long.valueOf(decryptedClientKey)); 
    List<String> emailIdList = new ArrayList<String>(); 
    for (String ids : emailIds) { 
     emailIdList.add(ids.toLowerCase()); 
    } 
    if (emailIdList != null && !emailIdList.isEmpty()) { 
     if (emailIdList.contains(email.toLowerCase())) { 
      return false; 
     } else { 
      return true; 
     } 
    } else { 
     return true; 
    } 

} 

然後我使用http.get方法調用此服務,如下所示。

AngularJS調用

$scope.checkEmail = function() { 
    if (!appClient.isUndefinedOrNull($scope.person.email)) { 
     alert($scope.person.email); 
     $scope.spinnerClass = "icon-2x icon-spinner icon-spin"; 
     var serverConnect = serverUrl + 'checkPersonEmail' + '/' + jUserSessionId + '/' + jClientSessionId + '/'+ $scope.person.email; 
     $http.get(serverConnect).success(function(data, status) { 
      // alert(JSON.stringify(data)); 
      if (data == "true") { 
       $scope.spinnerClass = "icon-hide"; 
       $scope.msgClass = "text-success icon-ok"; 
       $scope.message = "Available"; 
      } else { 
       $scope.spinnerClass = "icon-hide"; 
       $scope.msgClass = "text-error icon-remove"; 
       $scope.message = "Not Available"; 
      } 
     }).error(function(data, status) { 
      alert("Failure"); 
     }); 
    } 
} 

每當這個checkEmail被稱爲是一個HTTP錯誤請求(400)

回答

0

可能是因爲你有兩個jClientSessionId並在@RequestMapping ({jClientSessionId}/{jClientSessionId})?

沒有 jUserSessionId
0

如果您的控制器沒有註釋爲@RestController,則需要在checkName方法上註釋@ResponseBody註釋。

相關問題