guyanqing пре 1 година
родитељ
комит
5a118aa00b
27 измењених фајлова са 321 додато и 112 уклоњено
  1. 17 1
      04maven/spring/.idea/workspace.xml
  2. 12 11
      springmvc/.idea/workspace.xml
  3. 8 0
      springmvc/pom.xml
  4. 103 1
      springmvc/src/main/java/com/sf/conroller/BookController.java
  5. 18 0
      springmvc/src/main/java/com/sf/conroller/CommonException.java
  6. 0 94
      springmvc/src/main/java/com/sf/conroller/HelloController.java
  7. 26 0
      springmvc/src/main/java/com/sf/conroller/myHandlerInterceptor.java
  8. 26 1
      springmvc/src/main/webapp/WEB-INF/dispatcherServlet-servlet.xml
  9. 17 0
      springmvc/src/main/webapp/WEB-INF/views/error.jsp
  10. 24 0
      springmvc/src/main/webapp/index.jsp
  11. BIN
      springmvc/target/classes/com/sf/conroller/BookController.class
  12. BIN
      springmvc/target/classes/com/sf/conroller/CommonException.class
  13. BIN
      springmvc/target/classes/com/sf/conroller/HelloController.class
  14. BIN
      springmvc/target/classes/com/sf/conroller/myHandlerInterceptor.class
  15. BIN
      springmvc/target/springmvc.war
  16. BIN
      springmvc/target/springmvc/WEB-INF/classes/com/sf/conroller/BookController.class
  17. BIN
      springmvc/target/springmvc/WEB-INF/classes/com/sf/conroller/CommonException.class
  18. BIN
      springmvc/target/springmvc/WEB-INF/classes/com/sf/conroller/HelloController.class
  19. BIN
      springmvc/target/springmvc/WEB-INF/classes/com/sf/conroller/myHandlerInterceptor.class
  20. 26 1
      springmvc/target/springmvc/WEB-INF/dispatcherServlet-servlet.xml
  21. BIN
      springmvc/target/springmvc/WEB-INF/lib/jackson-annotations-2.9.8.jar
  22. BIN
      springmvc/target/springmvc/WEB-INF/lib/jackson-core-2.9.0.jar
  23. BIN
      springmvc/target/springmvc/WEB-INF/lib/jackson-core-2.9.8.jar
  24. BIN
      springmvc/target/springmvc/WEB-INF/lib/jackson-databind-2.9.0.jar
  25. BIN
      springmvc/target/springmvc/WEB-INF/lib/jackson-databind-2.9.8.jar
  26. 17 0
      springmvc/target/springmvc/WEB-INF/views/error.jsp
  27. 27 3
      springmvc/target/springmvc/index.jsp

+ 17 - 1
04maven/spring/.idea/workspace.xml

@@ -5,8 +5,22 @@
   </component>
   <component name="ChangeListManager">
     <list default="true" id="8c3e0ed0-6141-4ee9-a284-3fa2d43ee5eb" name="Changes" comment="">
+      <change afterPath="$PROJECT_DIR$/../../springmvc/src/main/java/com/sf/conroller/CommonException.java" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/../../springmvc/src/main/webapp/WEB-INF/views/error.jsp" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/../../springmvc/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../../springmvc/.idea/workspace.xml" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/../../springmvc/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../../springmvc/pom.xml" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/../../springmvc/src/main/java/com/sf/conroller/BookController.java" beforeDir="false" afterPath="$PROJECT_DIR$/../../springmvc/src/main/java/com/sf/conroller/BookController.java" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/../../springmvc/src/main/java/com/sf/conroller/HelloController.java" beforeDir="false" />
+      <change beforePath="$PROJECT_DIR$/../../springmvc/src/main/webapp/WEB-INF/dispatcherServlet-servlet.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../../springmvc/src/main/webapp/WEB-INF/dispatcherServlet-servlet.xml" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/../../springmvc/src/main/webapp/index.jsp" beforeDir="false" afterPath="$PROJECT_DIR$/../../springmvc/src/main/webapp/index.jsp" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/../../springmvc/target/classes/com/sf/conroller/BookController.class" beforeDir="false" afterPath="$PROJECT_DIR$/../../springmvc/target/classes/com/sf/conroller/BookController.class" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/../../springmvc/target/classes/com/sf/conroller/HelloController.class" beforeDir="false" />
+      <change beforePath="$PROJECT_DIR$/../../springmvc/target/springmvc.war" beforeDir="false" afterPath="$PROJECT_DIR$/../../springmvc/target/springmvc.war" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/../../springmvc/target/springmvc/WEB-INF/classes/com/sf/conroller/BookController.class" beforeDir="false" afterPath="$PROJECT_DIR$/../../springmvc/target/springmvc/WEB-INF/classes/com/sf/conroller/BookController.class" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/../../springmvc/target/springmvc/WEB-INF/classes/com/sf/conroller/HelloController.class" beforeDir="false" />
+      <change beforePath="$PROJECT_DIR$/../../springmvc/target/springmvc/WEB-INF/dispatcherServlet-servlet.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../../springmvc/target/springmvc/WEB-INF/dispatcherServlet-servlet.xml" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/../../springmvc/target/springmvc/index.jsp" beforeDir="false" afterPath="$PROJECT_DIR$/../../springmvc/target/springmvc/index.jsp" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />
     <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -49,7 +63,8 @@
     "project.structure.last.edited": "Modules",
     "project.structure.proportion": "0.15",
     "project.structure.side.proportion": "0.13333334",
-    "settings.editor.selected.configurable": "preferences.fileTypes",
+    "settings.editor.selected.configurable": "editor.preferences.fonts.default",
+    "spring.configuration.checksum": "2a2d595e6ed9a0b24f027f2b63b134d6",
     "vue.rearranger.settings.migration": "true"
   }
 }]]></component>
@@ -153,6 +168,7 @@
       <option name="presentableId" value="Default" />
       <updated>1689993904831</updated>
       <workItem from="1689993906819" duration="76525000" />
+      <workItem from="1690702886400" duration="792000" />
     </task>
     <servers />
   </component>

+ 12 - 11
springmvc/.idea/workspace.xml

@@ -10,21 +10,22 @@
   </component>
   <component name="ChangeListManager">
     <list default="true" id="32ba8696-e546-42f9-8a17-6935ed145529" name="Changes" comment="">
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/conroller/Author.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/conroller/Book.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/conroller/BookController.java" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/conroller/CommonException.java" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/conroller/myHandlerInterceptor.java" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/src/main/webapp/WEB-INF/views/error.jsp" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/../04maven/spring/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../04maven/spring/.idea/workspace.xml" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/src/main/java/com/sf/conroller/HelloController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/sf/conroller/HelloController.java" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/src/main/webapp/WEB-INF/views/result.jsp" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/webapp/WEB-INF/views/result.jsp" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/src/main/webapp/WEB-INF/web.xml" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/webapp/WEB-INF/web.xml" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/main/java/com/sf/conroller/BookController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/sf/conroller/BookController.java" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/main/java/com/sf/conroller/HelloController.java" beforeDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/main/webapp/WEB-INF/dispatcherServlet-servlet.xml" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/webapp/WEB-INF/dispatcherServlet-servlet.xml" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/src/main/webapp/index.jsp" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/webapp/index.jsp" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/target/classes/com/sf/conroller/HelloController.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/com/sf/conroller/HelloController.class" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/target/classes/com/sf/conroller/BookController.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/com/sf/conroller/BookController.class" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/target/classes/com/sf/conroller/HelloController.class" beforeDir="false" />
       <change beforePath="$PROJECT_DIR$/target/springmvc.war" beforeDir="false" afterPath="$PROJECT_DIR$/target/springmvc.war" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/target/springmvc/WEB-INF/classes/com/sf/conroller/HelloController.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/springmvc/WEB-INF/classes/com/sf/conroller/HelloController.class" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/target/springmvc/WEB-INF/views/result.jsp" beforeDir="false" afterPath="$PROJECT_DIR$/target/springmvc/WEB-INF/views/result.jsp" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/target/springmvc/WEB-INF/web.xml" beforeDir="false" afterPath="$PROJECT_DIR$/target/springmvc/WEB-INF/web.xml" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/target/springmvc/WEB-INF/classes/com/sf/conroller/BookController.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/springmvc/WEB-INF/classes/com/sf/conroller/BookController.class" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/target/springmvc/WEB-INF/classes/com/sf/conroller/HelloController.class" beforeDir="false" />
+      <change beforePath="$PROJECT_DIR$/target/springmvc/WEB-INF/dispatcherServlet-servlet.xml" beforeDir="false" afterPath="$PROJECT_DIR$/target/springmvc/WEB-INF/dispatcherServlet-servlet.xml" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/target/springmvc/index.jsp" beforeDir="false" afterPath="$PROJECT_DIR$/target/springmvc/index.jsp" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />
@@ -169,7 +170,7 @@
       <option name="presentableId" value="Default" />
       <updated>1690439501381</updated>
       <workItem from="1690439502870" duration="24084000" />
-      <workItem from="1690525438535" duration="4759000" />
+      <workItem from="1690525438535" duration="31674000" />
     </task>
     <servers />
   </component>

+ 8 - 0
springmvc/pom.xml

@@ -53,6 +53,14 @@
       <scope>provided</scope>
     </dependency>
 
+<!--    文件上传
+-->
+    <dependency>
+      <groupId>commons-fileupload</groupId>
+      <artifactId>commons-fileupload</artifactId>
+      <version>1.3.3</version>
+    </dependency>
+
   </dependencies>
 
 

+ 103 - 1
springmvc/src/main/java/com/sf/conroller/BookController.java

@@ -1,14 +1,21 @@
 package com.sf.conroller;
 
+import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
 import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.ExceptionHandler;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.servlet.ModelAndView;
 
 import javax.servlet.http.HttpServletRequest;
+import java.io.*;
+import java.net.URLEncoder;
 import java.util.Map;
 
 @Controller
@@ -102,7 +109,102 @@ public class BookController {
     @RequestMapping(value = "/testMap")
     public String testMap(Map map){
         /*向域对象中存数据*/
-        map.put("userName","李雷Map");
+        map.put("userName","李雷");
         return "result";
     }
+
+    /**
+     * 测试转发和重定向
+     * @return
+     */
+
+    @RequestMapping(value = "/testRedirect",method = RequestMethod.GET)
+    public String testRedirect(){
+        System.out.println("测试重定向处理.....");
+        /*
+         *   redirect: 这是springmvc转发的关键字
+         *   默认情况下返回值为String类型时,返回值为视图名称
+         *   如果返回值以redirect作为前缀,那么redirect后面的变为请求地址
+         * */
+        return "redirect:ok";
+    }
+
+
+
+
+    @RequestMapping(value = "/testforward",method = RequestMethod.GET)
+    public String testforward(){
+        System.out.println("测试转发求处理.....");
+        /*
+         *   forward: 这是springmvc转发的关键字
+         *   默认情况下返回值为String类型时,返回值为视图名称
+         *   如果返回值以forward作为前缀,那么forward后面的变为请求地址
+         * */
+        return "forward:ok";
+    }
+
+    @RequestMapping(value = "/ok",method = RequestMethod.GET)
+    public String ok(){
+        System.out.println("ok.....");
+        return "result";
+    }
+
+
+    /**
+     * w文件上传
+     */
+    @RequestMapping(value="/uploadFile")
+    public String uploadFile(@RequestParam("file") MultipartFile[] multipartFiles) throws IOException {
+//        iter
+        for (MultipartFile multipartFile : multipartFiles) {
+            if(!multipartFile.isEmpty()){
+//                文件上传的方法
+                multipartFile.transferTo(new File("D:\\"+multipartFile.getOriginalFilename()));
+            }
+        }
+        return "result";
+    }
+
+
+    /**
+     * 文件下载
+     * @return
+     */
+  @RequestMapping("/downloadFile")
+    public ResponseEntity<byte[]> downloadFile() throws IOException {
+//      确定文件位置
+      File file = new File("D://123.jpg");
+//      将要下载的文件变成输入流
+      FileInputStream fileInputStream = new FileInputStream(file);
+      //将输入流读到缓冲区
+      BufferedInputStream in = new BufferedInputStream(fileInputStream);
+      //创建按byte[] 的大小
+      byte[] body =  new byte[in.available()];
+      in.read(body); //将输入流读到缓冲区
+      //文件名
+      String fileName="123.jpg";
+      //当文件名为中文时需要进行编码,否则会出现中文乱码
+      fileName= URLEncoder.encode(fileName, "UTF-8");
+      HttpHeaders header = new HttpHeaders();
+      //inline: 直接显示
+      //header.add("Content-Disposition", "inline;filename="+fileName);
+      //附件下载
+      header.add("Content-Disposition", "attachment;filename=123.jpg");
+      ResponseEntity<byte[]> result = new ResponseEntity<>(body,header,HttpStatus.OK);
+      in.close();
+      return result;
+  }
+
+//    /**
+//     * 单个异常处理
+//     */
+//    @ExceptionHandler(value = {Exception.class})
+//    public ModelAndView testException(Exception e){
+//        System.out.println("error--->"+e.getMessage());
+//        ModelAndView modelAndView = new ModelAndView();
+//        modelAndView.setViewName("error");
+//        modelAndView.addObject("msg",e.getMessage());
+//        return modelAndView;
+//    }
+
 }

+ 18 - 0
springmvc/src/main/java/com/sf/conroller/CommonException.java

@@ -0,0 +1,18 @@
+package com.sf.conroller;
+
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.servlet.ModelAndView;
+
+@ControllerAdvice
+public class CommonException {
+
+    @ExceptionHandler(value = {Exception.class})
+    public ModelAndView testException(Exception e){
+        System.out.println("error--->"+e.getMessage());
+        ModelAndView modelAndView = new ModelAndView();
+        modelAndView.setViewName("error");
+        modelAndView.addObject("msg",e.getMessage());
+        return modelAndView;
+    }
+}

+ 0 - 94
springmvc/src/main/java/com/sf/conroller/HelloController.java

@@ -1,94 +0,0 @@
-package com.sf.conroller;
-
-import org.springframework.beans.propertyeditors.CustomDateEditor;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.WebDataBinder;
-import org.springframework.web.bind.annotation.*;
-
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-@Controller
-public class HelloController {
-
-
-    /**
-     * string : "result":视图的名称
-     * @return
-     * 200:成功
-     * 400/404:找不到  前端发送一个请求后端服务器没有对应的映射地址
-     * 500:后端服务器错误
-     * 405:方法不允许   --  Request method 'GET' not supported
-     *
-     */
-    @RequestMapping(value = "/hello",method = RequestMethod.GET)
-    public String hello(){
-        System.out.println("hello");
-        return "result";
-    }
-
-
-    /**
-     * 测试  @PathVariable注解的数据绑定
-     *
-     * @param id
-     * @return
-     */
-    @RequestMapping(value = "/testPathVariable/{id}",method = RequestMethod.GET)
-    public String testPathVariable(@PathVariable("id") Integer id){
-        System.out.println("testPathVariable.....");
-        System.out.println(id);
-        return "result";
-    }
-
-    /**
-     * 测试拼接方式get请求的数据绑定
-     * @return
-     */
-    @RequestMapping(value = "/testGet",method = RequestMethod.GET)
-    public String testGet(Integer id ,Integer name){
-        System.out.println(id);
-        System.out.println(name);
-        return "result";
-    }
-
-
-    /**
-     * id=1001&id=1002
-     * @return
-     */
-    @RequestMapping(value = "testArray",method = RequestMethod.GET)
-    public String testArray(int[] id){
-        System.out.println("testArray...");
-        for (int i : id) {
-            System.out.println(i);
-        }
-        return "result";
-    }
-
-    /**
-     * 测试  @PathVariable注解的多数据绑定
-     * @return
-     */
-    @RequestMapping(value = "/testPathVariable2/{id}/{name}",method = RequestMethod.GET)
-    public String testPathVariable2(@PathVariable("id") Integer id,@PathVariable("name") String name){
-        System.out.println(id);
-        System.out.println(name);
-        return "result";
-    }
-
-
-    /**
-     * 测试嵌套数据绑定
-     * @param book
-     * @return
-     */
-
-    @RequestMapping(value = "/testBook",method = RequestMethod.POST)
-    public String testBook(Book  book){
-        System.out.println(book);
-        return "result";
-    }
-
-
-}

+ 26 - 0
springmvc/src/main/java/com/sf/conroller/myHandlerInterceptor.java

@@ -0,0 +1,26 @@
+package com.sf.conroller;
+
+import org.springframework.web.servlet.HandlerInterceptor;
+import org.springframework.web.servlet.ModelAndView;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public class myHandlerInterceptor implements HandlerInterceptor {
+    @Override
+    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
+        //程序调用此拦截器之后还需要继续执行,那么返回true否则返回false
+        System.out.println("preHandle...");
+        return true;
+    }
+
+    @Override
+    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
+        System.out.println("postHandle....");
+    }
+
+    @Override
+    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
+        System.out.println("afterCompletion...");
+    }
+}

+ 26 - 1
springmvc/src/main/webapp/WEB-INF/dispatcherServlet-servlet.xml

@@ -2,7 +2,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"
-       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
+       xmlns:mvc="http://www.springframework.org/schema/mvc"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">
 
 
     <!--配置扫描的包-->
@@ -15,4 +16,28 @@
         <!--        后缀-->
         <property name="suffix" value=".jsp"></property>
     </bean>
+
+<!--    id不能随便指定,必须是multipartResolver-->
+    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
+<!--        默认字符集 utf-8-->
+        <property name="defaultEncoding" value="UTF-8"></property>
+<!--        通过spel表达式设置文件上传的大小   -1不限制-->
+        <property name="maxUploadSize" value="#{1024*1024}"></property>
+    </bean>
+
+<!--    添加注解驱动 注意导以mvc结尾的包-->
+    <mvc:annotation-driven></mvc:annotation-driven>
+
+<!--    配置全局拦截器-->
+<!--    <mvc:interceptors>-->
+<!--        <bean id="myHandlerInterceptor" class="com.sf.conroller.myHandlerInterceptor"></bean>-->
+<!--    </mvc:interceptors>-->
+    
+<!--    配置拦截一个请求-->
+    <mvc:interceptors>
+        <mvc:interceptor>
+            <mvc:mapping path="/book/getBook"/>
+            <bean class="com.sf.conroller.myHandlerInterceptor"></bean>
+        </mvc:interceptor>
+    </mvc:interceptors>
 </beans>

+ 17 - 0
springmvc/src/main/webapp/WEB-INF/views/error.jsp

@@ -0,0 +1,17 @@
+<%--
+  Created by IntelliJ IDEA.
+  User: Lenovo
+  Date: 2023/7/30
+  Time: 15:18
+  To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<html>
+<head>
+    <title>Title</title>
+</head>
+<body>
+<h1>error</h1>
+${msg}
+</body>
+</html>

+ 24 - 0
springmvc/src/main/webapp/index.jsp

@@ -79,4 +79,28 @@
 <%--测试model数据模型传递--%>
 <a href="${pageContext.request.contextPath}/book/testMap">testMapp</a>
 </body>
+
+<form action="${pageContext.request.contextPath}/book/testRedirect" method="post">
+    <input type="submit" value="测试重定向提交">
+</form>
+
+<br>
+<a href="${pageContext.request.contextPath}/book/testRedirect">测试重定向</a>
+
+<br>
+<form action="${pageContext.request.contextPath}/book/testforward" method="post">
+    <input type="submit" value="测试转发提交">
+</form>
+
+<br>
+<a href="${pageContext.request.contextPath}/book/testforward">get-转发</a>
+
+<%--测试文件上传  enctype="multipart/form-data--%>
+<form action="${pageContext.request.contextPath}/book/uploadFile" method="post" enctype="multipart/form-data">
+    <input type="file" name="file">
+    <input type="submit" value="文件上传提交">
+</form>
+
+<%--文件下载--%>
+<a href="${pageContext.request.contextPath}/book/downloadFile">文件下载</a>
 </html>

BIN
springmvc/target/classes/com/sf/conroller/BookController.class


BIN
springmvc/target/classes/com/sf/conroller/CommonException.class


BIN
springmvc/target/classes/com/sf/conroller/HelloController.class


BIN
springmvc/target/classes/com/sf/conroller/myHandlerInterceptor.class


BIN
springmvc/target/springmvc.war


BIN
springmvc/target/springmvc/WEB-INF/classes/com/sf/conroller/BookController.class


BIN
springmvc/target/springmvc/WEB-INF/classes/com/sf/conroller/CommonException.class


BIN
springmvc/target/springmvc/WEB-INF/classes/com/sf/conroller/HelloController.class


BIN
springmvc/target/springmvc/WEB-INF/classes/com/sf/conroller/myHandlerInterceptor.class


+ 26 - 1
springmvc/target/springmvc/WEB-INF/dispatcherServlet-servlet.xml

@@ -2,7 +2,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"
-       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
+       xmlns:mvc="http://www.springframework.org/schema/mvc"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">
 
 
     <!--配置扫描的包-->
@@ -15,4 +16,28 @@
         <!--        后缀-->
         <property name="suffix" value=".jsp"></property>
     </bean>
+
+<!--    id不能随便指定,必须是multipartResolver-->
+    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
+<!--        默认字符集 utf-8-->
+        <property name="defaultEncoding" value="UTF-8"></property>
+<!--        通过spel表达式设置文件上传的大小   -1不限制-->
+        <property name="maxUploadSize" value="#{1024*1024}"></property>
+    </bean>
+
+<!--    添加注解驱动 注意导以mvc结尾的包-->
+    <mvc:annotation-driven></mvc:annotation-driven>
+
+<!--    配置全局拦截器-->
+<!--    <mvc:interceptors>-->
+<!--        <bean id="myHandlerInterceptor" class="com.sf.conroller.myHandlerInterceptor"></bean>-->
+<!--    </mvc:interceptors>-->
+    
+<!--    配置拦截一个请求-->
+    <mvc:interceptors>
+        <mvc:interceptor>
+            <mvc:mapping path="/book/getBook1"/>
+            <bean class="com.sf.conroller.myHandlerInterceptor"></bean>
+        </mvc:interceptor>
+    </mvc:interceptors>
 </beans>

BIN
springmvc/target/springmvc/WEB-INF/lib/jackson-annotations-2.9.8.jar


BIN
springmvc/target/springmvc/WEB-INF/lib/jackson-core-2.9.0.jar


BIN
springmvc/target/springmvc/WEB-INF/lib/jackson-core-2.9.8.jar


BIN
springmvc/target/springmvc/WEB-INF/lib/jackson-databind-2.9.0.jar


BIN
springmvc/target/springmvc/WEB-INF/lib/jackson-databind-2.9.8.jar


+ 17 - 0
springmvc/target/springmvc/WEB-INF/views/error.jsp

@@ -0,0 +1,17 @@
+<%--
+  Created by IntelliJ IDEA.
+  User: Lenovo
+  Date: 2023/7/30
+  Time: 15:18
+  To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<html>
+<head>
+    <title>Title</title>
+</head>
+<body>
+<h1>error</h1>
+${msg}
+</body>
+</html>

+ 27 - 3
springmvc/target/springmvc/index.jsp

@@ -70,13 +70,37 @@
 <a href="${pageContext.request.contextPath}/book/testModelAndView">testModelAndView</a>
 <br>
 <%--测试model数据模型传递--%>
-<a href="/book/testModel">testModel</a>
+<a href="${pageContext.request.contextPath}/book/testModel">testModel</a>
 
 
 <%--测试model数据模型传递--%>
-<a href="/book/testModelMap">testModelMap</a>
+<a href="${pageContext.request.contextPath}/book/testModelMap">testModelMap</a>
 
 <%--测试model数据模型传递--%>
-<a href="/book/testMap">testMapp</a>
+<a href="${pageContext.request.contextPath}/book/testMap">testMapp</a>
 </body>
+
+<form action="${pageContext.request.contextPath}/book/testRedirect" method="post">
+    <input type="submit" value="测试重定向提交">
+</form>
+
+<br>
+<a href="${pageContext.request.contextPath}/book/testRedirect">测试重定向</a>
+
+<br>
+<form action="${pageContext.request.contextPath}/book/testforward" method="post">
+    <input type="submit" value="测试转发提交">
+</form>
+
+<br>
+<a href="${pageContext.request.contextPath}/book/testforward">get-转发</a>
+
+<%--测试文件上传  enctype="multipart/form-data--%>
+<form action="${pageContext.request.contextPath}/book/uploadFile" method="post" enctype="multipart/form-data">
+    <input type="file" name="file">
+    <input type="submit" value="文件上传提交">
+</form>
+
+<%--文件下载--%>
+<a href="${pageContext.request.contextPath}/book/downloadFile">文件下载</a>
 </html>