まず第一に、私のJDKが1.8Tomcatであること、私のプロジェクトがSSM+Mavenであることを説明させてください。
春のフレームワークは4.3です。それを使用する場合、コントローラーの@Controllerアノテーションの前に@Crossoriginを注釈するだけで、SpringMVC.XML構成ファイルに追加する必要があります。
<?xml version = "1.0" encoding = "utf-8"?> <beans xmlns = "http://www.springframework.org/schema/beans" xmlns:xsi = "http://www.w3.org/2001/xmlschema-instance" xmlns:Context = "http://www.springframework.org/schema/context" xmlns:mvc = "http://www.springframework.org/schema/mvc" xsi:schemalocation = " http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/ <MVC:CORS> <MVC:マッピングPATH = "/**" Aldoct-Origins = "" post、get、options、delete、put "//ヘッダーのユーザー名とパスワードは、プロジェクトのニーズのためにカスタムリクエストヘッダーの内容です。 Aldument-headers = "Origin、x-mx-reqtoken、x-requested-with、password、authorization、Accepont、content-type" Allow-credentials = "true"/>> </mvc:cors> </beans>
これがアノテーションを追加するコントローラーレイヤーのスクリーンショットです
春4.3でクロスドメインCORを実装する上記の方法は、私があなたと共有するすべてのコンテンツです。参照を提供できることを願っています。wulin.comをもっとサポートできることを願っています。