ความงามของความเรียบง่าย, SpringMVC, MyBatis เป็นโซลูชันการรวมที่ดีที่สามารถตอบสนองความต้องการของโครงการทั่วไปได้ แชร์ไฟล์การกำหนดค่าโครงการในเวลาว่างสำหรับการอ้างอิงของคุณ:
1. ก่อนอื่นมาดู POM ที่พึ่งพา:
<!-ฤดูใบไม้ผลิ-> <การพึ่งพา> <roupId> org.springframework </groupId> <ratifactId> Spring-core </artifactid> <persion> $ {spring.version} </เวอร์ชัน> </predency> <cerson> $ {spring.version} </version> </การพึ่งพา> <การพึ่งพา> <loupId> org.springframework </groupId> <ratifactid> Spring-context </artifactid> <version> $ {Spring.version} </เวอร์ชัน> <ArtIfactId> Spring-Tx </artifactId> <persion> $ {Spring.version} </เวอร์ชัน> </การพึ่งพา> <การพึ่งพา> <roupId> org.springframework </groupId> <atifactid> Spring-Web </artifactid> <RoupID> org.springframework </groupId> <ratifactId> Spring-Webmvc </ArtifactId> <Sersion> $ {Spring.Version} </เวอร์ชัน> </การพึ่งพาอาศัย> <predency> <ratrid> org.springFramework </permentency> <การพึ่งพา> <roupId> org.springframework </groupId> <ratifactId> การทดสอบฤดูใบไม้ผลิ </artifactId> <cersion> $ {Spring.version} </เวอร์ชัน> <pope> ทดสอบ </pope> </การพึ่งพาอาศัยกัน> <! <ArtIfactId> myBatis </artifactId> <persion> 3.2.8 </เวอร์ชัน> </การพึ่งพา> <!-ปลั๊กอินสปริง mybatis-> <predency> <roupid> org.mybatis </groupid> <RoupID> mySQL </groupId> <ratifactId> mysql-connector-java </artifactid> <version> 5.1.34 </เวอร์ชัน> </การพึ่งพา> <!-แหล่งข้อมูล-> <predency> <roupId> org.aspectj </groupId> <ratifactid> AppistjWeaver </artifactid> <cersion> 1.8.4 </เวอร์ชัน> </การพึ่งพาอาศัย> <!-log4j-> <cendency> <roupid> log4j </groupid> <roupId> javax.servlet </groupId> <ratifactid> servlet-api </artifactid> <cersion> 3.0-alpha-1 </version> </การพึ่งพา> <การพึ่งพา> <roupid> javax.servlet </groupid> <RoupID> org.codehaus.jackson </groupId> <ratifactid> Jackson-Mapper-Asl </artifactid> <persion> 1.9.13 </version> </การพึ่งพา> <การพึ่งพา> <roupid> com.alibaba </groupid> <RoupID> com.fasterxml.jackson.core </groupId> <ratifactid> Jackson-Annotations </artifactid> <persion> $ {Jackson.version} </senture> </perctive> <Sersion> $ {Jackson.Version} </Sident> </การพึ่งพา> <การพึ่งพา> <roupId> com.fasterxml.jackson.core </groupid> <ratifactid> Jackson-Databind </artifactid> <ArtIfactId> Commons-io </artifactId> <sersion> 2.4 </เวอร์ชัน> </การพึ่งพาอาศัย> <การพึ่งพา> <roupId> Commons-FilePilePload </groupId>สปริงใช้เวอร์ชัน 4.1.4 และเราสามารถเลือกรุ่นที่เหมาะสมกับเราตามความต้องการของระบบ
2. ไฟล์การกำหนดค่าที่เกี่ยวข้อง:
a) Spring.xml
<? xml version = "1.0" การเข้ารหัส = "utf-8"?> <beans xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://ww.w3.org/2001/xml xmlns: context = "http://www.springframework.org/schema/context" xsi: schemalocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd "> <! @Service ฉีดเข้าไปในถั่ว-> <บริบท: Component-Scan base-base-package = "com.demo.report.web.service" />
B) Spring-MVC.XML
<? xml version = "1.0" การเข้ารหัส = "utf-8"?> <beans xmlns = "http://www.springframework.org/schema/beans" xmlns: mvc = "http://ww.springframework xmlns: xsi = "http://www.w3.org/2001/xmlschema-instance" xmlns: p = "http://www.springframework.org/schema/p" xmlns: บริบท = "http:/ XSI: schemalocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframwork http://www.springframework.org/schema/context/spring-context-4.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/scthema <!- สแกนคลาสทั้งหมดภายใต้แพ็คเกจคอนโทรลเลอร์โดยอัตโนมัติ ถ้า @controller ฉีดเป็นถั่ว-> <บริบท: คอมโพเนนต์-สแกนฐานแพคเกจ = "com.demo.report.web.controller" /> <!-หลีกเลี่ยงการดาวน์โหลดไฟล์เมื่อ IE เรียกใช้ Ajax กลับไปที่ JSON-> <value> text/html; charset = utf-8 </value> </list> </property> </ebean> <!-เริ่มฟังก์ชั่นคำอธิบายประกอบของสปริง MVC เพื่อทำการแม็พของคำขอและคำอธิบายประกอบ Pojos-> <bean> Bean = "MappingjacksonhttpmessageConverter"/> </list> </property> </ebean> <!-การแยกวิเคราะห์ชื่อมุมมองโมเดลนั่นคือการเพิ่มคำนำหน้าลงในชื่อมุมมองของรุ่น-> <bean> value = "/> <property name =" suffix "value =" "/> </ebean> <!-กำหนดค่าการอัปโหลดหลายไฟล์ <bean id =" MultipartResolver "> <property name =" DefaultEncoding "> <value> UTF-8 </value> name = "MaxinMemorySize"> <value> 4096 </value> </property> </ebean>-> </ebeans>
c) Spring-mybatis.xml
<? xml version = "1.0" การเข้ารหัส = "utf-8"?> <beans xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://ww.w3.org/2001/xml xmlns: tx = "http://www.springframework.org/schema/tx" xmlns: aop = "http://www.springframework.org/schema/aop" xsi: schemalocation = "http:/ http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/tx http://ww.springframework http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1. แหล่งที่มา-> <bean name = "dataSource" init-method = "init" destroy-method = "close"> <property name = "url" value = "$ {jdbc.url}" /> <property name = "username" value = "$ {jdbc.username}" /> < <property name = "ค่าเริ่มต้น" value = "0" /> <!-จำนวนการเชื่อมต่อสูงสุดที่ใช้โดยพูลการเชื่อมต่อ-> <ชื่อคุณสมบัติ = "maxactive" value = "20" /> <!-การเชื่อมต่อฟรีขั้นต่ำ-> <property name = "minidle" value = "0" /> <! value = "true" /> <property name = "MaxPoolPreparedStatementPerConnesionesize" value = "33" /> <!-ใช้เพื่อตรวจจับ SQL ที่ถูกต้อง-> <ชื่อคุณสมบัติ = "ValidationQuery" value = "$ {ValidationQuery}" NAME = "TESTHALLYIDLE" value = "true" /> <!-กำหนดค่าระยะเวลาในการดำเนินการตรวจจับช่วงเวลาเพื่อตรวจจับการเชื่อมต่อที่ไม่ได้ใช้งานที่ต้องปิดในมิลลิวินาที-> <ชื่อทรัพย์สิน = name = "minevictableidletimeMillis" value = "25200000" /> <!-เปิดฟังก์ชั่น removeAbandOned-> <property name = "removeAbandOned" value = "true" /> <!-1800 วินาทีนั่นคือ 30 นาที-> <คุณสมบัติ name = "logabandoned" value = "true" /> <!-ฐานข้อมูลการตรวจสอบ-> <ชื่อคุณสมบัติ = "ตัวกรอง" value = "merestat" /> </ebean> <!-ไฟล์ mybatis-> <bean id = "sqlsessionfactory" configuration.xml -> <property name = "mapperlocations" value = "classpath: com/demo/report/web/mapper/*. xml"/> </ebean> <bean> <property name = "basepackage" value = "com.feidai.report.web.mapper"/> </ebean> <!-กำหนดค่าตัวจัดการธุรกรรม-> <bean id = "transactionManager"> <property name = "DataSource" ref = "DataSource"/> </ebean>d) web.xml
<pramplay-name> springmvc_mybatis_demo </display-name> <context-param> <param-name> contextconfiglocation </param-name> <param-value> classpath: spring.xml, classpath: spring-mybatis.xml </param-value> <Tilter-class> org.springframework.web.filter.characterencodingFilter </filter-class> <init-Param> <param-name> การเข้ารหัส </param-name> <param-value> UTF-8 </param-value> <param-value> True </param-value> </init-param> </filter> <filter-mapping> <filter-name> encodingFilter </filter-name> <url-pattern>/*</url-pattern> <Sistener-class> org.springframework.web.context.contextloaderlistener </listener-class> </listener> <!-ป้องกันไม่ให้หน่วยความจำฤดูใบไม้ผลิผู้ฟัง-> <sistener> servlet </คำอธิบาย> <servlet-name> REST </servlet-name> <servlet-lass> org.springframework.web.servlet.dispatcherservlet </servlet-lass> <init-param> <param-name> contextconfiglocation </param-name> <param-calue> <load-on-startup> 1 </load-on-startup> </servlet> <servlet-mapping> <servlet-mapping> <servlet-name> rest </servlet-name>/</url-pattern> </servlet-mapping> <servlet> <servlet-class> com.alibaba.druid.support.http.statviewservlet </servlet-class> </servlet> <servlet-mapping> <servlet-name> druidstatview </servlet-name> <session-config> <session-timeout> 30 </session-timeout> </session-config> <welcome-file-list> <welcome-file> index.jsp </welcome-file>
ใช้แหล่งข้อมูล DRUID โปรดดูรหัสสำหรับการกำหนดค่าโดยละเอียดในเว็บ
ข้างต้นเป็นบทสรุปของข้อมูลเกี่ยวกับการกำหนดค่าการรวม SpringMVC MyBatis เราจะยังคงเพิ่มข้อมูลที่เกี่ยวข้องในอนาคต ขอบคุณสำหรับการสนับสนุนเว็บไซต์นี้!