Qing 1 рік тому
батько
коміт
754676ef6c

+ 85 - 32
springmvc-demo/.idea/workspace.xml

@@ -10,40 +10,21 @@
     <option name="autoReloadType" value="SELECTIVE" />
   </component>
   <component name="ChangeListManager">
-    <list default="true" id="d55c211f-cca4-4230-b149-ae8c1dab3c43" name="Changes" comment="0117 springmvc">
+    <list default="true" id="d55c211f-cca4-4230-b149-ae8c1dab3c43" name="Changes" comment="0118 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/controller/HelloController.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/dao/AuthorDao.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/dao/BookDao.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/dao/TypeDao.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/entity/Author.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/entity/Book.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/entity/Type.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/service/AuthorService.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/service/BookService.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/service/impl/AuthorServiceImpl.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/service/impl/BookServiceImpl.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/resources/db.properties" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/resources/mapper/authorMapper.xml" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/resources/mapper/bookMapper.xml" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/resources/mapper/typeMapper.xml" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/resources/mybatis-config.xml" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/resources/spring.xml" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/controller/HttpController.java" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/src/test/java/com/sf/TestSpringMvc.java" 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" />
       <change beforePath="$PROJECT_DIR$/../gn_oa_vip27/.idea/jarRepositories.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../gn_oa_vip27/.idea/jarRepositories.xml" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/../gn_oa_vip27/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../gn_oa_vip27/.idea/misc.xml" afterDir="false" />
       <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/MyServletContainerInitializer.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/sf/anno/MyServletContainerInitializer.java" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/src/main/java/com/sf/MyWebAppInitializer.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/sf/anno/MyWebAppInitializer.java" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/src/main/java/com/sf/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/BookController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/sf/controller/BookController.java" 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/entity/Author.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/sf/entity/Author.java" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />
     <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -61,8 +42,8 @@
         <option value="Jsp File" />
         <option value="Spring Xml File" />
         <option value="Interface" />
-        <option value="Class" />
         <option value="Mybatis Mapper Xml File" />
+        <option value="Class" />
       </list>
     </option>
   </component>
@@ -91,6 +72,8 @@
   </component>
   <component name="PropertiesComponent"><![CDATA[{
   "keyToString": {
+    "HTTP Request.rest-api_1 | #1.executor": "Run",
+    "JUnit.TestSpringMvc.test.executor": "Run",
     "Maven. [org.apache.maven.plugins:maven-archetype-plugin:RELEASE:generate].executor": "Run",
     "RunOnceActivity.OpenProjectViewOnStart": "true",
     "RunOnceActivity.ShowReadmeOnStart": "true",
@@ -104,10 +87,10 @@
     "node.js.selected.package.eslint": "(autodetect)",
     "node.js.selected.package.tslint": "(autodetect)",
     "nodejs_package_manager_path": "npm",
-    "project.structure.last.edited": "Project",
+    "project.structure.last.edited": "Modules",
     "project.structure.proportion": "0.17833698",
-    "project.structure.side.proportion": "0.0",
-    "settings.editor.selected.configurable": "preferences.externalResources",
+    "project.structure.side.proportion": "0.2150838",
+    "settings.editor.selected.configurable": "preferences.pluginManager",
     "vue.rearranger.settings.migration": "true"
   }
 }]]></component>
@@ -121,7 +104,26 @@
       <recent name="$PROJECT_DIR$/src/main/java/com/sf/anno" />
     </key>
   </component>
-  <component name="RunManager">
+  <component name="RunManager" selected="Tomcat Server.Tomcat 10.0.21">
+    <configuration name="rest-api_1 | #1" type="HttpClient.HttpRequestRunConfigurationType" factoryName="HTTP Request" temporary="true" nameIsGenerated="true" path="$APPLICATION_CONFIG_DIR$/scratches/rest-api_1.http" requestIdentifier="#1" runType="Run single request">
+      <method v="2" />
+    </configuration>
+    <configuration name="TestSpringMvc.test" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
+      <module name="springmvc-demo" />
+      <extension name="coverage">
+        <pattern>
+          <option name="PATTERN" value="com.sf.*" />
+          <option name="ENABLED" value="true" />
+        </pattern>
+      </extension>
+      <option name="PACKAGE_NAME" value="com.sf" />
+      <option name="MAIN_CLASS_NAME" value="com.sf.TestSpringMvc" />
+      <option name="METHOD_NAME" value="test" />
+      <option name="TEST_OBJECT" value="method" />
+      <method v="2">
+        <option name="Make" enabled="true" />
+      </method>
+    </configuration>
     <configuration name="Tomcat 10.0.21" type="#com.intellij.j2ee.web.tomcat.TomcatRunConfigurationFactory" factoryName="Local" APPLICATION_SERVER_NAME="Tomcat 10.0.21" ALTERNATIVE_JRE_ENABLED="false" nameIsGenerated="true">
       <option name="OPEN_IN_BROWSER_URL" value="http://localhost:8080/springmvc_demo/hello" />
       <option name="UPDATING_POLICY" value="restart-server" />
@@ -216,6 +218,12 @@
         </option>
       </method>
     </configuration>
+    <recent_temporary>
+      <list>
+        <item itemvalue="HTTP Request.rest-api_1 | #1" />
+        <item itemvalue="JUnit.TestSpringMvc.test" />
+      </list>
+    </recent_temporary>
   </component>
   <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
   <component name="TaskManager">
@@ -226,7 +234,7 @@
       <option name="presentableId" value="Default" />
       <updated>1705471907664</updated>
       <workItem from="1705471908780" duration="12452000" />
-      <workItem from="1705492873471" duration="6116000" />
+      <workItem from="1705492873471" duration="16210000" />
     </task>
     <task id="LOCAL-00001" summary="0117 springmvc">
       <option name="closed" value="true" />
@@ -236,15 +244,60 @@
       <option name="project" value="LOCAL" />
       <updated>1705481868228</updated>
     </task>
-    <option name="localTasksCounter" value="2" />
+    <task id="LOCAL-00002" summary="0118 ssm整合">
+      <option name="closed" value="true" />
+      <created>1705551875551</created>
+      <option name="number" value="00002" />
+      <option name="presentableId" value="LOCAL-00002" />
+      <option name="project" value="LOCAL" />
+      <updated>1705551875551</updated>
+    </task>
+    <option name="localTasksCounter" value="3" />
     <servers />
   </component>
   <component name="TypeScriptGeneratedFilesManager">
     <option name="version" value="3" />
   </component>
+  <component name="Vcs.Log.Tabs.Properties">
+    <option name="OPEN_GENERIC_TABS">
+      <map>
+        <entry key="a504f1b5-4d9a-4e77-842b-fa8776f962fa" value="TOOL_WINDOW" />
+      </map>
+    </option>
+    <option name="TAB_STATES">
+      <map>
+        <entry key="a504f1b5-4d9a-4e77-842b-fa8776f962fa">
+          <value>
+            <State>
+              <option name="FILTERS">
+                <map>
+                  <entry key="branch">
+                    <value>
+                      <list>
+                        <option value="HEAD" />
+                      </list>
+                    </value>
+                  </entry>
+                  <entry key="structure">
+                    <value>
+                      <list>
+                        <option value="dir:/Users/Qing/IdeaProjects/SiFu/VIPJAVA/springmvc-demo" />
+                      </list>
+                    </value>
+                  </entry>
+                </map>
+              </option>
+              <option name="SHOW_ONLY_AFFECTED_CHANGES" value="true" />
+            </State>
+          </value>
+        </entry>
+      </map>
+    </option>
+  </component>
   <component name="VcsManagerConfiguration">
     <MESSAGE value="0117 springmvc" />
-    <option name="LAST_COMMIT_MESSAGE" value="0117 springmvc" />
+    <MESSAGE value="0118 ssm整合" />
+    <option name="LAST_COMMIT_MESSAGE" value="0118 ssm整合" />
   </component>
   <component name="XSLT-Support.FileAssociations.UIState">
     <expand />

+ 12 - 0
springmvc-demo/pom.xml

@@ -122,5 +122,17 @@
     </dependencies>
     <build>
         <finalName>springmvc-demo</finalName>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.11.0</version>
+                <configuration>
+                    <parameters>true</parameters>
+                    <source>17</source>
+                    <target>17</target>
+                </configuration>
+            </plugin>
+        </plugins>
     </build>
 </project>

+ 94 - 0
springmvc-demo/src/main/java/com/sf/controller/HttpController.java

@@ -0,0 +1,94 @@
+package com.sf.controller;
+
+import jakarta.servlet.http.HttpServletRequest;
+import org.springframework.web.bind.annotation.*;
+
+@RestController
+@RequestMapping("/http")
+public class HttpController {
+    @RequestMapping(method = RequestMethod.GET)
+    public String get() {
+        return "Hello from get";
+    }
+
+    @RequestMapping(method = RequestMethod.DELETE)
+    public String delete() {
+        return "Hello from delete";
+    }
+
+    @RequestMapping(method = RequestMethod.POST)
+    public String post() {
+        return "Hello from post";
+    }
+
+    @RequestMapping(method = RequestMethod.PUT)
+    public String put() {
+        return "Hello from put";
+    }
+
+
+    @RequestMapping("/request")
+    public String testRequestMapping(HttpServletRequest request) {
+        System.out.println("请求方式    " + request.getMethod());
+        System.out.println("UA    " + request.getHeader("user-agent"));
+        System.out.println("请求带过来的用户名    " + request.getParameter("username"));
+        System.out.println("请求带过来的密码    " + request.getParameter("password"));
+        System.out.println("host:  " + request.getHeader("host"));
+        return "success";
+    }
+
+    // http://localhost:8080/springmvc_demo/http/login?username=lovecoding&password=nobug888
+    @RequestMapping("/login")
+    public String testUser(String username, String password) {
+        System.out.println(username);
+        System.out.println(password);
+        return "success";
+    }
+
+    // http://localhost:8080/springmvc_demo/http/login/param?username=qing&password=123456
+    @RequestMapping("/login/param")
+    public String testParam(@RequestParam("username") String username,
+                            @RequestParam("password") String password) {
+        System.out.println(username);
+        System.out.println(password);
+        return "success";
+    }
+
+    // http://localhost:8080/springmvc_demo/http/login/other?user=qing&pw=654321
+    // http://localhost:8080/springmvc_demo/http/login/other?user=&pw=654321
+    // http://localhost:8080/springmvc_demo/http/login/other?pw=654321
+    @RequestMapping("/login/other")
+    public String testParamOther(
+            @RequestParam(value = "user", defaultValue = "lovecoding") String username,
+            @RequestParam("pw") String password) {
+        System.out.println(username);
+        System.out.println(password);
+        return "success";
+    }
+
+    // http://localhost:8080/springmvc_demo/http/login/required?username=lovecoding
+    @RequestMapping("/login/required")
+    public String testRequired(
+            @RequestParam(value = "username", required = true) String username,
+            @RequestParam(value = "password", required = false) String password) {
+        System.out.println(username);
+        System.out.println(password);
+        return "success";
+    }
+
+    // http://localhost:8080/springmvc_demo/http/register/111222
+    @RequestMapping(value = "/register/{id}", method = RequestMethod.GET)
+    public String testRegister(@PathVariable("id") String id) {
+        System.out.println("ID is " + id);
+        return "hello PathVariable";
+    }
+
+    // http://localhost:8080/springmvc_demo/http/header
+    @RequestMapping("/header")
+    public String testHeader(@RequestHeader("user-agent") String UA,
+                             @RequestHeader("host") String host) {
+        System.out.println(UA);
+        System.out.println(host);
+        return "success";
+    }
+}

+ 3 - 3
springmvc-demo/src/main/java/com/sf/entity/Author.java

@@ -18,10 +18,10 @@ public class Author implements Serializable {
 
     private Long id;
 
-    private String authorId;
+    private String authorId; // author_id
 
-    private String authorName;
+    private String authorName; // author_name
 
-    private String authorDesc;
+    private String authorDesc; // author_desc
 
 }

+ 26 - 0
springmvc-demo/src/test/java/com/sf/TestSpringMvc.java

@@ -0,0 +1,26 @@
+package com.sf;
+
+import com.sf.controller.AuthorController;
+import com.sf.controller.BookController;
+import com.sf.service.BookService;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
+import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
+
+//@SpringJUnitConfig
+@SpringJUnitWebConfig(locations = {"classpath:spring.xml","classpath:spring-mvc.xml"})
+public class TestSpringMvc {
+
+    @Autowired
+    private BookService bookService;
+
+    @Autowired
+    private AuthorController authorController;
+
+    @Test
+    public void test(){
+        //        System.out.println(bookService.queryBooks());
+        System.out.println(authorController.getAll());
+    }
+}