From 15aab95f2cdb12d60311a7e1a6d9a58c26666cbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=8F=AD=E9=98=B3=E4=B8=BD?= <2431466589@qq.com> Date: Thu, 4 Jan 2024 11:50:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20230103 \344\275\234\344\270\232.txt" | 147 ++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 "37 \346\217\255\351\230\263\344\270\275/20230103 \344\275\234\344\270\232.txt" diff --git "a/37 \346\217\255\351\230\263\344\270\275/20230103 \344\275\234\344\270\232.txt" "b/37 \346\217\255\351\230\263\344\270\275/20230103 \344\275\234\344\270\232.txt" new file mode 100644 index 0000000..63e6769 --- /dev/null +++ "b/37 \346\217\255\351\230\263\344\270\275/20230103 \344\275\234\344\270\232.txt" @@ -0,0 +1,147 @@ +## 作业 + +步骤; + +1.pom.xml,将没有的东西复原,如java,test + +```js + + 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 + +```js +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 + +```js +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 + +```js +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 + } + + +} +``` \ No newline at end of file -- Gitee