In diesem Artikel wird der zweite Artikel des Bibliothekssystem -Bibliotheksverwaltungssystems für Ihre Referenz berichtet. Der spezifische Inhalt ist wie folgt
Schritt 1: Fügen Sie die Datenbankkonfigurationsdatei hinzu
jdbc.properties
# Database driver jdbc.driver=com.mysql.jdbc.Driver # Database address jdbc.url=jdbc:mysql://localhost:3306/library?useUnicode=true&characterEncoding=UTF-8 # Username jdbc.username=root # Password jdbc.password=root # Initialize connection initialSize=0 # Maximum number of Verbindungen MaxActive = 20 # Maximale Leerlaufverbindung Maxidle = 20 # minimaler Leerlaufanschluss Minidle = 1 # Zeitüberschreitungszeit Maxwait = 60000
Schritt 2: MyBatis -Konfigurationsdatei hinzufügen
mybatis-config.xml
<? JDBCs GetGeneratedKeys, um den Primärschlüssel zu erhalten-> <Einstellungsname = "useGeneratedKeys" value = "true"/> <!-Ersetzen Sie die Spaltennamen durch einen Alias, Standard-Ture-> <Einstellungsname = "usecolumnLabel" value = "true"/> <!-Turn-Einsteuerungs-Konvertieren-> <Seting-Name ". </Konfiguration>
Schritt 3: Feder -Konfigurationsdatei hinzufügen
Erstellen Sie zwei neue Dateien im Ressourcen-/Spring -Verzeichnis:
│ └── Frühling
│ ├── Spring-Mybatis.xml
│ ├── Spring-Service.xml
│ └── Spring-mvc.xml
Spring-Mvc.xml
<? xmlns: p = "http://www.springframework.org/schema/p" xmlns: context = "http://www.springframework.org/schema/mvc" xsi: schemalocation = "http://www.spingframework.org/schema http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/scha http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"> <!-- Register component scanner --> <context:component-scan base-package="com.ray.controller"/> <!-- Access static resources --> <mvc:default-servlet-handler/> <!-- Enable annotation mode --> <mvc:annotation-driven> <mvc:message-converters> <bean> <property name="supportedMediaTypes"> <list> <!-- Solve Chinese garbled--> <value>text/plain;charset=UTF-8</value> <value>text/html;charset=UTF-8</value> <wert> application/json; charSet = utf-8 </value> </list> </property> </bean> </mvc: Nachrichtenkonverter> </mvc: Annotation-gesteuert> <!-Ansicht Parser-> <bean> <!-Präfix-> <Eigenschaft name = "prefix" value = "/wet-inf/" views/"/"/". Value = ". JSP"/> </bean> </beans>
Spring-Mybatis.xml
<? xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/context/context/context/contex/context/contex/contex/contex/context/context/contex/conted./Sconted. http://www.springframework.org/schema/tx http://www.springFramework.org/schema/tx/spring-tx.xsd "> <!-1. Konfigurieren Sie Datenbank-Relat-Parameter-> <context: Eigenschaften: Propertagen: Properties: Properties: Properties: Properties: Properties. Die Druid-Datenquelle-> <bean id = "dataSource" init-method = "init" destroy-method = "close"> <!-konfigurieren value = "$ {jdbc.username}"/> <Eigenschaft name = "password" value = "$ {jdbc.password}"/> <!-Konfigurieren Sie die Initialisierungsgröße, minimaler, maximaler Wert-> <Eigenschaftsname "InitialSize" Value = "1"/> <Property name = "Minidle". Holen Sie sich das Verbindungswartungs-Timeout-> <Eigenschaft name = "maxwait" value = "10000"/> <!-Konfigurieren Sie, wie lange es dauert, um ein Erkennungsintervall auszuführen name = "minevictableIdletImemillis" value = "300000" /> <!-SQL, die überprüfen, ob die Verbindung gültig ist, unterschiedliche Datenkonfigurationen sind unterschiedlich-> <Eigenschaft name = "validationQuery" value = "select 1" /> <! value = "true"/> <! name = "poolpreparedStatements" value = "true"/> <Eigenschaft name = "MaxpoolProparedStatementPerconectionSize" value = "20"/> <!-Konfigurieren Sie die Einreichungsmethode hier, der Standard ist wahr, Sie können ohne Konfiguration-> <Property name = "DefaultAutocommit" Value ". value = "stat"/> </bean> <!-3. konfigurieren Sie MyBatis 'SQLSessionFactory-Objekt-> <bean id = " ref = "dataSource"/> <!-scannen Sie die Konfigurationsdatei-> <Eigenschaft name = "mapperlocations" value = "classPath: mapping/*. xml"/> </bean> <!-4. Konfigurieren Sie das gescannte DAO-Schnittstellenpaket, das DAO-Schnittstelle injizieren Sie das DAO-Schnittstellen, das das Feder-Container-. name = "basepackage" value = "com.ray.dao"/> </bean> </beans>Spring-Service.xml
<? xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/sping/sping/sping/sping/sping/sping/sping/sping/sping/sping/sping/sping.-contexte.xsd http://www.springframework.org/schema/tx http://www.springFramework.org/schema/tx/spring-tx.xsd "> <!-Automatische Scan-> <context: component-scan-base-package =" com.rayManMan "/> <! name = "dataSource" ref = "dataSource"/> </bean> <!-Schalten Sie Annotationsunterstützung für die Transaktionskontrolle ein-> <tx: Annotationsgetriebene Transaktionsmanager = "TransactionManager"/> </beans>
Schritt 4: Logback -Konfigurationsdatei hinzufügen
Die Logback -Konfiguration ist einfacher als log4j und die Funktionen sind ähnlich
├── Ressourcen
│ ├── logback.xml
Erstellen Sie eine neue Datei im Ordner Ressourcenordner: logback.xml
<?xml version="1.0" encoding="UTF-8" ?> <configuration debug="true"> <appender name="STDOUT"> <encoder> <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> </encoder> </appender> <!---Enable debug log mode and Protokolle in der Konsole-> <root Level = "Debug"> <Appender-ref ref = "stdout"/> </root> </configuration> druckenSchritt 5: Konfigurieren Sie Web.xml
web.xml
<web-app xmlns = "http://xmlns.jcp.org/xml/ns/javaee" xmlns: xsi = "http://www.w3.org/2001/xmlschema-instance" XSI: Schemalocation = "http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee http Version = "3.1" metadata-complete = "true"> <display-name> Archetype erstellt Webanwendung </display-name> <!-Konfigurieren Sie DispatcherServlet-> <servlet> <Servlet-name> Seckill-Dispatcher </servlet-name> <Servlet-Class> org. Laden Sie für SpringMVC Spring-DAO.xml, fing-service.xml, fing-web.xml myBatis-> Spring-> SpringMvc-> <init-param> <param-name> contextconfigLocation </param-name> <param-value> classpath: fing/fing/fing/fed-*. <Load-on-Startups> 1 </load-on-Startup> <Async-Supported> true </async-supportiert> </servlet> <Servlet-Mapping> <Servlet-Mapping> <Servlet-NAME> Seckill-Dispatcher </Servlet-Name> <!-Alle Anfragen übereinstimmen. Garnled-> <Filter> <Filter-Name> CharakterCodingfilter </Filter-Name> <Filter-Klasse> org.springFramework.Web.Filter.Charactercodingfilter </Filter-Class> <init-param> <param-name> </param-name> utf- valuue> utf- </filter> <filter-mapping> <filter-name> charakteranisch-filter </filter-name> <url-pattern>/*</url-puster> </filter-mapping> </web-App>
Projektstruktur:
Das obige ist der gesamte Inhalt dieses Artikels. Ich hoffe, es wird für das Lernen aller hilfreich sein und ich hoffe, jeder wird Wulin.com mehr unterstützen.