Org.springframework.web.bind.MissingServletRequestParameterException: Required Long parameter 'userId' missing "

I get an exception when sending a spring controller call

An exception:

 org.springframework.web.bind.MissingServletRequestParameterException : Required Long parameter 'userId' is not present"

My Javascript File:

$scope.removeUser = function(user){
        var userId = JSON.stringify(user);
        $http.post('/portal/settings/user/deletecustomeruser', userId).success(function(data){
                $scope.response = data;
            })
        }
    }

Spring controller code:

      @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 );

When I put it (required = false), the meaning userIdhas become null. The JavaScript controller explicitly sends "userId"in JSON format, but there are some problems on the controller side.

I checked almost all the questions in stackoverflow, but these solutions did not help.

+4
source share
1 answer

, userId , userId ,

userId

 $http.post('/portal/settings/user/deletecustomeruser?userId='+userId)

, userId

myControllerMethod (@RequestBody String userId)
+7

All Articles