この記事では、参照のためにライブラリシステムライブラリ管理システムの2番目の記事を共有しています。特定のコンテンツは次のとおりです
ステップ1:データベース構成ファイルを追加します
JDBC.Properties
#データベースドライバーjdbc.driver = com.mysql.jdbc.driver#データベースアドレスjdbc.url = jdbc:mysql:// localhost:3306/library?useunicode = true&charateremencoding = utf-8#username jdbc.username = root jdbc.passise nivelize niverize niverize niverize niversemes接続maxactive = 20#最大アイドル接続maxidle = 20#最小アイドル接続minidle = 1#タイムアウト待機時間maxwait = 60000
ステップ2: MyBatis構成ファイルを追加します
mybatis-config.xml
<?xml version = "1.0" encoding = "utf-8"?> <!doctype構成public " - // mybatis.org//dtd config 3.0 // en" "http://mybatis.org/dtd/mybatis-3-config.dtd" GetGeneratedKeysプライマリキーを取得します - > <name = "usegeneratedkeys" value = "true"/> <! - 列名をエイリアスに置き換えます、デフォルトのture-> <"usecolumnlabel" value = "true"/> <! - キャメルネーミング変換のターン - >
ステップ3:スプリング構成ファイルを追加します
リソース/スプリングディレクトリに2つの新しいファイルを作成します。
spring spring
│├│。。Spring-Mybatis.xml
spring-service.xml
spring-mvc.xml
spring-mvc.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:P = "http://www.springframework.org/schema/p" xmlns:context = "http://www.springframework.org/schema/mvc" xsi:schemalocation = "http://ww.springframework. http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context-4.tpring http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd "> <! - コンポーネントスキャナーの登録 - > - > <MVC:default-servlet Handler/> <! - enable annotation Mode-> <MVC:annotation-driven> <mvc:mession-converters> <bean> <プロパティ名= "supportedmediatypes"> <リスト> < <value> Application/json; charset = utf-8 </value> </list> </property> </bean> </mvc:message-converters> </mvc:annotation-driven> <! - view parser-> <bean> <!-preix-> <property name = "preperix" value = " value = "。jsp"/> </bean> </bean>
spring-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:Context = "http://www.springframework.org/schema/context" xmlns:tx = "http://www.springframework.org/schema/tx" xsi:schemalocation = "http://ww.springframework http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context-/spring-context-/spring-contex http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd "> <!-1。 Druidデータソースの構成 - > <Bean Id = "DataSource" init-method = "init" destroy-method = "close"> <! - 構成接続プールプロパティ - > <プロパティ名= "driverclassName" value = "$ {jdbc.driver}"/> <プロパティname = "url" $ {jdbc.urlal} "/>> <urname"/< value = "$ {jdbc.username}"/> <プロパティname = "password" value = "$ {jdbc.password}"/> <! - 初期化サイズ、最小値、最大値 - > <プロパティname = "Initialsize" value = "1"/> <Property name = "minidle" 1 "1"/> <maxactive "/> <" maxactive "/> <接続待機時間を取得 - > <プロパティ名= "maxwait" value = "10000"/> <! - 検出間隔の実行にかかる時間を構成します。 name = "minevictableidletimemillis" value = "300000" /> <! - sql接続が有効であることを確認するsql異なるデータ構成が異なる - > <プロパティ名= "validationquery" value = "select 1" /> <! - アイドル時間が時間よりも大きい場合は、nievictionrunsmillisを実行します。 value = "true"/> <! - 取得した接続が利用できないのを防ぐためにここでTRUEとして構成することをお勧めします - > <プロパティ名= "testonborrow" value = "true"/> <property name = "testonborrow" value = "true"/> <プロパティ名= "testonreturn" value = "false"/> < name = "poolpreparedStatements" value = "true"/> <プロパティname = "maxpoolpreparedStatementperconnectionsize" value = "20"/> <! - デフォルトはtrueで実行できます。値= "stat"/> </bean> <! - 3。mybatisのsqlsessionfactory object-> <bean id = "sqlsessionfactory"> <! - mybatis global configuration file-> <property name = "configlocation" value = "classpath:mybatis-config.xml"/>> <! ref = "dataSource"/> <! - 構成ファイルをスキャン - > <プロパティ名= "mapperlocations" value = "classpath:mapping/*。xml"/> </bean> <! - 4。 name = "basepackage" value = "com.ray.dao"/> </bean> </beans>spring-service.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" xmlns:tx = "http://www.springframework.org/schema/tx" xsi:schemalocation = "http://ww.springframework http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd "> <! - 自動スキャン - > <コンテキスト:com.ray"/>> < <プロパティ名= "dataSource" ref = "dataSource"/> </bean> <! - トランザクションコントロールのアノテーションサポートをオンにします - > <tx:annotation-driven transaction-manager = "transactionmanager"/> </beans> <
ステップ4:ログバック構成ファイルを追加します
ログバック構成はlog4jよりも単純で、関数は似ています
├)。リソース
│├│。-logback.xml
リソースフォルダーで新しいファイルを作成します:logback.xml
<?xml version = "1.0" encoding = "utf-8"?> <configuration debug = "true"> <appender name = "stdout"> <pattern>%d {hh:mm:ss.sss} [%スレッド]%-5level%logger {36} - コンソールにログを印刷 - > <rootレベル= "debug"> <appender-ref ref = "stdout"/> </root> </configuration>ステップ5: 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/web-app_3_1.xsd"バージョン= "3.1アプリケーション</display-name> <! - DispatcherServletを構成 - > <Servlet> <Servlet-Name> seckill-dispatcher </servlet-name> <servlet-class> org.springframework.web.servlet.dispatcherservlet </servlet-class> <! - スプリングMVCをロードする必要があるためにロードする必要がある構成ファイルファイルSpring-dao.xml、spring-service.xml、spring-web.xml mybatis-> spring-> springmvc-> <init-param> <param-name> contextconfiglocation </param-name> <param-value> classpath:spring/spring - * <async-supported> true </async-supported> </servlet> <servlet-mapping> <servlet-name> seckill-dispatcher </servet-name> <! - デフォルトですべてのリクエストを一致させる - > <url-pattern>/</url-pattern> <filter-name> charatelecodingfilter </filter-name> <filter-class> org.springframework.web.filter.characterencodingfilter </filter-class> <init-param> <param-name> encoding </param-name> <-value> utf-8 </param-> </init-param> </filter> </filt <filter-name> charitiousencodingfilter </filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
プロジェクト構造:
上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。