search

Home  >  Q&A  >  body text

angular.js - How does angularjs pass parameters to springMVC

In other words, angular's parameters are converted to json format, and springMVC needs to have relevant entity classes to receive it with @requestBody. But what if general parameters are passed, such as an array or a numeric ID?

Of course, a digital ID can be passed from the request parameter path. However, it is just to pass general random parameters, such as data={"xx", xxx}

Obviously, the springMVC side cannot receive it with @requestParam like when receiving jquery.

I read a lot on the Internet, saying that I need to change the contentType of the request header, but it doesn’t work even if I set it... What should I do?

$http({
url:"ts",
data={"xx",xxx},
type:"POST"
})
.... ...

How to receive data={"xx", xxx},

on the spirngMVC side
为情所困为情所困2784 days ago603

reply all(2)I'll reply

  • 巴扎黑

    巴扎黑2017-05-15 17:03:04

    Front desk code:

    angular.module('app')
        .factory('Email', function ($resource) {
            return $resource('api/emails/:id', {}, {
                'query': { method: 'GET', isArray: true},
                'get': {method: 'GET'},
                'update': { method:'PUT' }
            });
        });

    Background reception

    @RequestMapping(value = "/emails",
                method = RequestMethod.POST,
                produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<EmailDTO> createEmail(@RequestBody EmailDTO emailDTO) {.....} 
    
              

    reply
    0
  • PHP中文网

    PHP中文网2017-05-15 17:03:04

    The problem is not how Angular passes parameters to the backend, it mainly depends on how you implement it in the backend. It is enough for angular to provide an interface in the background. Angular can directly $http adjust the background interface to pass the parameters to the background.

    $http.get("mainUrl"+parameter).then();
    

    In this way, the parameters can be passed to the backend. As for whether to get or post or anything else, it mainly depends on the backend.

    reply
    0
  • Cancelreply