단순성의 아름다움, SpringMVC, Mybatis는 일반적인 프로젝트 요구를 충족시킬 수있는 좋은 간단한 통합 솔루션입니다. 여가 시간에 참조를 위해 프로젝트 구성 파일을 공유하십시오.
1. 첫째, 의존성 POM을 살펴 보겠습니다.
<!- 봄 -> <pectionency> <groupId> org.springframework </groupid> <artifactid> 스프링 코어 </artifactid> <버전> $ {spring.version} </version> </fectionency> <pectionency> <groupId> org.springframework </groupid> <artifactid> 스프링 벡스 </artifactid> <버전> $ {spring.version} </version} </version> </fectionency> <de Pendency> <groupid> org.springframework </groupid> <artifactid> spring-context </artifactid> <버전> $ {spring.version} </version} </version </fectionency> <dep Endency> <groupid> org.springframework </groupid> <artifactid> spring-tx </artifactid> <버전> $ {spring.version} </version> </fectionency> <종속 cy> <groupid> org.springframework </groupid> <artifactid> spring-web </artifactid> <버전> $ {spring.version} </version} </version> </fectionency> < GroupId> org.springframework </groupid> <artifactid> spring-webmvc </artifactid> <버전> $ {spring.version} </version> </fectionency> <pectionency> <gr oupid> org.springframework </groupid> <artifactid> spring-jdbc </artifactid> <버전> $ {spring.version} </version> </fectionency> <ceptency> <groupi d> org.springframework </groupid> <artifactid> spring-test </artifactid> <bersion> $ {spring.version} </version> <cope> test </scope> </fectionency> <!- mybatis 패키지-> <pectionency> <groupid> org.mybatis </groupid> <artifactid> mybatis </artifactid> <버전> 3.2.8 </version> </fectionency> <!-Mybatis spring 플러그인-> <ceptency> <groupid> org.mybatis </groupid> <artifactid> mybatis-spring </artifactid> <버전> 1.2.2 </version> </fectionency> <!-mysql 연결 -> <pectionency> <groupId> mySQL </groupId> <artifactID> mySQL-connector-java </artifactid> <버전> 5.1.34 </version> </fectionency> <!-데이터 소스-> <pectionency> <groupId> com.alibaba </groupId> <artifactid> druid </artifactid> <버전> 1.0.12 </version> </dependency> <pectionement> <groupid> org.aspectj </groupid> <artifactid> sagneweaver </artifactid> 1.8.4 </version> <! -> <pectionency> <groupId> log4J </groupId> <artifactid> log4J </artifactid> <2.17 </version> </fectionency> <!-서블릿 -> <pectionency> <groupId> javax.servlet </groupId> <artifactid> servlet-api </artifactid> <bersion> 3.0-alpha-1 </version> </dependency> <groupID> javax.servlet </groupid> <artifactid> jstl </artifactid> 1.2 </version> 1. -> <pectionency> <groupId> org.codehaus.jackson </groupid> <artifactid> Jackson-Mapper-Asl </artifactid> <bersion> 1.9.13 </version> </fectionency> <pectomency> <groupid> com.alibaba </grou pid> <artifactid> fastjson </artifactid> <bersion> 1.2.3 </version> </dependency> <pectomency> <groupid> com.fasterxml.jackson.core </groupid> <artifactid> jackson-nantations </artifactid > <버전> $ {jackson.version} </version> </dectomency> <pectionency> <groupid> com.fasterxml.jackson.core </groupid> <artifactid> jackson-core </artifactid> <버전> $ {jackson.version} < /version>/dependency> <dependency><<<<<<<<<<<<<<<<<< groupid>com .fasterxml.jackson.core</groupid> artifactid> jackson-databind</artifactid> assion> {Jackson.version }</version></dependency><! 파일 업로드-> <pectionency> <groupId> Commons-IO </groupId> <ArtifactID> Commons-IO </artifactId> <버전> 2.4 </version> </fectionency> <groupIdency> <groupId> commons-fileupload </groupid> <artifactid> commons-fileupload </artifactid> 1.2 </repontement>Spring은 버전 4.1.4를 사용하며 시스템의 요구에 따라 우리에게 적합한 버전을 선택할 수 있습니다.
2. 관련 구성 파일 :
a) spring.xml
<? xml 버전 = "1.0"alcoding = "utf-8"?> <beans xmlns = "http://www.springframework.org/schema/beans"xmlns : xsi = "http://ww.w.w3.org/2001/xmlschema-instance" xmlns : context = "http://www.springframework.org/schema/context"xsi : schemalocation = "http://www.springframework.org/schema/beanshttp://www.s pringframework.org/schema/beans/spring-beans-4.1.xsdhttp://www.springframework.org/schema/context/spring-context-4.1.xsd">!--introducting 구성 속성 파일-> <context : property-placeher location = "classPath : config.Properties" /> <!-@Service가 포함 된 자동 스캔 @Service를 bean에 주입합니다-> <context : component-scan base-package = "com.demo.report.web.service" />
b) 스프링 -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/schema/scremans/spred-beans- http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd"><! @Controller가 bean-> <context : component-scan base-package = "com.demo.report.web.controller" /> <!-즉, ajax를 실행할 때 다운로드 파일을 피하십시오. id = "Mapping JacksonhttpMessageConverter"class = "org.springframework.http.converter.json.mappingjackson2httpmessageconverter"> <property name = "supportedMediaTypes"> <list> <value> text/html; charset = utf-8 </value> </vally> </ban MVC annotation function to complete the mapping of requests and annotations POJOs--><beanclass="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"><property name="messageConverters"><list><!-- json converter--><ref bean="mappingJacksonHttpMessageConverter" /> </list> </property> </bean> <!-모델보기 이름을 해결합니다. /> <property name = "prefix"value = "" /> <property name = "접미사"value = " /> < /bean> <!-멀티 파일 업로드 <bean id ="multipartresolver "class ="org.springframework.web.multipart.commons.commonsmultipartresolver "> < 이름 = "DefaultEncoding"> <aluff-8 </value> </value> </property> <property name = "maxuploadsize"> <value> 32505856 </value> </property> <property name = "maxinmemorysize"> 4096 </value> </property> </bans>
c) Spring-mybatis.xml
<? xml 버전 = "1.0"alcoding = "utf-8"?> <beans xmlns = "http://www.springframework.org/schema/beans"xmlns : xsi = "http://ww.w.w3.org/2001/xmlschema-instance" xmlns : tx = "http://www.springframework.org/schema/tx"xmlns : aop = "http://www.springframework.org/schema/aop"xsi : schemalocation = "http://www.springframwork.org/schema/schema/springwork.org/schema/schemas http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/sprring-44.1.ced http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd예. 이름 = "dataSource"init-method = "init"destroy-method = "close"> <property name = "url"value = "$ {jdbc.url}" /> <property name = "username"value = "$ {jdbc.username}" /> <property name = "password"value ""$ {jdbc.username {jdbc.username}. 이름 = "이니셜 크기"값 = "0" /> <!-연결 풀에 사용 된 최대 연결-> <속성 이름 = "maxActive"value = "20" /> <!-최소 무료 연결-> <속성 이름 = "minidle"value = "0" /> <!-<속성 이름 = "maxWait" "maxWait" "600" />>>>>>>>>> <! value = "true" /> <property name = "maxpoolpreparedStatementperConnectionsize"value = "33" /> <!-유효한 sql을 감지하는 데 사용됩니다-> <property name = "validationQuery"value = "$ {validationQuery}" /> <속성 이름 = "testonborr"value = "false"<property <property <value " /> <속성. 이름 = "testwhileIdle"value = "true" /> <!-밀리 초로 닫아야하는 유휴 연결을 감지하는 데 테스트를 수행하는 데 걸리는 시간-> <property name = "timebetweenevictionRunsmillis"value = "60000" /> <!-수영장에서 생존하기위한 최소 시간을 구성하십시오. 이름 = "MineVictableIdleTimemIllis"value = "25200000" /> <!-제거 기능-> <속성 이름 = "removeaBandOned"value = "true" /> <!-1800 초, 30 분-> <속성 이름 = "removebandonedTimeout"value = "1800" /> <!-< name = "logabandoned"value = "true" /> <!-모니터링 데이터베이스-> <속성 이름 = "필터"value = "mergestat" /> < /bean> <!-mybatis 파일-> <bean id = "sqlsession actory"> <property name = "dataSource"ref = "dataSource" /> <! configuration.xml-> <속성 이름 = "mapperlocations"value = "classpath : com/demo/report/web/web/mapper/*. xml"/> </bean> <ean> <ean> <property name = "basepackage"value = "com.feidai.report.web.mapper"/> /> < /bean> <!-트랜잭션 관리자 구성-> <bean id = "transactionManager"class = "org.springframework.jdbc.datasource.datasourcetransactionManager"> <property name = "ref ="dataSource " /> < /boan>d) web.xml
<display-name> springmvc_mybatis_demo </display-name> <countxt-param> <param-name> contextConfigLocation </param-name> <param- value> classpath : spring.xml, classpath : spring-mybatis.xml </param-val ue> </context-param> <filter> <filter-name> encodingfilter </filter-name> <filter-class> org.springframework.wilter.characterencodingfilter </filter-class> <init-param> <param-name> encoding </p aram-name> <param- value> utf-8 </param-value> </init-param> <init-param> <apar-name> forceencoding </param-name> <param- value> true </param-value> </init-param> </filter> <filter-mapping> <filter-name > EncodingFilter </filter-name> <Url-pattern>/*</url-pattern> </filter-mapping> <layer> <layer-class> org.spramework.web.context.contextloaderListener </hareser-class> </hareser> <!- 오버 플로우 리스너에서 스프링 메모리 방지-> <layer> <Leater-Class> org.springframework.web.util.introspectorcleanUplistener </hareser-class> </laiseer> <servlet> <description> Spring MVC Servlet </descript> <servlet-name> REST </servlet-name> <Servlet-class> org.springframework.web.servlet.dispatcherServlet </servlet-class> <init-param> <param-name> conte 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-pattern>/</url-pattern> </servlet-mapping> <servlet> <servlet-name> druidstatview </servlet-name> <servlet-class> com.alibaba.druid.support .http.StatViewServlet </servlet-class> </servlet> <servlet-mapping> <servlet-name> druidstatview </servlet-name> <url-pattern>/druid/*</url-pattern> </servlet-mapping> <!- 세션 시간 초과 시간, 단위 분-> <세션 -Config> <Session-TimeOut> 30 </session-timeout> </session-config> <Welcome-File-List> <welcome-file> index.jsp </welcome-file-list>를 구성하십시오
DRUID 데이터 소스를 사용한 경우 웹에서 자세한 구성은 코드를 참조하십시오.
위는 편집기가 소개 한 SpringMVC 및 MyBatis의 통합 구성 예에 대한 자세한 설명입니다. 나는 그것이 당신에게 도움이되기를 바랍니다. 궁금한 점이 있으면 메시지를 남겨주세요. 편집자는 제 시간에 답장을 드릴 것입니다. Wulin Network 웹 사이트를 지원해 주셔서 대단히 감사합니다!