From f12b88ea9c6559d463ca9136cffcd86e8851a40b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E9=9C=96=E9=BA=92?= Date: Fri, 30 Oct 2026 09:46:34 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9D=99=E6=80=81=E8=B5=84=E6=BA=90=E5=A4=84?= =?UTF-8?q?=E7=90=862?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Spring-ch14-staticAndCORS/pom.xml | 21 +++++++++++++++++++ .../main/java/com/ycjy/config/AppConfig.java | 2 +- .../main/java/com/ycjy/config/WebConfig.java | 16 ++++++++++---- .../src/test/java/corsTest/index.html | 17 +++++++++++++++ Spring-ch14-staticAndCORS/web/WEB-INF/web.xml | 6 ++++++ Spring-ch14-staticAndCORS/web/static/test.txt | 1 + 6 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 Spring-ch14-staticAndCORS/src/test/java/corsTest/index.html create mode 100644 Spring-ch14-staticAndCORS/web/WEB-INF/web.xml create mode 100644 Spring-ch14-staticAndCORS/web/static/test.txt diff --git a/Spring-ch14-staticAndCORS/pom.xml b/Spring-ch14-staticAndCORS/pom.xml index 8907719..e35ea8a 100644 --- a/Spring-ch14-staticAndCORS/pom.xml +++ b/Spring-ch14-staticAndCORS/pom.xml @@ -31,4 +31,25 @@ hibernate-validator + + + + + org.apache.maven.plugins + maven-war-plugin + + ${basedir}/web + + + + org.apache.maven.plugins + maven-compiler-plugin + + 21 + 21 + --enable-preview + + + + \ No newline at end of file diff --git a/Spring-ch14-staticAndCORS/src/main/java/com/ycjy/config/AppConfig.java b/Spring-ch14-staticAndCORS/src/main/java/com/ycjy/config/AppConfig.java index 53bed73..9c5ee79 100644 --- a/Spring-ch14-staticAndCORS/src/main/java/com/ycjy/config/AppConfig.java +++ b/Spring-ch14-staticAndCORS/src/main/java/com/ycjy/config/AppConfig.java @@ -8,4 +8,4 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc; @EnableWebMvc @ComponentScan({"com.ycjy.web"}) public class AppConfig { -} +} \ No newline at end of file diff --git a/Spring-ch14-staticAndCORS/src/main/java/com/ycjy/config/WebConfig.java b/Spring-ch14-staticAndCORS/src/main/java/com/ycjy/config/WebConfig.java index ca3621d..d9a691f 100644 --- a/Spring-ch14-staticAndCORS/src/main/java/com/ycjy/config/WebConfig.java +++ b/Spring-ch14-staticAndCORS/src/main/java/com/ycjy/config/WebConfig.java @@ -1,14 +1,22 @@ package com.ycjy.config; import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration public class WebConfig implements WebMvcConfigurer { +// @Override +// public void addResourceHandlers(ResourceHandlerRegistry registry) { +// registry.addResourceHandler("/static/**") +// .addResourceLocations("/static/","classpath:/static/"); +// } + + + // webappçš„ @Override - public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry.addResourceHandler("/static/**") - .addResourceLocations("/static/","classpath:/static/"); + public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { + configurer.enable(); } -} +} \ No newline at end of file diff --git a/Spring-ch14-staticAndCORS/src/test/java/corsTest/index.html b/Spring-ch14-staticAndCORS/src/test/java/corsTest/index.html new file mode 100644 index 0000000..28d11a0 --- /dev/null +++ b/Spring-ch14-staticAndCORS/src/test/java/corsTest/index.html @@ -0,0 +1,17 @@ + + + + + + Document + + + + + + \ No newline at end of file diff --git a/Spring-ch14-staticAndCORS/web/WEB-INF/web.xml b/Spring-ch14-staticAndCORS/web/WEB-INF/web.xml new file mode 100644 index 0000000..d80081d --- /dev/null +++ b/Spring-ch14-staticAndCORS/web/WEB-INF/web.xml @@ -0,0 +1,6 @@ + + + \ No newline at end of file diff --git a/Spring-ch14-staticAndCORS/web/static/test.txt b/Spring-ch14-staticAndCORS/web/static/test.txt new file mode 100644 index 0000000..9d07aa0 --- /dev/null +++ b/Spring-ch14-staticAndCORS/web/static/test.txt @@ -0,0 +1 @@ +111 \ No newline at end of file