Die Schönheit der Einfachheit, SpringMVC und MyBatis ist eine gute einfache Integrationslösung, die den allgemeinen Projektanforderungen entsprechen kann. Teilen Sie die Projektkonfigurationsdateien in Ihrer Freizeit für Ihre Referenz:
1. Schauen wir uns zunächst die Abhängigkeits -POM an:
<!- Frühling -> <depeencing> <gruppe> org.springFramework </gruppeId> <artifactId> Spring-Core </artifactId> <version> $ {Spring.version} </Version> </abhängig> <Dependentcy> <gruppe> org.springFramework </Groupid> <artifactId> Spring-Beer </artifactid> <version> $ {Spring.version} </Version> </abhängig> <de pendency> <GroupID> org.springFramework </gruupid> <artifactId> Spring-Context </artifactId> <version> $ {Spring.version} </Version> </abhängig> <dep endcy> <GroupID> org.springFramework </gruppeId> <artifactID> Spring-Tx </artifactId> <version> $ {Spring.version} </Version> </abhängig> <abhängig Cy> <gruppe> org.springFramework </gruppeId> <artifactId> Spring-Web </artifactId> <version> $ {Spring.version} </Version> </abhängig> <depeopycus> < GroupID> org.springFramework </gruppeId> <artifactId> Spring-webmvc </artifactId> <version> $ {Spring.version} </Version> </abhängig> <depelziee> <gr OUPID> org.springFramework </gruppeId> <artifactId> Spring-Jdbc </artifactId> <version> $ {Spring.version} </Version> </abhängig> <depelziewerte> <Groupi d> org.springFramework </gruppeId> <artifactId> Spring-Test </artifactId> <version> $ {Spring.version} </Version> <Scope> Test </Scope> </abhängig> <!- MyBatis-Paket-> <De vor Ort> <GroupId> org.mybatis </Groupid> <artifactId> mybatis </artifactid> <version> 3.2.8 </Version> </abhängig> <!-MyBatis Spring Plug-In-> <De vor Ort> <gruppe> org.mybatis </Groupid> <artifactId> mybatis-pring </artifactId> <version> 1.2.2 </Version> </abhängig> <!-Mysql Verbindung -> <depeencing> <gruppe> MySQL </Groupid> <artifactId> Mysql-connector-Java </artifactId> <version> 5.1.34 </Version> </abhängig> <!-Daten source--><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.0.12</version></dependency><dependency><groupId>org.aspectj</groupId><artifactId>aspectjweaver</artifactId><version>1.8.4</version></dependency><!-- log4j -> <depeencing> <GroupId> log4j </GroupID> <artifactId> log4j </artifactId> <version> 1.2.17 </Version> </abhängig> <!-Servlet --><dependency><groupId>javax.servlet</groupId><artifactId>servlet-api</artifactId><version>3.0-alpha-1</version></dependency><dependency><groupId>javax.servlet</groupId><artifactId>jstl</artifactId><version>1.2</version></dependency><!-- json -> <depeencing> <gruppe> org.codeehaus.jackson </Groupid> <artifactId> Jackson-mapper-asl </artifactId> <version> 1.9.13 </Version> </abhängig> <depelzus> <gruppe> com.alibaba </guu PID> <artifactId> fastjson </artifactId> <version> 1.2.3 </Version> </abhängig> <depeaponcy> <gruppe> com.fasterxml.jackson.core </gruppacid> <artifactid> jackson-Annotationen </artifactid > <version> $ {Jackson.version} </Version> </abhängig> <depeopecy> <gruppe> com.fasterxml.jackson.core </Groupid> <artifactid> Jackson-Core </artifactid> <version> $ {Jackson.version} < /version></dependency><Dependency><GroupId> comcom.fasterxml.jackson.core</groupid><ArtifactId>jackson-databind</artifactid><Version>$ {Jackson.Version </version></dependency><! Datei-Upload-> <De vor Ort> <gruppe> commons-io </GroupId> <artifactId> commons-io </artifactId> <version> 2.4 </Version> </abhängig> <depeaponcy> <GroupId> Commons-fileUpload </GroupId> <artifactId> commons-fileUpload </artifactid> 1.2.2 </Version> </artifactId> </Version> </Version> </fusion> </artifactId> </ussion> </fusion> </artifactid> </ussion> </fusion> </reibungsweiseSpring verwendet Version 4.1.4, und wir können die Version auswählen, die uns entsprechend den Anforderungen des Systems entspricht.
2. Verwandte Konfigurationsdateien:
A) Spring.xml
<? xmlns: context = "http://www.springframework.org/schema/context" xsi: schemalocation = "http://www.springframework.org/schema/beanshttp://www.s pringframework.org/schema/beans/spring-geans-4.1.xsdhttp://www.springframework.org/schema/context/spring-context-4.1.xsd"><!-Eindringliche Konfigurationseigenschaften Datei-> <Kontext: Eigenschafts-Placeholder-Standort = "classPath: config.Properties" /> <!
b) Spring-Mvc.xml
<? xmlns: xsi = "http://www.w3.org/2001/xmlschema-instance" xmlns: p = "http://www.springframework.org/schema/p" xmlns: context = "http://www.springframework.org/schema/context" xsi: schemalocation = "http://www.spingframework.org/schema/beans http://www.springframework.org/schems/beans- http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd"><!-scannen automatisch alle Klassen unter dem Controller-Paket. Wenn @Controller als bean injiziert wird-> <context: component-scan base-package = "com.demo.report id = "mapingjacksonhttpMessageConverter" class = "org.springframework.http.converter.json.mappingjackson2HttpMessageConverter"> <Property name = "SupportedMediTypes"> <List> <Wert> text/html; charset = utf-8 </value> </list> </property> </bean> <!-Start Spring MVC-Annotationsfunktion, um die Zuordnung von Anforderungen und Annotationen abzuschließen Pojos-> <beanclass = "org.springframework.web.servlet.mvc.annotation Lösen Sie den Namen der Modellansicht, dh, dem Modellansichtsname -> <beanclass = "org.springFramework.web.Servlet.View.InternalResourceViewresolver"> <Eigenschaft name = "viewClass" value = "org.springFramework.web.Servlet.Vew.View.Jstlview" /> -Stame.Web.Servlet.Vew.View.JSTLVIEW " /> -Stame.Web.Servlet.View.View.JSTLVIEW" /> /> <Eigenschaft name = "suffix" value = ""/> </bean> <!-Konfigurieren Sie Multi-File-Upload <bean id = "multipartresolver" class = "org.springFramework name = "maxUploadSize"> <wert> 32505856 </value> </Property> <Eigenschaft name = "maxinMemorySize"> <wert> 4096 </value> </property> </bean>-> </beans>
c) Spring-Mybatis.xml
<? xmlns: tx = "http://www.springframework.org/schema/tx" xmlns: aop = "http://www.spingframework.org/schema/aop" xsi: schemalocation = "http://wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww.Stramework." http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/sping-tx- http://www.springframework.org/schema/aop http://www.springFramework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd"> & lata-QUSPRING-AP-4.1.XSD"> & lata-Quelle-Die Data-die Data-die Data-die Data-die Data-die Data-die Data-die Data-die Data-die Data-die Data-die Data-die Data-die Data-die Data-die Data, die die daten-aop-4.1.xsd"> & lata · uid-aop-4.1.xsd"> & lat · · · · · · · · · · · · · · · · · · ted"> &Tium-die Data Quelle-die Data-Datruid-a. name="dataSource"init-method="init" destroy-method="close"><property name="url" value="${jdbc.url}" /><property name="username" value="${jdbc.username}" /><property name="password" value="${jdbc.password}" /><!-- Initialize the connection size--><property name = "initialSize" value = "0" /> <!-Maximale Anzahl der im Verbindungspool verwendeten Verbindungen-> <Eigenschaftsname = "MaxActive" value = "20" /> <!-Minimum kostenlose Verbindungen-> <Eigenschaft name = "minidle" value = "0" /> <! value = "true" /> <Eigenschaft name = "maxpoolProparedStatementPerConnectionSize" value = "33" /> <!-verwendet, um gültige SQL-> <Eigenschaft name = "validationQuery" value = "$ {validationQuery}" /> <Property name = "testonborde" value = "usworge" /> <Stiefs-Name " /> <Stiefs-Name", " /> <Stiefs" zu erkennen ". value = "true" /> <!-Konfigurieren Sie, wie lange es dauert, um einen Test durchzuführen, um die Leerlaufverbindung zu erkennen, die in Millisekunden geschlossen werden muss. /> <!-RemoveaBandoned-Funktion einschalten-> <Eigenschaft name = "removeaBandoned" value = "true" /> <!-1800 Sekunden, das heißt 30 Minuten-> <Eigenschaft name = "removeaBandOnedTimeout" value = "1800" /> <!-Ausgabefehlerprotokoll beim Schließen der abgestellten Verbindung-> <Eigenschaftsname = "Logaboned". name = "filters" value = "mergestat" /> < /bean> <!-myBatis-Datei-> <bean id = " value = "classPath: com/Demo/report/web/mapper/*. xml"/> </bean> <bean> <bean> <Eigenschaftsname = "Basepackage" value = "com.feidai.report.web.mapper"/> <Property name = " Manager-> <bean id = "transactionManager" class = "org.springframework.jdbc.datasource.datasourcetransactionManager"> <Eigenschaft name = "dataSource" Ref = "DataSource" /> < /bean>d) web.xml
<diagendrat-Name> springmvc_mybatis_demo </display-name> <context-param> <param-name> contextConfigLocation </param-name> <param-value> classPath: Spring.xml, ClassPath: Spring-Mybatis.xml </param-val ue> </context-param> <filter> <filter-name> codingFilter </filter-name> <filterklasse> org.springFramework.web.filter.CharactercodingFilter </filter-classe> <init-param> <Param-name> codieren </p aram-name> <param-value> utf-8 </param-value> </init-param> <init-param> <param-name> crossEcoding </param-name> <param-value> true </param-value> </init-param > CodingFilter </filter-name> <URL-PATTERN>/*</URL-PATTERN> </filter-mapping> <hörer> <hörerklasse> org.springFramework.web.Context.ContextLoaderListener </Listener-Class> </Hörer> <! Verhindern Sie den Frühlingsspeicher vom Überlauf-Hörer-> <Hörer> <Hörer-Klasse> org.springframework.web.util.InrospectorCleanUplistener </Listener-Klasse> </Hörer> <servlet> <beschreibung> Spring MVC Servlet </Beschreibung> <Servlet-Name> Rest </servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </Servlet-Class> <init-param> <Param-name> contal xtconfigLocation </param-name> <param-value> classPath: Spring-mvc.xml </param-value> </init-param> <load-on-startup> 1 </load-on-Startup> </Servlet> <Servlet-Mapping> <servle T-NAME> REST </Servlet-Name> <URL-Muster>/</url-pattern> </servlet-mapping> <servlet> <servlet-name> druidstatView </servlet-name> <Servlet-Klasse> com.alibaba.druid.support .http.statViewServlet </servlet-classe> </servlet> <servlet-mapping> <servlet-name> druidstatView </servlet-name> <url-pattern>/druid/*</url-pattern> </servlet-mapping> <!-- Konfigurieren von Sitzungszeiten für die Sitzung, Einheit Minuten-> <ssionskonfigur> <Session-Timeout> 30 </Session-Timeout> </Session-Config> <Welcome-File-List> <Welcome-File> Index.jsp </Welcome-File> </Welcome-File-List>
Verwenden Sie die Druid -Datenquelle. Weitere Informationen finden Sie im Code für eine detaillierte Konfiguration im Web.
Das obige ist eine detaillierte Erklärung des integrierten Konfigurationsbeispiels von SpringMVC und MyBatis, die Ihnen vom Editor vorgestellt wurden. Ich hoffe, es wird Ihnen hilfreich sein. Wenn Sie Fragen haben, hinterlassen Sie mir bitte eine Nachricht. Der Herausgeber wird Ihnen rechtzeitig antworten. Vielen Dank für Ihre Unterstützung für die Wulin Network -Website!