The configuration of the SSM XML and Web. config

Source: Internet
Author: User

Display Layer (Handler/controller):

Request to the front controller of the SPRINGMVC, from the processor mapper to find the corresponding handler (with the @requestmapping ("") callout, after the successful mapping, a handler object is generated by SPRINGMVC, there is a method in the object, That is, the method that mapped successfully), by the corresponding processor adapter to execute the Handler,handler called the Business Control Layer (service) of the method interface. Then return the JSP address of the string or have the address and request parameters of the Modelandview object (which loaded parameters such as Name,id, and the target address is the corresponding display page such as JSP, see part of the source code, is stored with the map, and then placed in the request object) to the front controller, The front-end controller then passes the Modelandview to the view parser, with the prefix and suffix of the JSP address set in the parser, then returns the view to the front controller, then renders the view (as if it were the request object that populated the data in the map) and returns it to the client.

Business Control Layer (service):

A service interface, and its corresponding implementation class Serviceimpl, which enables the development of the business Control layer and the development of the display layer in parallel, as long as the display layer of a service interface can be. The service Layer implementation class uses the spring IOC (autowired annotations) to automatically inject one or more Mapper objects, which are obtained by getbean methods that call Sqlsessionfactory's getsession. The corresponding method of the Mapper object is then called and the appropriate control flow (such as the Beanutils.copyproperties () method to copy the attributes or verify the business) should be added when needed.

Persistence Layer (Dao/mapper):

The corresponding Mapper.java is generated by reverse engineering, namely the corresponding Mapper.xml, and the pojo corresponding to the database table, which can realize simple single-table query.

If you have more than one table associated with a query, you need to customize Mapper, because the returned results include properties from multiple Pojo, it is not recommended to add the corresponding property directly in Pojo, instead write a subclass that inherits a Pojo class, and then add the attributes in the other pojo that you want in that subclass. This is the subclass for which the return type is. Where the query parameter is the Queryvo class, which combines the above subclasses and other subclasses of the object, what parameters need to write what object.

Applicationcontext-mvc.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:mvc= "Http://www.springframework.org/schema/mvc" xmlns: context= "Http://www.springframework.org/schema/context" xmlns:p= "http://www.springframework.org/schema/p" xsi: schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans-4.3.xsdhttp://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/ Spring-mvc-4.3.xsd Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/ Spring-context-4.3.xsd "><!--open annotations. Scan--><context:annotation-config></context:annotation-config><context:component-scan Base-package= "com.***" ></context:component-scan><!--filter out JS, jpg, PNG, CSS, static files--><mvc: default-servlet-handler/><!--start MVC <mvc:annotation-driven/>--> <!--first step: Create a custom date conversion rule--<bean id= "Dateconvert" class= "com.***.utils. Dateconvert "/> <!--Step Two: Create Convertion-service and inject dateconvert--> <bean id=" Conversionservice "CLA ss= "Org.springframework.format.support.FormattingConversionServiceFactoryBean" > <property name= "Converters "> <set> <ref bean=" Dateconvert "/> </set> &LT;/PROPERTY&G    T </bean> <!--step Three: Register processor Mapper/processor adapter, add Conversion-service Properties--<mvc:annotation-driven Conversion-service= "Conversionservice"/><!--open MVC <mvc:annotation-driven/><bean id= "Inter" class= " Com.***.inter. Logininter "></bean>--><!--Interceptor Configuration <mvc:interceptors><mvc:interceptor><mvc:mapping Path= "/**"/>//intercept all <ref bean= "Inter"/></mvc:interceptor></mvc:interceptors>-<!--address solution --><bean class= "Org.springframework.web.servlet.view.InternalResourceViewResolver" ><propeRty name= "prefix" value= "/web-inf/views/" ></property><property name= "suffix" value= ". JSP" ></ Property></bean></beans>

Applicationcontext.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:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" xmlns:tx= "Http://www.springframework.org/schema/tx" xmlns: p= "http://www.springframework.org/schema/p" xsi:schemalocation= "Http://www.springframework.org/schema/beans http ://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/context http ://www.springframework.org/schema/context/spring-context-4.3.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http ://www.springframework.org/schema/aop/spring-aop-4.3.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/TX/http Www.springframework.org/schema/tx/spring-tx-4.3.xsd "><!--@Component, @Repository, @Service, @Controller, @ autowired, @Resources--><!--developed with annotations--><context:annotation-config></context:annotation-config ><!--Note Scan package--><context:component-scan base-package= "com.***" ><!--This does not load the controller's bean--><context : Exclude-filter type= "annotation" expression= "Org.springframework.stereotype.Controller"/></context: component-scan><!--1. The data source-->< reads the db.properties file!--. Read to database information--><context:property-placeholder location= "classpath:db.properties"/><bean id= "DataSource" class= "Com.alibaba.druid.pool.DruidDataSource" ><property name= "Driverclassname" value= "${jdbc.driver}" > </property><property name= "url" value= "${jdbc.url}" ></property><property name= "username" Value= "${jdbc.username}" ></property><property name= "password" value= "${jdbc.password}" ></  property></bean><!--2. Create Sqlsessionfactory ==> mybatis core profile read--><bean id= "sqlsessionfactory" class= " Org.mybatis.spring.SqlSessionFactoryBean "><property name=" DataSource "ref=" DataSource "></property ><property name= "Configlocation"Value=" Classpath:mybatis-config.xml "></property></bean><!--3. Mapper interface path for scanning MyBatis-->< !--This bean can scan our mapper interface directly. Scan the interface directly. Register to Spring Bean--><bean class= "Org.mybatis.spring.mapper.MapperScannerConfigurer" > <property name= " Sqlsessionfactorybeanname "value=" Sqlsessionfactory "></property> <!--will look for interface under the provided base package. According to interface's name. Sketch the initial letter to the bean that corresponds to this interface---<property name= "Basepackage" value= "Com.***.mapper" ></property> </bean ><!--4. Transaction processing--><bean id= "TransactionManager" class= " Org.springframework.jdbc.datasource.DataSourceTransactionManager "><property name=" datasource "ref=" DataSource "></property></bean><tx:advice id=" Txmanager "transaction-manager=" TransactionManager "><tx:attributes><tx:method name=" get* "read-only=" true "/><tx:method name=" query* "read-only=" true "/><tx:method name=" search* "read-only=" true "/><tx:method name=" select* " Read-only= "true"/><tx:method name=" find* "read-only=" true "/><tx:method name=" * "isolation=" DEFAULT "propagation=" REQUIRED "/></tx:attributes></tx:advice><aop:config><aop:pointcut expression=" Execution ( * Com.***.*.*.*.* (..)) " Id= "Cut"/><aop:advisor advice-ref= "Txmanager" pointcut-ref= "cut"/></aop:config><!--handling transactions with annotations < Tx:annotation-driven transaction-manager= "TransactionManager"/>--></beans>

Mybatis-config.xml

<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE configuration Public  "-//mybatis.org//dtd Config 3.0//en"  "http://mybatis.org/dtd/ Mybatis-3-config.dtd "><configuration><!--mybatis Core configuration  --><!--mybatis Run Configuration-->< settings><!--turn on level two cache--><setting name= "cacheenabled" value= "true"/><setting name= " Lazyloadingenabled "value=" true "/><!--if this property is true, then any of the methods in your class are executed. To load properties, lazy loading is not effective at this time. --><setting name= "aggressivelazyloading" value= "false"/></settings></configuration>

Xml

<?xml version= "1.0" encoding= "UTF-8"? ><web-app version= "2.5" xmlns= "Http://java.sun.com/xml/ns/javaee" Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http ://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "><!--read configuration files except MVC--><context-param>< param-name>contextconfiglocation</param-name><param-value>classpath:applicationcontext.xml</ param-value></context-param><!--The entire web container is being monitored by this listener. This listener can listen for project startup. To directly load the core configuration file--><listener><listener-class>org.springframework.web.context.contextloaderlistener </listener-class></listener> <filter><filter-name>characterencodingfilter</ Filter-name><filter-class>org.springframework.web.filter.characterencodingfilter</filter-class> <init-param><param-name>encoding</param-name><param-value>UTF-8</param-value> </init-param><init-param><param-name>forceencoding</param-name><param-value>true</param-value></init-param></ Filter><filter-mapping><filter-name>characterencodingfilter</filter-name><url-pattern >/*</url-pattern></filter-mapping><!--Custom Filters--<filter><filter-name> Loginfilter</filter-name><filter-class>com.***.filter. loginfilter</filter-class></filter><filter-mapping><filter-name>loginfilter</ Filter-name><url-pattern>/*</url-pattern></filter-mapping> <servlet> <servlet-name >springMVC</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</ servlet-class> <!--give spring's path--<init-param> <param-name>contextconfiglocation</  Param-name> <param-value>classpath:applicationContext-mvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup><!--when web capacityWhen the device loads, initialize spring--</servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name > <url-pattern>/</url-pattern><!--All--</servlet-mapping> <listener> <listene R-class>org.springframework.web.context.request.requestcontextlistener</listener-class> </listener > </web-app>

  

The configuration of the SSM XML and Web. config

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.