[英]Resolved exception caused by Handler execution: org.springframework.web.bind.MissingServletRequestParameterException:
[英]org.springframework.web.bind.MissingServletRequestParameterException : Required Long parameter 'userId' is not present"
我在發布對Spring控制器的調用時遇到異常
例外情況是:
org.springframework.web.bind.MissingServletRequestParameterException : Required Long parameter 'userId' is not present"
我的Javascript文件是:
$scope.removeUser = function(user){
var userId = JSON.stringify(user);
$http.post('/portal/settings/user/deletecustomeruser', userId).success(function(data){
$scope.response = data;
})
}
}
Spring控制器代碼是:
@RequestMapping( value = "/user/deletecustomeruser", method = RequestMethod.POST , headers="Accept=application/json")
public @ResponseBody String deleteCustomerUser( @RequestParam (value = "userId") Long userId,
HttpServletRequest request )
throws Exception
{
String returnString = "";
User user = userService.getUserById( userId );
當我把(required = false)
, userId
值變為null
。 JavaScript控制器顯然以JSON格式發送"userId"
,但是從控制器端出現了一些問題。
我在stackoverflow中檢查了幾乎所有問題,但給定的解決方案沒有幫助。
您希望userId作為服務器端的請求參數,但是您在客戶端http post請求中將userId作為請求主體發送,
更改客戶端以將userId作為請求參數發送
$http.post('/portal/settings/user/deletecustomeruser?userId='+userId)
或者更改服務器端以將userId用作控制器中的請求主體
myControllerMethod (@RequestBody String userId)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.