第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Angular2 / Spring Boot允許在PUT上交叉原點(diǎn)

Angular2 / Spring Boot允許在PUT上交叉原點(diǎn)

我的Web應(yīng)用程序存在一個(gè)小問(wèn)題:一個(gè)與spring boot API連接的angular2應(yīng)用程序。我無(wú)法從angular2應(yīng)用訪問(wèn)我的請(qǐng)求。我收到此錯(cuò)誤:Failed to load http://localhost:8080/deliveryMan/: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.Java代碼:@RestController@RequestMapping(value = "/deliveryMan")@CrossOriginpublic class DeliveryManController {    @Autowired    DeliveryManService deliveryManService;    @RequestMapping(value = "/getAllDeliveryMan", method = RequestMethod.GET)    public Iterable<DeliveryMan> getAllDeliveryMan(){        return deliveryManService.findAll();    }    @RequestMapping(method = RequestMethod.PUT, consumes = "application/json")    public DeliveryMan addDeliveryMan(@RequestBody DeliveryMan deliveryMan) throws InvalidObjectException {        deliveryManService.save(deliveryMan);        return deliveryMan;    }@SpringBootApplication@EnableAutoConfiguration@ComponentScanpublic class MyApp{    public static void main(String[] args) {        SpringApplication.run(MyApp.class, args);    }}angular2代碼:private apiUrl = 'http://localhost:8080/deliveryMan/';getAll(): Promise<DeliveryMan[]> {  const url = this.apiUrl + 'getAllDeliveryMan';  return this.http.get(url)    .toPromise()    .then(response => response.json().data as DeliveryMan[])    .catch(this.handleError);}saveDeliveryMan(deliveryMan: DeliveryMan): Promise<DeliveryMan> {  const url = this.apiUrl;  return this.http.put(url, JSON.stringify(deliveryMan), this.headers)    .toPromise()    .then(() => deliveryMan)    .catch(this.handleError);}為了解決該問(wèn)題,我在控制器類中添加了@CrossOrigin。它解決了getAll方法的問(wèn)題,但沒(méi)有解決其他方法的問(wèn)題。如何解決它,以便我可以使用PUT方法而不會(huì)出現(xiàn)此錯(cuò)誤?
查看完整描述

3 回答

?
犯罪嫌疑人X

TA貢獻(xiàn)2080條經(jīng)驗(yàn) 獲得超4個(gè)贊

@CrossOrigin(origins = "http://localhost:4200")向您的控制器添加注釋,例如:


@CrossOrigin(origins = "http://localhost:4200")

@RequestMapping(method = RequestMethod.PUT, consumes = "application/json")

    public DeliveryMan addDeliveryMan(@RequestBody DeliveryMan deliveryMan) throws InvalidObjectException {

        deliveryManService.save(deliveryMan);

        return deliveryMan;

    }


查看完整回答
反對(duì) 回復(fù) 2019-10-12
?
慕仙森

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超8個(gè)贊

您可以只使用:(它對(duì)所有CRUD操作都適用)


@CrossOrigin(origins = "*")


查看完整回答
反對(duì) 回復(fù) 2019-10-12
  • 3 回答
  • 0 關(guān)注
  • 598 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)