SSM 3つの統合学習

3:統合MyBatisの

以下の項目を完了

 

 

一つは:それは必要なjarパッケージをダウンロードします


<! -日志- >
<依存>
<groupIdを> log4jの</ groupIdを>
<たartifactId> log4jの</たartifactId>
<バージョン> 1.2.17 </バージョン>
</依存関係>

<! -数据源- >
<! - https://mvnrepository.com/artifact/org.apache.commons/commons-dbcp2 - >
<依存>
<groupIdを> org.apache.commons </ groupIdを>
<たartifactId>コモンズ-dbcp2 </たartifactId >
<バージョン> 2.1.1 </バージョン>
</依存関係>

<! - https://mvnrepository.com/artifact/org.mybatis/mybatis-spring - >
<依存>
<groupIdを> org.mybatis </ groupId>
<たartifactId> MyBatisのスプリング</たartifactId>
<バージョン>1.3.2 </バージョン>
</依存関係>

<! - https://mvnrepository.com/artifact/org.mybatis/mybatis - >
<依存性>
<のgroupId> org.mybatis </のgroupId>
<たartifactId> MyBatisの</たartifactId>
<バージョン> 3.4.6 </バージョン>
</依存>
<依存性>
<のgroupId> org.aspectj </のgroupId>
<たartifactId > aspectjweaver </たartifactId>
<バージョン> 1.8.4 </バージョン>
</依存関係>

2:コンフィギュレーション情報を書き込みます

ディスパッチャ-servlet.xmlの構成情報を記入

<?xml version = "1.0"エンコード= "UTF-8"?> 
<豆のxmlns = "http://www.springframework.org/schema/beans"
のxmlns:XSI = "http://www.w3.org / 2001 / XMLスキーマ・インスタンス"
のxmlns:MVC = "http://www.springframework.org/schema/mvc"
のxmlns:コンテキスト= "http://www.springframework.org/schema/context"
のxmlns:TX =" http://www.springframework.org/schema/tx "
のxmlns:AOP = "http://www.springframework.org/schema/aop"
のxsi:schemaLocationの=" http://www.springframework.org/schema/豆
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx .xsd
https://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/aop
http://www.springframework.org/schema/context
のhttp:// WWW .springframework.org /スキーマ/コンテキスト/スプリングコンテキスト3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd ">
<MVC:注釈ドリブン/>
<MVC:デフォルト・サーブレット・ハンドラ/>

< -开启扫描- >!
<コンテキスト:コンポーネント・スキャンベースパッケージ=" com.founderit "/>
<コンテキスト:注釈-config />

<文脈:プロパティプレースホルダ位置= "クラスパス:リソース/ db.properties" />


<! - DBCP数据库连接池- >
<ビーンID =」情報元"
クラス= "org.apache.commons.dbcp2.BasicDataSourceは"
破壊法= "閉じる">
<プロパティ名= "driverClassName"値= "$ {DRIVERCLASS}" />
<プロパティ名= "URL"値= "$ { URL} "/>
<プロパティ名="ユーザ名」値= "$ {USERNAME}" />
<プロパティ名= "パスワード"値= "$ {PASSWORD}" />
< - MAXACTIVE:!最大连接数量- >
<プロパティ名= "maxTotal"値= "150" />
< - minIdle:!最小空闲连接- >
<プロパティ名= "minIdle"値= "5" />
< - maxIdle:!最大空闲连接- >
<プロパティ名=」maxIdle」値= "20" />
< - INITIALSIZE:!初始化连接- >
<プロパティ名= "INITIALSIZE"値= "30" />
< - (秒単位)removeAbandonedTimeoutを:!タイムアウト- >
<プロパティ名= "removeAbandonedTimeoutを"値= "10" />
</豆>

<! -春とMyBatisのの完全な統合- >
<豆= ID "SqlSessionFactory"クラス= "org.mybatis.spring.SqlSessionFactoryBean">
<プロパティ名= "データソース" REF = "データソース" />
<! - > - mapping.xmlは、自動的にファイルスキャン
<プロパティ名を=「mapperLocations 。 "=値" CLASSPATH:COM / founderit /マッパー/ * xmlの「> </プロパティ>
</豆>

<! -パッケージ名が、春は自動的にカテゴリの下にそれを見つけるでしょうDAOインタフェース- >
<beanクラス= "org.mybatis.spring.mapper.MapperScannerConfigurer">
<プロパティ名= "basePackage" 値= "com.founderit.dao" />
<! - <プロパティ名= "sqlSessionFactoryBeanName"値= "sqlSessionFactory"> </ property>の- >
</豆>
<! - (事务管理)トランザクションマネージャ- >
の<beanのid = "のTransactionManager"
クラス= "org.springframework.jdbc.datasource.DataSourceTransactionManager">
<プロパティ名= "データソース" REF = "データソース" />
</豆>

< -通知- >!

<TX:アドバイスID = "txAdvice"トランザクション・マネージャ= "のTransactionManager">
<TX:>属性
< -传播行为- >!
<TX:メソッド名= "保存*"伝播= "REQUIRED" />
<TX:メソッド名= "挿入*"伝播= "REQUIRED" />
<TX:メソッド名= "追加*"伝播= "REQUIRED" />
<TX:メソッド名= "作成*"伝播= "REQUIRED" />
<TX:メソッド名= "削除*"伝播= "REQUIRED" />
<TX:メソッド名= "更新*"伝播= "REQUIRED" / >
<TX:メソッド名= "見つける*"伝搬は=読み取り専用= "真" /> "サポート"
<TX:メソッド名=伝播= "*を選択し、"読み取り専用= "真" /> "サポート"
< TX:メソッド名= "取得*"伝播は=読み取り専用= "真" /> "サポート"
属性>:</ TX
</ TX:アドバイス>
! - -切面> <
設定>:<AOP
<AOP :アドバイス-REF =顧問"txAdvice"
ポイントカット= "実行(com.founderit.service * * *(..)。)" />
</ AOP:config>の
</豆>

完全なプロジェクトによっては、対応するクラスを作成します

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 3:テスト

結果を確認するにはTomcatを実行、ハロー要求

 

おすすめ

転載: www.cnblogs.com/lovetq520/p/11721374.html