MyBatisの統合春のブート手順は次のとおりです。
1、のpom.xmlに構成従属相関ジャー
<! -加载MyBatisの整合springboot - > <依存> <groupIdを> org.mybatis.spring.boot </ groupIdを> <たartifactId> MyBatisの-springboot-スターター</たartifactId> <バージョン> 1.3.1 </バージョン> </依存関係> <! - MySQLの的のJDBC驱动包- > <依存> <groupIdを> mysqlの</ groupIdを> <たartifactId>のmysql-コネクタ-javaの</たartifactId> </依存関係>
図2に示すように、コアMyBatisの構成ファイルの構成はMapper.xmlファイル場所にSpringbootをapplication.properties。
Mapper.xmlファイル位置の#1 MyBatisの構成 mybatis.mapperの -locations = CLASSPATH:COM /例/ springboot01 /マッパー/ * .xmlファイル
図3に示すように、コンフィギュレーション・ファイル・ソース内の構成データは、コアSpringbootのをapplication.properties。
#配置数据源 spring.datasource.username = ルート spring.datasource.password = ルート spring.datasource.driver - クラス -name = はcom.mysql.jdbc.Driver spring.datasource.url = JDBCます。mysql:// localhostを:3306 /試験?useUnicode =真&characterEncoding = UTF8&useSslオプション=偽
4、新しいDAOインターフェース、インターフェースに注釈マッパー@Mapper MyBatisの追加や@MapperScan(「com.bjpowernode.springboot.mapper」)を追加注釈の主走査型パッケージ上で実行されています
@Mapper パブリック インターフェースTClassMapper { リスト <クラス> リスト(); }
若しくは
図5に示すように、MavenのプラグインはMyBatisのための自動コード生成を生成ここで使用MyBatisのマップファイルを、書き込み
新しいサービスおよびコントローラ
パブリック インターフェースTClassService { リスト <はTClass> リスト(); } @Controller パブリック クラスHelloController { @Autowired プライベートTClassService tClassService。 (@RequestMapping "index.do" ) 公衆@ResponseBodyオブジェクトリストを(){ 戻り)(tClassService.listします。 } }
サービスは、注射を与えられている場合は、ツールが問題である、それは警告を変更することができます