From 91e539f40b48b63149bfb37f22ebb9164320ad8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E5=8E=9A=E8=BE=B0?= <7964342+zha_cai@user.noreply.gitee.com> Date: Wed, 3 Jan 2024 04:43:42 +0000 Subject: [PATCH 1/2] =?UTF-8?q?add=2053=20=E5=91=A8=E5=8E=9A=E8=BE=B0/2024?= =?UTF-8?q?0102=20MVCSpring.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 周厚辰 <7964342+zha_cai@user.noreply.gitee.com> --- .../20240102 MVCSpring" | 183 ++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 "53 \345\221\250\345\216\232\350\276\260/20240102 MVCSpring" diff --git "a/53 \345\221\250\345\216\232\350\276\260/20240102 MVCSpring" "b/53 \345\221\250\345\216\232\350\276\260/20240102 MVCSpring" new file mode 100644 index 0000000..1c772de --- /dev/null +++ "b/53 \345\221\250\345\216\232\350\276\260/20240102 MVCSpring" @@ -0,0 +1,183 @@ +## 笔记 + +名称:@ComponentScan + +类型:类注解 + +属性 + +excludeFilters:排除扫描路径中加载的bean,需要指定类别(type)与具体项(classes) + +includeFilters:加载指定的bean,需要指定类别(type)与具体项(classes) + +名称:@RequestParam + +类型:形参注解 + +位置:SpringMVC控制器方法形参定义前面 + +作用:绑定请求参数与处理器方法形参间的关系 + +参数: + +required:是否为必传参数 + +defaultValue:参数默认值 + +名称:@EnableWebMvc + +类型:配置类注解 + +位置:SpringMVC配置类定义上方 + +作用:开启SpringMVC多项辅助功能 + +## 作业 + +步骤; + +1.pom.xml,将没有的东西复原,如java,test。。。 + +```xml + + 4.0.0 + com.xlu + ssmvc + war + 1.0-SNAPSHOT + + + + javax.servlet + javax.servlet-api + 3.1.0 + provided + + + + org.springframework + spring-webmvc + 5.2.25.RELEASE + + + + + + + + + + + org.apache.tomcat.maven + tomcat7-maven-plugin + 2.2 + + 88 + / + + + + + + + +``` + +2.创建com.xlu.config.SpringMvcConfig + +```java +package com.xlu.config; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ComponentScan("com.xlu") +public class SpringMvcConfig { +} +``` + +3.com.xlu.config.WeblnitConfig + +```java +package com.xlu.config; + +import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; + +public class WeblnitConfig extends AbstractAnnotationConfigDispatcherServletInitializer { + + + protected Class[] getRootConfigClasses() { + return new Class[0];//加载spring的核心配置文件 + } + + protected Class[] getServletConfigClasses() { + //加载springmvc的核心配置文件 + return new Class[]{SpringMvcConfig.class}; + } + + protected String[] getServletMappings() { + //设置从/开始的路径,都归tomcat管理 + return new String[]{"/"}; + } +} +``` + +4.com.xlu.controller.UserController + +```java +package com.xlu.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.xml.ws.RequestWrapper; +import java.security.PublicKey; + +@Controller +public class UserController { + + + @RequestMapping("/save") + @ResponseBody + public String userSave(){ + + return "ok";//http://localhost:88/save网址,查看是否出现OK + + } + + @RequestMapping("/book") + @ResponseBody + public String book(){ + return "book is ok!";//http://localhost:88/book网址,查看是否有东西 + } + + + @RequestMapping("/hello") + @ResponseBody + public String hello(){ + + System.out.println(666); + return "666";//http://localhost:88/hello网址,查看是否有东西 + + } + +// @RequestMapping("/shouYe") +// public String shouYe(){ +// +// return "index.jsp";//http://localhost:88/shouYe网址,跳转网页出现 helloword +// } + + @RequestMapping("/shouYe") + @ResponseBody + public String shouYe(){ + + return "index.jsp";//http://localhost:88/shouYe网址,出现index.jsp + } + + +} +``` + -- Gitee From 575b10d08fbc5549e9e5a7cefb505ef6069549dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E5=8E=9A=E8=BE=B0?= <7964342+zha_cai@user.noreply.gitee.com> Date: Wed, 3 Jan 2024 04:43:59 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=E9=87=8D=E5=91=BD=E5=90=8D=2053=20?= =?UTF-8?q?=E5=91=A8=E5=8E=9A=E8=BE=B0/20240102=20MVCSpring=20=E4=B8=BA=20?= =?UTF-8?q?53=20=E5=91=A8=E5=8E=9A=E8=BE=B0/20240102=20MVCSpring.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20240102 MVCSpring.md" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "53 \345\221\250\345\216\232\350\276\260/20240102 MVCSpring" => "53 \345\221\250\345\216\232\350\276\260/20240102 MVCSpring.md" (100%) diff --git "a/53 \345\221\250\345\216\232\350\276\260/20240102 MVCSpring" "b/53 \345\221\250\345\216\232\350\276\260/20240102 MVCSpring.md" similarity index 100% rename from "53 \345\221\250\345\216\232\350\276\260/20240102 MVCSpring" rename to "53 \345\221\250\345\216\232\350\276\260/20240102 MVCSpring.md" -- Gitee