You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Di
8000
smiss alert
As you may already know, to use MyBatis with Spring you need at least an SqlSessionFactory and at least one mapper interface.
MyBatis-Spring-Boot-Starter will:
Autodetect an existing DataSource.
Will create and register an instance of a SqlSessionFactory passing that DataSource as an input using the SqlSessionFactoryBean.
Will create and register an instance of a SqlSessionTemplate got out of the SqlSessionFactory.
Autoscan your mappers, link them to the SqlSessionTemplate and register them to Spring context so they can be injected into your beans.
Uh oh!
There was an error while loading. Please reload this page.
方式一:mybatis-spring-boot-starter
这种方式比较简单,具体步骤如下:
在Application.java上添加注解@MapperScan:
然后就可以使用mybatis-generator生成mapper接口,mapper xml,model了,关于事务详见这里。
方式一解释:
其实mybatis-spring-boot-starter替我们做了大部分配置:(摘自官方文档)
大概翻译一下:
也许你早就知道,为了在spring上使用mybatis你至少需要一个SqlSessionFactory和一个mapper接口。
MyBatis-Spring-Boot-Starter会:
如果使用方式二的话,就需要显示做出部分配置。
方式二:mybatis-spring
这种方式与传统的spring集成mybatis基本一致(下面展示完整的java配置版,部分xml版)
部分xml版配置:
The text was updated successfully, but these errors were encountered: