2017-12-01 5 views
0

私のコードベースでは、特定のIDのレコードを削除するためにREST APIを使用しています。私は以下のように削除サービスに加入して次のようにJavaでCORSエラー:REST APIを使用して特定のIDのレコードを削除する

deleteScheduleViewService(id : number) : Observable<any> { 
    let url = `http://localhost:8080/schedules/${id}`; 
    return this.http.delete(url) 
    .map(response => response.json() as any); 
} 

私のRESTエンドポイントは次のとおりです。

@RequestMapping(value = "/schedules/{id}", method = RequestMethod.DELETE) 
public void deleteSchedules(@PathVariable("id") Long id) 
{ 
    scheduleServiceManager.deleteSchedule(id); 
} 

私の重要な問題は、私が削除エンドポイントURLのことで任意のIDと一致しない方法です。一種の正規表現を入れてIDを抽出しますか?

編集は

私は、RESTエンドポイントにアクセスしようとすると、次のエラーが表示されます。私は今、クロスオリジンリソースの共有エラーを取得していますように

Response to preflight request doesn't pass access control check: 
No 'Access-Control-Allow-Origin' header is present on the requested resource. 
Origin 'http://localhost:8090' is therefore not allowed access. The response had HTTP status code 405. 

それはそうです。

+0

.html –

答えて

0

"Access-Control-Allow-Origin"を解決するには、コントローラクラスにCrossOriginを追加します。たとえば、次のポスト以下、http://javabycode.com/spring-framework-tutorial/spring-mvc-tutorial/cross-origin-request-blocked-spring-mvc-restful-angularjsをCORSを有効

@CrossOrigin("*") 
@Controller 
public class YourSuperController 
関連する問題