Qing 1 éve
szülő
commit
8053da4cc9

+ 22 - 24
springmvc-demo/.idea/workspace.xml

@@ -10,16 +10,13 @@
     <option name="autoReloadType" value="SELECTIVE" />
   </component>
   <component name="ChangeListManager">
-    <list default="true" id="d55c211f-cca4-4230-b149-ae8c1dab3c43" name="Changes" comment="0118 springmvc示例">
+    <list default="true" id="d55c211f-cca4-4230-b149-ae8c1dab3c43" name="Changes" comment="0119 ssm全注解版">
       <change afterPath="$PROJECT_DIR$/../.idea/VIPJAVA.iml" afterDir="false" />
       <change afterPath="$PROJECT_DIR$/../gn_oa_vip27/.idea/google-java-format.xml" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/WebInitConfig.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/anno/DruidConfig.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/anno/MybatisConfig.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/anno/SpringConfig.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/resources/log4j.properties" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/webapp/WEB-INF/templates/hello.html" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/webapp/WEB-INF/templates/test.html" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/sql/org_fiction.sql" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/controller/ScopeController.java" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/src/main/webapp/WEB-INF/templates/testlist.html" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/src/main/webapp/WEB-INF/templates/testscope.html" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/../02_JavaWeb/day06_mybatis/src/main/java/com/lc/mapper/UserMapper.java" beforeDir="false" afterPath="$PROJECT_DIR$/../02_JavaWeb/day06_mybatis/src/main/java/com/lc/mapper/UserMapper.java" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/../02_JavaWeb/day06_mybatis/src/main/resources/com/lc/mapper/UserMapper.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../02_JavaWeb/day06_mybatis/src/main/resources/com/lc/mapper/UserMapper.xml" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/../02_JavaWeb/day07_mybatis/src/main/resources/com/lc/mapper/UserMapper.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../02_JavaWeb/day07_mybatis/src/main/resources/com/lc/mapper/UserMapper.xml" afterDir="false" />
@@ -28,17 +25,7 @@
       <change beforePath="$PROJECT_DIR$/../gn_oa_vip27/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../gn_oa_vip27/.idea/workspace.xml" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/../gn_oa_vip27/src/main/java/com/sf/utils/JdbcUtil.java" beforeDir="false" afterPath="$PROJECT_DIR$/../gn_oa_vip27/src/main/java/com/sf/utils/JdbcUtil.java" 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/anno/MyServletContainerInitializer.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/sf/anno/init/MyServletContainerInitializer.java" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/src/main/java/com/sf/anno/MyWebAppInitializer.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/sf/anno/init/MyWebAppInitializer.java" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/src/main/java/com/sf/anno/SpringMvcConfig.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/sf/anno/SpringMvcConfig.java" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/src/main/java/com/sf/controller/AuthorController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/sf/controller/AuthorController.java" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/src/main/java/com/sf/controller/HelloController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/sf/controller/HelloController.java" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/src/main/java/com/sf/controller/HttpController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/sf/controller/HttpController.java" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/src/main/resources/spring-mvc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/spring-mvc.xml" 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/webapp/hello.jsp" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/webapp/WEB-INF/jsp/hello.jsp" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/src/main/webapp/index.jsp" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/webapp/WEB-INF/jsp/index.jsp" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />
     <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -58,9 +45,9 @@
         <option value="Interface" />
         <option value="Mybatis Mapper Xml File" />
         <option value="Properties File" />
-        <option value="Thymeleaf HTML File" />
-        <option value="HTML File" />
         <option value="Class" />
+        <option value="HTML File" />
+        <option value="Thymeleaf HTML File" />
       </list>
     </option>
   </component>
@@ -99,7 +86,7 @@
     "Tomcat Server.Tomcat 8.5.93.executor": "Run",
     "git-widget-placeholder": "master",
     "kotlin-language-version-configured": "true",
-    "last_opened_file_path": "/Users/Qing/IdeaProjects/SiFu/VIPJAVA/springmvc-demo",
+    "last_opened_file_path": "/Users/Qing/IdeaProjects/SiFu/VIPJAVA/springmvc-demo/sql",
     "node.js.detected.package.eslint": "true",
     "node.js.detected.package.tslint": "true",
     "node.js.selected.package.eslint": "(autodetect)",
@@ -114,6 +101,8 @@
 }]]></component>
   <component name="RecentsManager">
     <key name="CopyFile.RECENT_KEYS">
+      <recent name="$PROJECT_DIR$/sql" />
+      <recent name="$PROJECT_DIR$" />
       <recent name="$PROJECT_DIR$/src/main/java/com/sf" />
       <recent name="$PROJECT_DIR$/src/main/resources" />
       <recent name="$PROJECT_DIR$/src/main/webapp/WEB-INF" />
@@ -259,7 +248,7 @@
       <workItem from="1705471908780" duration="12452000" />
       <workItem from="1705492873471" duration="19225000" />
       <workItem from="1705593304178" duration="747000" />
-      <workItem from="1705625830502" duration="9118000" />
+      <workItem from="1705625830502" duration="15568000" />
     </task>
     <task id="LOCAL-00001" summary="0117 springmvc">
       <option name="closed" value="true" />
@@ -285,7 +274,15 @@
       <option name="project" value="LOCAL" />
       <updated>1705569024785</updated>
     </task>
-    <option name="localTasksCounter" value="4" />
+    <task id="LOCAL-00004" summary="0119 ssm全注解版">
+      <option name="closed" value="true" />
+      <created>1705638546742</created>
+      <option name="number" value="00004" />
+      <option name="presentableId" value="LOCAL-00004" />
+      <option name="project" value="LOCAL" />
+      <updated>1705638546742</updated>
+    </task>
+    <option name="localTasksCounter" value="5" />
     <servers />
   </component>
   <component name="TypeScriptGeneratedFilesManager">
@@ -331,7 +328,8 @@
     <MESSAGE value="0117 springmvc" />
     <MESSAGE value="0118 ssm整合" />
     <MESSAGE value="0118 springmvc示例" />
-    <option name="LAST_COMMIT_MESSAGE" value="0118 springmvc示例" />
+    <MESSAGE value="0119 ssm全注解版" />
+    <option name="LAST_COMMIT_MESSAGE" value="0119 ssm全注解版" />
   </component>
   <component name="XSLT-Support.FileAssociations.UIState">
     <expand />

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 1425 - 0
springmvc-demo/sql/org_fiction.sql


+ 9 - 0
springmvc-demo/src/main/java/com/sf/controller/HelloController.java

@@ -2,7 +2,9 @@ package com.sf.controller;
 
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.servlet.ModelAndView;
 
@@ -26,6 +28,13 @@ public class HelloController {
         return "hello";
     }
 
+    // http://localhost:8080/springmvc_demo/hello/all?username=lovecoding
+    @GetMapping("/hello/all")
+    public String helloAll(@RequestParam("username") String username, Model model) {
+        model.addAttribute("name", username);
+        return "hello";
+    }
+
     // http://localhost:8080/springmvc_demo/testForward
     @RequestMapping("/testForward")
     public String testForward() {

+ 93 - 0
springmvc-demo/src/main/java/com/sf/controller/ScopeController.java

@@ -0,0 +1,93 @@
+package com.sf.controller;
+
+import jakarta.servlet.http.HttpServletRequest;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.servlet.ModelAndView;
+
+import java.util.Map;
+
+@Controller
+public class ScopeController {
+
+    // http://localhost:8080/springmvc_demo/testList
+    // 最原始的请求方式
+    // 不处理数据 直接返回页面
+    @RequestMapping("/testList")
+    public String testScopeList(HttpServletRequest request) {
+        // WEB-INF/templates/testlist.html
+        return "testlist";
+    }
+
+    // 原始的请求方式
+    // 处理数据  <"testRequestScope","hello,servletAPI">
+    // ${testRequestScope}
+    // 然后返回页面
+    @RequestMapping("/testScope")
+    public String testRequestByServletAPI(HttpServletRequest request) {
+        // 设置request域数据 键值对
+        request.setAttribute("testRequestScope","hello,servletAPI");
+        // WEB-INF/templates/testscope.html
+        return "testscope";
+    }
+
+    // 既然就是key value 可以直接使用map
+    // <"testRequestScope","hello map">
+    // 页面本身${testRequestScope}  接收数据 将实际的数据替换占位符
+    // 拼接返回页面的路径 WEB-INF/templates/testscope.html
+    @RequestMapping("/testMap")
+    public String testMap(Map<String,Object> map) {
+        map.put("testRequestScope","hello map");
+        System.out.println(map.getClass().getName());
+        return "testscope";
+    }
+
+    // 如果不使用String 代表页面名字
+    // 可以使用ModelAndView   分别设置数据和页面
+    // addObject("testRequestScope","hello model and view");
+    //   把数据对象放入到model中然后设置对应的view
+    // setViewName("testscope");
+    // 来拼接返回页面的路径 WEB-INF/templates/testscope.html
+    @RequestMapping("/testModelAndView")
+    public ModelAndView testModelAndView() {
+        // 创建ModelAndView对象
+        ModelAndView modelAndView = new ModelAndView();
+        // 设置域数据键值对
+        modelAndView.addObject("testRequestScope","hello model and view");
+        // 设置视图名称
+        modelAndView.setViewName("testscope");
+        System.out.println("modelAndView:" + modelAndView.getClass().getName());
+        return modelAndView;
+    }
+
+
+    // ModelMap用法
+    // HttpServletRequest -> Map<String,Object> -> ModelAndView -> ModelMap
+    //   因为Model和View揉在一起 用起来有点麻烦  所以view还是通过方法的返回值String来表示
+    //   Model就是一个Map 合在一起叫做ModelMap
+    //   通过addAttribute来进行赋值 <key,value>
+    @RequestMapping("/testModelMap")
+    public String testModelMap(ModelMap modelMap) {
+        modelMap.addAttribute("testRequestScope","hello model map");
+        System.out.println("modelMap:" + modelMap.getClass().getName());
+        return "testscope";
+    }
+
+    // Model用法
+    // 最后索性 map也不要了  只使用Model
+    // 在一个路径所映射的方法中  这个方法是对某个请求的处理逻辑
+    // 这个处理逻辑中 Model只处理数据、View对应返回String的名字、Control就是整个方法的逻辑
+    // 最终组成MVC
+    //         Controller -> Service ->  Dao
+    //  SpringMVC中
+    //         DispatcherServlet -> HandlerMapping -> HandlerAdapter -> Controller.method()
+    //                    (html) <-                    viewResolver  <-
+    @RequestMapping("/testModel")
+    public String testModel(Model model) {
+        model.addAttribute("testRequestScope","hello model");
+        System.out.println("model:" + model.getClass().getName());
+        return "testscope";
+    }
+}

+ 15 - 0
springmvc-demo/src/main/webapp/WEB-INF/templates/testlist.html

@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html lang="en" xmlns:th="http://www.thymeleaf.org">
+<head>
+    <meta charset="UTF-8">
+    <title>Title</title>
+</head>
+<body>
+<h1>list page</h1>
+<a th:href="@{/testScope}">testScope</a><br>
+<a th:href="@{/testMap}">testMap</a> <br>
+<a th:href="@{/testModelAndView}">testModelAndView</a> <br>
+<a th:href="@{/testModelMap}">testModelmap</a> <br>
+<a th:href="@{/testModel}">testModel</a> <br>
+</body>
+</html>

+ 11 - 0
springmvc-demo/src/main/webapp/WEB-INF/templates/testscope.html

@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html lang="en" xmlns:th="http://www.thymeleaf.org">
+<head>
+  <meta charset="UTF-8">
+  <title>Title</title>
+</head>
+<body>
+<h1>result page</h1>
+<p th:text="${testRequestScope}"></p>
+</body>
+</html>

Nem az összes módosított fájl került megjelenítésre, mert túl sok fájl változott