統合フレームワークのSpring Frameworkはmybais - 注入マッパーを実装します

上記のケースを通じて、私たちは、これは私たちがすることができます、その後、UserMapperImpl.javaを見てきたもので、特定のメソッドの実装の各時間は、我々は非常に面倒であるマッパーを作成し、見ることができます彼は省略する、IOCコンテナ春を管理するためのマッパー方法を作成します、答えはイエスです

aplicationContext.xml

1 <XMLバージョン= "1.0"エンコード= "UTF-8"?>
 2 <豆のxmlns = "http://www.springframework.org/schema/beans"
 3つ      のxmlns:XSI = "のhttp:// WWW。 w3.org/2001/XMLSchema-instance」 
 4つ      のxmlns:P = "http://www.springframework.org/schema/p"
 5つ      のxmlns:AOP = "http://www.springframework.org/schema/aop" 
 6つ      のxmlns:TX = "http://www.springframework.org/schema/tx"
 7つ      のxmlns:コンテキスト= "http://www.springframework.org/schema/context"
 8      のxsi:schemaLocationの= "のhttp:// www.springframework.org/schema/beans
 9      のhttp:// www.springframework。ORG /スキーマ/豆/春豆-3.2.xsd 
10      のhttp:// www.springframework.org/schema/aop 
11      のhttp:// www.springframework.org/schema/aop/spring-aop-3.2.xsd 
12      のhttp:// www.springframework.org/schema/tx 
13      のhttp:// www.springframework.org/schema/tx/spring-tx-3.2.xsd 
14      のhttp:// www.springframework.org/schema/context 
15      のhttp:// www.springframework.org/schema/context/spring-コンテキスト3.2.xsd "> 
16  
17      <! -配置数据源- >
 18      <ビーンID ="データソース」クラス = "org.apache.commons.dbcp.BasicDataSource">
 19         <プロパティ名= "driverClassName"値= "はcom.mysql.jdbc.Driver"> </ property>の
 20          <プロパティ名= "URL"
 21              値= "はjdbc:mysqlの:// localhostを:?3306 / smbms useUnicode =真&#038 ; characterEncoding = UTF-8 "> </プロパティ>
 22          <プロパティ名="ユーザ名」値= "ルート"> </プロパティ>
 23          <プロパティ名= "パスワード"値= "ルート"> </ property>の
 24  
25      </豆>
 26      <! -配置SqlSessionFactoryBean - >
 27      <豆ID = "sqlSessionFactory" クラス = "org.mybatis.spring。
SqlSessionFactoryBean「> 28          <! -あなたのデータソースに取得する- >
 29         <プロパティ名= "データソース" REF = "データソース"> </プロパティ>
 30          <! - MyBatisのプロファイル取得した注目属性値がここで使用される- >
 31が          <プロパティ名= "configLocation"値=「CLASSPATH :MyBatisの-config.xmlの"> </プロパティ>
 32          <! - -次のSQLファイルを使用して、このようにして得られた>
 33である          mapperLocations「<プロパティ名=">
 34である              <リスト>
 35                  CN / smbms:<値> CLASSPATH / DAO / ** / *。XML </ value>は
 36              </一覧>
 37は、[          </プロパティ> 
 38である     </豆>
 39      
40      <!
- 設定SqlSessionTemplateが継承SqlSessionDaoSupportウェイデータベースを使用してさまざまな操作を実行するためにそれを使用し、種類SqlSessionTemplateを得ることはありません - >41である < - > <!ビーンID =「SqlSessionTemplate」クラス=「org.mybatis.spring.SqlSessionTemplate」
 42は        、このSqlSessionTemplateクラスコンストラクタによって参照されるデータベースへの接続データベースの操作、ときに
 43である        <コンストラクタのArg-NAME =「SqlSessionFactory "REFは=" SqlSessionFactory「> </のArg-コンストラクタは>
 44である     </ビーン> - >
 45      
46れる     <! -ばねIOCコンテナ、この時間を管理するために実装することがマッパ、クラスを削除してもよいUserMapperImpl可能である- >
 47      <ビーンID = "UserMapper"クラス= "org.mybatis.spring.mapper.MapperFactoryBean">
 48      <プロパティ名= "mapperInterface"値= "cn.smbms.dao.user.UserMapper"> </プロパティ> 
<! -私はセッションファクトリを設定する必要がなぜ、主な理由は、データベースのsqlSessionTemplate操作を取得することです- >
49 <プロパティ名= "SqlSessionFactory" REF = "sqlSessionFactory"> </プロパティ> 50 </ビーン> 51 52 </豆>

この時点で、我々はUserMapperImpl.javaクラスは削除後、プロジェクト構造を削除することができます。

 

 最も一般的な結果:

 

 

  

おすすめ

転載: www.cnblogs.com/dongyaotou/p/12152477.html