diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 4ce4acd..5875f50 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -11,6 +11,7 @@ + diff --git a/.idea/encodings.xml b/.idea/encodings.xml index 50deeda..9076776 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -21,5 +21,7 @@ + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 6a8bc54..e289113 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,6 +3,7 @@ + diff --git a/springmvc-01-523/pom.xml b/springmvc-01-523/pom.xml new file mode 100644 index 0000000..99f8b99 --- /dev/null +++ b/springmvc-01-523/pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + + org.example + springmvc-01-523 + 1.0-SNAPSHOT + war + + + 11 + 11 + UTF-8 + + + + + org.springframework + spring-context + 5.0.3.RELEASE + + + + org.springframework + spring-webmvc + 5.0.3.RELEASE + + + org.springframework + spring-web + 5.0.3.RELEASE + + + javax.servlet + javax.servlet-api + 3.0.1 + provided + + + javax.servlet + jsp-api + 2.0 + provided + + + jstl + jstl + 1.2 + + + junit + junit + 4.12 + + + + \ No newline at end of file diff --git a/springmvc-01-523/src/main/java/cn/czyx007/mvc/controller/MyController.java b/springmvc-01-523/src/main/java/cn/czyx007/mvc/controller/MyController.java new file mode 100644 index 0000000..dcf073c --- /dev/null +++ b/springmvc-01-523/src/main/java/cn/czyx007/mvc/controller/MyController.java @@ -0,0 +1,29 @@ +package cn.czyx007.mvc.controller; + +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.mvc.Controller; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * @author : 张宇轩 + * @createTime : 2023/5/23 - 10:33 + */ +public class MyController implements Controller { + @Override + public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { + //接收器群 + System.out.println("成功接收到请求"); + //处理请求-不处理-将来要处理 + System.out.println("处理请求...不处理-将来要处理"); + //返回响应 + //ModelAndView封装数据和视图 + ModelAndView modelAndView = new ModelAndView(); + //1.封装数据 + modelAndView.addObject("userName", "abc"); + //2.封装视图 + modelAndView.setViewName("WEB-INF/jsp/index.jsp"); + return modelAndView; + } +} diff --git a/springmvc-01-523/src/main/java/cn/czyx007/mvc/controller/UserController.java b/springmvc-01-523/src/main/java/cn/czyx007/mvc/controller/UserController.java new file mode 100644 index 0000000..67b41a6 --- /dev/null +++ b/springmvc-01-523/src/main/java/cn/czyx007/mvc/controller/UserController.java @@ -0,0 +1,28 @@ +package cn.czyx007.mvc.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.servlet.ModelAndView; + +/** + * @author : 张宇轩 + * @createTime : 2023/5/23 - 11:40 + */ +@Controller +public class UserController { + @RequestMapping("/user") + public ModelAndView showUser(){ + //接收器群 + System.out.println("成功接收到请求"); + //处理请求-不处理-将来要处理 + System.out.println("处理请求...不处理-将来要处理"); + //返回响应 + //ModelAndView封装数据和视图 + ModelAndView modelAndView = new ModelAndView(); + //1.封装数据 + modelAndView.addObject("userName", "blue"); + //2.封装视图 + modelAndView.setViewName("WEB-INF/jsp/index.jsp"); + return modelAndView; + } +} diff --git a/springmvc-01-523/src/main/resources/springmvc.xml b/springmvc-01-523/src/main/resources/springmvc.xml new file mode 100644 index 0000000..0855495 --- /dev/null +++ b/springmvc-01-523/src/main/resources/springmvc.xml @@ -0,0 +1,19 @@ + + + + + + + + + + \ No newline at end of file diff --git a/springmvc-01-523/src/main/webapp/WEB-INF/jsp/index.jsp b/springmvc-01-523/src/main/webapp/WEB-INF/jsp/index.jsp new file mode 100644 index 0000000..4687cfc --- /dev/null +++ b/springmvc-01-523/src/main/webapp/WEB-INF/jsp/index.jsp @@ -0,0 +1,17 @@ +<%-- + Created by IntelliJ IDEA. + User: zyx + Date: 2023/5/23 + Time: 10:38 + To change this template use File | Settings | File Templates. +--%> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + Title + + +<%--el表达式--%> + ${userName} + + diff --git a/springmvc-01-523/src/main/webapp/WEB-INF/web.xml b/springmvc-01-523/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..189476f --- /dev/null +++ b/springmvc-01-523/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,26 @@ + + + + + dispatcherServlet + org.springframework.web.servlet.DispatcherServlet + + + contextConfigLocation + classpath:springmvc.xml + + + 1 + + + dispatcherServlet + + + + / + + + \ No newline at end of file diff --git a/springmvc-01-523/src/main/webapp/index.html b/springmvc-01-523/src/main/webapp/index.html new file mode 100644 index 0000000..09b8bc8 --- /dev/null +++ b/springmvc-01-523/src/main/webapp/index.html @@ -0,0 +1,10 @@ + + + + + Title + + +

hello, springmvc!

+ + \ No newline at end of file