Directory
Integrating Spring and SPRINGMVC
Integrating Spring and SPRINGMVC
We have previously integrated the spring and mybatis, and now we have integrated SSM on this basis.
Project directory:
650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/658141/201509/658141-20150904220754154-1408231451. PNG "style=" border:0px; "alt=" 658141-20150904220754154-1408231451.png "/>
Idea: SPRINGMVC's configuration file is independent, then configure the integration in Web. Xml.
(1) Configuration Spring-mvc.xml
The main is automatic Scan controller, view mode.
<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "http://www.springframework.org/ Schema/beans " xmlns:p=" http://www.springframework.org/schema/p " 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-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd Http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/ Spring-mvc-3.2.xsd "> <!-- automatically scan the package, The class that makes Springmvc think that the @controller annotation is under the package is the controller --> <context:component-scan base-package= "Com.aheizi.controller"/> <!-- Avoid IE in AJAX request, return JSON appears download --> <bean id= "Jacksonmessageconverter" class= " Org.springframework.http.converter.json.MappingJacksonHttpMessageConverter "> <property name= "Supportedmediatypes" > <list> <value>text/html;charset=utf-8 </value> </list> </property> </bean > <!-- DefinitionJump the prefix of the file , view mode configuration--> <bean class= " Org.springframework.web.servlet.view.InternalResourceViewResolver "> <!-- Configuration Here my understanding is to automatically add a prefix and suffix to the return string of the method that follows the action, turning it into a available URL address --> <property name= "prefix" value= "/web-inf/jsp/" /> <property name= "suffix" value= ". JSP" /> </bean> </beans>
(2) Configuring Web. Xml
Contains spring and MyBatis configuration files, encoding filters, logging, spring listeners, preventing spring memory overflow listeners, SPRINGMVC core configuration and error jump pages.
<?xml version= "1.0" encoding= "UTF-8"? ><web-app xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance " xmlns=" Http://java.sun.com/xml/ns/javaee " xsi:schemalocation="/HTTP/ Java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd " id=" WebApp_ID " version= "3.0" > <display-name>spring_mybatis_springmvc</display-name> <!--configuration files for spring and MyBatis --> <context-param> <param-name> Contextconfiglocation</param-name> <param-value> classpath:config/spring-mybatis.xml</param-value> </context-param> <!-- Encoding Filters --> <filter> <filTer-name>encodingfilter</filter-name> <filter-class >org.springframework.web.filter.CharacterEncodingFilter</filter-class> <async-supported>true</async-supported> <init-param> < param-name>encoding</param-name> <param-value>utf-8</param-value> </ init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </ filter-mapping> <!-- Logging (must be before Contextloaderlistener)--> < context-param> <!-- Log configuration file path --> <param-name>log4jConfigLocation</param-name> <param-value>classpath:properties/log4j.properties</param-value> </context-param> <context-param> <!-- Log page refresh interval --> <param-name>log4jRefreshInterval</param-name> <param-value>6000</param-value> </context-param> <listener> <listener-class> Org.springframework.web.util.Log4jConfiglistener</listener-class> </listener> <!-- spring Listener --> <listener> <listener-class>org.springframework.web.context.contextloaderlistener</ listener-class> </listener> <!-- Prevent spring memory overflow listener --> <listener> <listener-class>org.springframework.web.util.introspectorcleanuplistener</ listener-class> </listener> <!-- Spring MVC Core Configuration --> <servlet> <servlet-name>SpringMVC</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> < Init-param> <param-name> contextconfiglocation</param-name> <param-value>classpath:spring-mvc.xml</param-value> </init-param> <load-on-startup>1</ load-on-startup> <async-supported>true</ async-supported> </servlet> <!-- suffixes --> <servlet-mapping> <servlet-name>SpringMVC</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <!-- Welcome Page --> <welcome-file-list> <welcome-file>/index.jsp</welcome-file> </welcome-file-list> <!-- Error jump page --> < error-page> <!-- path is incorrect --> <error-code>404</error-code> <location>/web-inf/errorpage/404.html</location> </ error-page> <error-page> <!- - No access rights, access is forbidden --> <error-code>405</ error-code> <location>/WEB-INF/errorpage/405.html</location> </error-page> <error-page> <!-- INTERNAL Error --> <error-code>500</ error-code> <location>/web-inf/errorpage/500.html</ Location> </error-page> </web-app>
(3) Create showuser.jsp page
<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%><! DOCTYPE html>
Execute maven clean install, run tomcat, enter
127.0.0.1/spring_mybatis_springmvc/user/showuser.do?id=1 (I set the Tomcat port to 80)
The page is as follows:
650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/658141/201509/658141-20150906155139795-1533461746. PNG "style=" border:0px; "alt=" 658141-20150906155139795-1533461746.png "/>
OK, get it done!
Build the Spring + SPRINGMVC + mybatis Framework (integrate spring, MyBatis, and spring MVC)