angular.js - angularjs到底如何传参到springMVC
为情所困
为情所困 2017-05-15 17:01:04
0
2
535

话说angular的传参转变为json格式,而又需要springMVC有相关的实体类才能用@requestBody去接收。但是如果传的是一般的参数呢,比如一个数组,一个数字id?

当然,传一个数字id可以从请求参数路径传过去。但是,就是传一般的随机的参数,比如data={“xx”,xxx}

和明显,springMVC端是不能像接收jquery时候用@requestParam接收的。

网上看了一大片,说要改请求的header的contentType什么的,可是,设置了也没用.......怎么办?

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

spirngMVC端如何接收data={“xx”,xxx},

为情所困
为情所困

Antworte allen(2)
巴扎黑

前台代码:

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

后台接收

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

          
Ty80

问题不是angular怎么传参数到后台,主要是看你后台怎么实现的。后台给出一个接口对于angular就足够了,angular直接$http调后台接口就能把参数传给后台了。

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

这样就可以把参数parameter传给后台了,至于是get还是post或者其他的主要还是看后台。

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!