تشترك هذه المقالة في المقالة الثانية لنظام إدارة مكتبة المكتبة للرجوع إليه. المحتوى المحدد كما يلي
الخطوة 1: إضافة ملف تكوين قاعدة البيانات
JDBC.Properties
# database driver jdbc.driver = com.mysql.jdbc.driver # عنوان قاعدة البيانات jdbc.url = jdbc: mysql: // localhost: 3306/library؟ useUnicode = true & paractionoding = utf-8 # username MaxActive = 20 # الحد الأقصى لاتصال الخمول maxidle = 20 # اتصال الخمول minidle = 1 # وقت الانتظار maxwait = 60000
الخطوة 2: إضافة ملف تكوين MyBatis
mybatis-config.xml
<؟ getGeneratedKeys من JDBC للحصول على المفتاح الأساسي-> <setting name = "useGeneratedKeys" value = "true"/> <!-استبدل أسماء الأعمدة بالمستعار ، ture الافتراضي-> <setting name = "usecolabel" value = "true"/> <! </configuration>
الخطوة 3: إضافة ملف تكوين الربيع
قم بإنشاء ملفين جديدين في دليل الموارد/الربيع:
│ └ الربيع
│ ├ Spring-mybatis.xml
│ ├ spring-service.xml
│ └ spring-mvc.xml
spring-mvc.xml
<؟ xmlns: p = "http://www.springframework.org/schema/p" http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context-context http: http://www.springframework.org/schema/mvc -> <mvc: معالج الخدمات الافتراضي/> <!-تمكين وضع التعليق التوضيحي-> <mvc: يحركه التعليقات التوضيحية> <mvc: message-converters> <boan> <property name = "uppededediTypes"> <list> <! <Value> text/html ؛ charset = utf-8 </value> <value> application/json ؛ charset = utf-8 </value> </list> </property> </bean> </mvc: message-converters> </mvc: endive-driven> <! <!-لاحقة-> <property name = "FASEIX" value = ".
Spring-mybatis.xml
<؟ xmlns: context = "http://www.springframework.org/schema/context" xmlns: tx = "http://www.springframework.org/schema/tx http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/spring-3 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd "> <!-1. تكوين المعلمات المعتمدة Database- تكوين Druid Data Source-> <bean id = "dataSource" init-method = "init" DRIDED-METHOD = "CLOSE"> <!-تكوين خصائص تجمع الاتصال-> <property name = "driverClassName" value = "$ {jdbc.driver}"/> <property name = "$ {jdbctl} value = "$ {jdbc.username}"/> <property name = "password" value = "$ {jdbc.password}"/> <!-تكوين حجم التهيئة ، الحد الأدنى ، القيمة القصوى-> <اسم property = "initialsize" مهلة انتظار الاتصال-> <property name = "maxwait" value = "10000"/> <!-تكوين المدة التي يستغرقها إجراء فاصل زمني للكشف ، ويتطلب الكشف إغلاق اتصال الخمول بالمللي ثانية-> <property name = "timeBetweenevictionRunsmillis" value = "60000" name = "minevictableDleTleMemillis" value = "300000" /> <!-SQL التي تتحقق من أن الاتصال صالح ، فإن تكوينات البيانات المختلفة مختلفة-> <property name = "ValideDquery" value = "SELECT 1" /> <! value = "true"/> <!-يوصى بتكوينه على أنه صحيح هنا لمنع الاتصال المسترجع من كونه غير متوفر-> <property name = "testOnborrow" value = "true"/> <propert name = "poolpreparedStatements" value = "true"/> <property name = "maxPoolPrepedStateMentPerConnectionSize" value = "20"/> <!-تكوين طريقة التقديم هنا ، فإن الافتراضي هو صحيح ، يمكنك الاستغناء عنه- value = "stat"/> </bean> <!-3. تكوين myBatis 'sqlSessionFactory Object-> <bean id = "sqlsessionfactory"> <!-تكوين ملف التكوين العالمي myBatis-> <property name = "configlocation" value = "classpath: mybatis-config.xml"/> <! ref = "datasource"/> <!-مسح ملف التكوين-> <property name = "mapperlocations" value = "classpath: mapping/*. name = "basePackage" value = "com.ray.dao"/> </bean> </bans>الربيع service.xml
<؟ xmlns: context = "http://www.springframework.org/schema/context" xmlns: tx = "http://www.springframework.org/schema/tx http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd "> <!-المسح التلقائي-> <context: component-scan package = <property name = "dataSource" ref = "datasource"/> </bean> <!-قم بتشغيل دعم التعليقات التوضيحية للتحكم في المعاملة-> <tx: معاملة معاملة تعليمية التعليقات التوضيحية = "TransactactionManager"/> </bans>
الخطوة 4: إضافة ملف تكوين الظهور
تكوين Logback أبسط من Log4J ، والوظائف متشابهة
├ الموارد
│ ├ Logback.xml
قم بإنشاء ملف جديد في مجلد الموارد: logback.xml
<؟ طباعة سجلات في وحدة التحكم-> <root level = "debug"> <appender-ref ref = "stdout"/> </rout> </isplicuration>
الخطوة 5: تكوين web.xml
web.xml
<web-app xmlns = "http://xmlns.jcp.org/xml/ns/javaee" XSI: schemalocation = "http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns الإصدار = "3.1" metadata-complete = "true"> <dishing-name> تم إنشاء نوع ويب تم إنشاؤه </display-name> <!-تكوين dispatcherservlet-> <vishlet> <Servlet-name> seckill-dispatcher </servlet-name> يتم تحميلها لـ springmvc spring-dao.xml ، spring-service.xml ، spring-web.xml mybatis-> spring-> springmvc-> <Ing-param> <param-name> contextConfiglocation </ipar-name> <load-on-startup> 1 </load-on-startup> <surededed> true </async-sucueded> </servlet> <Sradlet-mapping> <Sradlet mapping> <Url-name> seckill-dispatcher </servlet-name> <!- garbled-> <livers> <filter-name> nareerencodingfilter </filter-name> <ilter-class> org.springframework.web.filter.characterencodingfilter </firlue-plater> <Ing-param> <Ind-name> الترميز </param-name> <param-value> </filter> <filter-mapping> <filter-name> nAffleenCodingFilter </filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
هيكل المشروع:
ما سبق هو كل محتوى هذه المقالة. آمل أن يكون ذلك مفيدًا لتعلم الجميع وآمل أن يدعم الجميع wulin.com أكثر.