La beauté de la simplicité, SpringMVC, Mybatis est une bonne solution d'intégration simple qui peut répondre aux besoins généraux du projet. Partagez les fichiers de configuration du projet pendant votre temps libre pour votre référence:
1. Premièrement, jetons un coup d'œil à la dépendance Pom:
<! - Spring -> <Dedency> <GroupId> org.springFramework </rom grouped> <ArtifActid> printemps-core </ artifactid> <version> $ {printemps.version} </-version> </pedency> <dependency> <proupId> org.springframework </proupId> <ArtifActid> Spring Beans </trifactid> <version> $ {printemps.version} </ version> </dependency> <dependency> <proupId> org.springFramework </proupId> <ArtifActid> Spring-Context </ ArtifactId> <De version> $ {Spring.Version} </ version> </ Dependency> <Dedidency> <ProupId> ORG.SPRINGFRAMEWRAWNWORK </ GroupId> <ArtefactId> Spring-Tx </ ArfactId> <Dersion> $ {printemps.version} </ version> </ Dependency> <Dedency> <ProupId> org.springFramework </proupId> <ArtefactId> Spring-Web </ ArtifactId> <Desentency> $ {printemps.version} </ version> </pedency> <dependency> <GroupId> org.springframework </proupId> <Artifactid> printemps-webmvc </ artifactid> <version> $ {printemps.springframework </pruidency> <pedigency> <proupId> org.springframework </proupId> <Artifactid> Spring-jdbc </pterifactid> </Dependency> <Dedency> <ProupId> org.springFramework </rom grouped> <ArtifActid> printemps-test </ artifactid> <version> $ {printemps.version} </-version> <cope> Test </cope> </pedidency> <! - Mybatis Pack <ArtefactId> Mybatis </ artifactid> <version> 3.2.8 </ version> </dependency> <! - Mybatis Spring Plug-in -> <dependency> <proupId> org.mybatis </proncId> <ArtifActid> Mybatis-Spring </ artifactid> <version> 1.2.2 </De version> </Depend> <! <GroupId> MySQL </rom grouped> <ArtifActid> MySQL-Connector-Java </ ArtifactId> <De version> 5.1.34 </ Version> </ Dependency> <! - Source de données -> <Dendency> </proupId> com.alibaba </prouvendid> <etifactid> duid </ptetifactid> <version> 1.0.12 </ version> </pterence> </ptecid> <version> 1.0.12 <12 <GroupId> org.AspectJ </proupId> <Artifactid> AspectJwweaver </ ArtifactId> <DERVIÈRE> 1.8.4 </DERNIERSE> </ Dependency> <! - Log4j -> <Dependance> <ProupID> LOG4J </rouped> <ArtifActid> Log4j </ Artifactid> <version> 1.2.17 </DERNIERSE> <GroupId> javax.servlet </prouprid> <Artifactid> servlet-api </ artifactive> <version> 3.0-alpha-1 </ version> </pedigency> <dependency> <proupId> javax.servlet </prouprid> <ptefactid> JSTL </ artifactid> <version> 1.2 </ version> </dependency> <GroupId> org.codehaus.jackson </rompuprid> <Artifactid> Jackson-Mapper-Asl </ ArtifactId> <Dersion> 1.9.13 </ Version> </ Dependency> <Dendency> <ProupId> com.alibaba </prouvenid> <esttifactid> FastJson </ artifactid> <version> 1.2.3 </Dero version> <Dependance> <Dedency> <proupId> com.fasterxml.jackson.core </proupId> <ErtifactId> Jackson-Annotations </Retifactid> <De version> $ {jackson.fasterxml.jackson.core </peechid> <proupdid> comi.fasterxml.jackson.core </proupId> <ArtifActid> jackson-core </tifactID> <version> $ {jackson.version} </ version> </ dépendance> <dependency> <proupId> com.fasterxml.jackson.core </proupId> <Artifactid> Jackson-databind </ artifactid> <version> $ {jackson.version} </-version> </Dedency> <! - File upload -> <pedency> <ArtefactId> Commons-io </ artifactId> <DERSE> 2.4 </ version> </Dependency> <Dependance> <GroupId> Commons-fileupload </rom grouped> <Artifactid> commons-fileupload </retifactid> <version> 1.2.2 </-version> </pedidency>Spring utilise la version 4.1.4, et nous pouvons choisir la version qui nous convient en fonction des besoins du système.
2. Fichiers de configuration connexes:
a) printemps.xml
<? xml version = "1.0" encoding = "utf-8"?> <beans xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://www.w3.org/2001/xmlschema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd "> <! - introduire le fichier de configuration des propriétés -> <Context: Automathander @crasspath: config.properties" / <! l'injecte en bean -> <contexte: composant-scan basage-package = "com.demo.report.web.service" />
b) printemps-mvc.xml
<? xml version = "1.0" encoding = "utf-8"?> <beans xmlns = "http://www.springframework.org/schema/beans" xmlns: mvc = "http://www.springframework.org/schema/mvc" 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.springframework.org/schema/beans http://www.springframework.org/schema/beans/springframeworks-4.1.xssd http://www.springframework.org/schema/contex http://www.springframework.org/schema/context/spring-context-4.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring Analysez toutes les classes dans le package du contrôleur. Si @Controller injecté sous le nom de Bean -> <context: composant-scan Base-Package = "com.demo.Report.web.Controller" /> <! - Évitez de télécharger des fichiers lorsque IE exécute Ajax, retournez à JSON -> <propriété ID = "MappingJackSonHSO <value> text / html; charset = utf-8 </value> </sist> </ propriété> </ank> <! - Démarrez la fonction d'annotation de Spring MVC pour compléter la cartographie des demandes et annotation Pojos -> <an Bean> <propriété Name = "MessageConverters"> <Sist> <! - JSON Converter -> <Ref Bean = "MAPPINGJACKSONHSONHSONHSON" </ list> </ propriété> </ bean> <! - Analyse du nom de la vue du modèle, c'est-à-dire, ajoutant le préfixe au nom de la vue du modèle -> <ean> <propriété name = "ViewClass" value = "org.springframework.web.servlet.view.jstlview" /> <propriété name = "prefix" value = <!! Multi-fichier upload <bean id = "MultipartResolver"> <propriété name = "Defatencecoding"> <value> utf-8 </value> </ propriété> <propriété name = "MAXUPLOADSIZE"> <VALANT> 32505856 </value> </ propriété> <propriété Name = "MAXINMEMORYSIZE"> <Value> 4096 </value> <prewetfot
c) printemps-mybatis.xml
<? xml version = "1.0" encoding = "utf-8"?> <beans xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://www.w3.org/2001/xmlschema-instance" xmlns: tx = "http://www.springframework.org/schema/tx" xmlns: aop = "http://www.springframework.org/schema/aop" xsi: schemalation = "http://www.spring http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsdd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd "> <! name = "dataSource" init-method = "init" destroy-méthod = "close"> <propriété name = "url" value = "$ {jdbc.url}" /> <propriété name = "username" value = "$ {jdbc.passwame}" /> <propriété name = "mot de passe" name = "initialSize" value = "0" /> <! - Nombre maximum de connexions utilisées par le pool de connexions -> <propriété name = "maxactive" value = "20" /> <! - Minimum Free Connections -> <propriété name = "MINIDLE" Value = "0" /> <! - Obtenez le maximum de connexion -> <propriété name = "maxwait" value = "60000" /> <propriété = "PoolParred) Value = "true" /> <propriété name = "MaxPoolPreparedStationPerConnectionsize" value = "33" /> <! - Utilisé pour détecter SQL valide -> <propriété name = "ValidationQuery" value = "$ {validationQuery}" /> < name = "Test WhileIdle" value = "true" /> <! - Configurez le temps qu'il faut pour effectuer un intervalle de détection pour détecter la connexion inactive qui doit être fermée, en millisecondes -> <propriété name = "TimebetweenEvictionRunsmillis" Value = "60000" /> <! name = "MineVictableIdleTimemillis" Value = "25200000" /> <! - Activez la fonction de removeAbandOned -> <propriété name = "RemoveAbandOned" value = "true" /> <! - 1800 secondes, c'est-à-dire 30 minutes -> <propriété Name = "RemoveAbandonEdTimeout" Value = "1800" /> <! name = "logabandoned" value = "true" /> <! - Base de données de surveillance -> <propriété name = "filters" value = "Mergestat" /> </Ean> <! - MyBatis Fichier -> <bean id = "SQLSessionFactory"> <propriété name = "DataSource" Réfr. "DataSource" -> <propriété name = "mapperlocations" value = "classpath: com / démo / report / web / mapper / *. xml" /> </ank> <ean> <propriété name = "baspackage" value = "com.feidai.report.web.mapper" /> <propriété name = "sqlsessionfactoryBeName" value = "sqlssion Transaction Manager -> <bean id = "TransactionManager"> <propriété name = "dataSource" ref = "dataSource" /> </ban>d) web.xml
<splay-name> printempsmvc_mybatis_demo </ display-name> <ftext-param> <param-name> contextConfiglocation </ param-name> <param-value> classpath: printemps.xml, classpath: spring-mybatis.xml </ param-value> </ptext-patam> <mybatis> <fileter-name> encodingfilter </ptext-name>> <filter> <fileter-name> ENCODINGERS </fettef-Param> <filter> <Filter-Class> org.springFramework.web.filter.CaracTerencodingFilter </ Filter-Class> <Init-Param> <Amam-Name> Encoding </ Param-Name> <Anit-Value> UTF-8 </ Param-Value> <Am param-Value> true </ Param-Value> </Init-Param> </ Filter> <Imlter-Mapping> <Lifter-Name> EncodingFilter </filter-Name> <Url-Pattern> / * </ url-Pattern> </ Fileter-Mapping> <Deurner> <écouteur-Class> Org.Sprier-Cramework.Web.ConText.ConText.ConText. </dinener> <! - Empêcher Spring Memory Overflow auditeur -> <ouvoiner> <auditeur-class> org.springframework.web.util.introspectorcleanupListener </ auteur-class> </diner> <vrlet> <description> Spring MVC Servlet </, description> </ servlet> repos </ servlet-name> <Serplet-Class> org.springframework.web.servlet.dispatcherServlet </vrlett-Class> <Init-Param> <Amam-Name> ContextConfiglocation </ Param-Name> <AmArd-Value> ClassPath: Spring-Mvc.xml </ param-Value> </Init-Param> <Lo dans le startup> <Serplet-mapping> <servlet-mapping> <servlet-name> rest </ serplet-name> / </url-potern> </ servlet-mapping> <serplet> <servlet-name> druidstatview </ servlet-name> <Serplet-Class> com.alibaba.druid.support> <Servlet-Masing> <Vertlet-Name> DruidStatView </ Servlet-Name> <Url-Pattern> / Druid / * </rurl-Pattern> </ Servlet-Mapping> <! - Configurer le délai de session, Minutes de l'unité -> <ession-Config> <Session-Timeout> 30 </ Session Timeout> </ Session-Config> </vendule-list> <leendage-file> INDEX.JSP </ Welcome> </ Welcome-File-list>
Utilisé la source de données Druid, veuillez vous référer au code pour une configuration détaillée sur le Web.
Ce qui précède est un résumé des informations sur la configuration d'intégration SpringMVC MyBatis. Nous continuerons d'ajouter des informations pertinentes à l'avenir. Merci pour votre soutien pour ce site Web!