First, Spring framework
Source Address: Https://github.com/spring-projects/spring-framework
Build tools: Gradle,gradle Tutorial: https://www.w3cschool.cn/gradle/
Gradle based on groovy language, groovy Tutorial: https://www.w3cschool.cn/groovy/
Data related to JSR standards : Https://jcp.org/en/jsr/all
Two, Spring Framework module
Official documents: https://docs.spring.io/spring/docs/4.3.17.RELEASE/spring-framework-reference/htmlsingle/#overview-modules
Iii. Building a DEMO-SPRINGMVC project using Maven
Maven (check create from archetype, select Maven-archetype-webapp), File-New Project, Next
GroupId:com.example
Artifactid:demo-spring
Next, Next
Project name:demo-spring
Finish
Comparing the two figure above, it is found that the difference is only in the web structure, and the default web structure needs to be modified. Go on...
Add Spring MVC Framework support to add spring MVC dependencies directly under dependencies in the Pom.xml file
<!--Https://mvnrepository.com/artifact/org.springframework/spring-webmvc -<Dependency> <groupId>Org.springframework</groupId> <Artifactid>Spring-webmvc</Artifactid> <version>4.3.17.RELEASE</version></Dependency>
Replace Web. xml
<?XML version= "1.0" encoding= "UTF-8"?><Web-appxmlns= "Http://xmlns.jcp.org/xml/ns/javaee"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "Http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"version= "3.1"> <Context-param> <Param-name>Contextconfiglocation</Param-name> <Param-value>/web-inf/applicationcontext.xml</Param-value> </Context-param> <Listener> <Listener-class>Org.springframework.web.context.ContextLoaderListener</Listener-class> </Listener> <servlet> <Servlet-name>Dispatcher</Servlet-name> <Servlet-class>Org.springframework.web.servlet.DispatcherServlet</Servlet-class> <Load-on-startup>1</Load-on-startup> </servlet> <servlet-mapping> <Servlet-name>Dispatcher</Servlet-name> <Url-pattern>/</Url-pattern> </servlet-mapping> <welcome-file-list> <Welcome-file>index.jsp</Welcome-file> </welcome-file-list></Web-app>
Add Applicationcontext.xml under Web-inf
<? XML version= "1.0" encoding= "UTF-8" ?> < xmlns= "Http://www.springframework.org/schema/beans" xmlns:xsi= " Http://www.w3.org/2001/XMLSchema-instance " xsi:schemalocation="/http/ Www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd " ></beans>
Dispatcher-servlet.xml
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"Xmlns:context= "Http://www.springframework.org/schema/context"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 http://www.springframework.org/schema/context/spring-context.xsd Http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd "> <!--Spring Basic Annotation Support - <Context:annotation-config/> <!--MVC Annotation Support - <Mvc:annotation-driven/> <!--Static Resource Mapping - <mvc:resourcesMapping= "/css/**" Location= "/web-inf/statics/css/"/> <mvc:resourcesMapping= "/js/**" Location= "/web-inf/statics/js/"/> <mvc:resourcesMapping= "/image/**" Location= "/web-inf/statics/image/"/> <!--JSP template View Support - <BeanID= "Defaultviewresolver"class= "Org.springframework.web.servlet.view.InternalResourceViewResolver"> < Propertyname= "Viewclass"value= "Org.springframework.web.servlet.view.JstlView"/> < Propertyname= "prefix"value= "/web-inf/view/"/> < Propertyname= "suffix"value= ". jsp"/> < Propertyname= "Exposecontextbeansasattributes"value= "true"/> </Bean> <!--Automatic Scanning Assembly - <Context:component-scanBase-package= "Com.example.demo"/></Beans>
Write a controller, run and see.
Two folders, Java, and test are built under SRC----set the resource type after creation.
The Java folder is set to Sources,test folder set to Tests
Create a test controller
Configuring the test server
Click Start to access Localhost:8080/user/get
Will show??
Cause: Spring MVC default Output character set iso-8859-1, you need to adjust the output character set to Utf-8
Start again, Access Localhost:8080/user/get, show normal.
Java notes Spring (i)