In contact with a new thing, always inevitably take some detours, it is in these detours, we continue to grow.
From Git to the previous written code to take down, to see me in the original use of spring and MyBatis in the Detour, passing the gentleman can also warning.
<!--transaction manager - <BeanID= "Txmanager"class= "Org.springframework.jdbc.datasource.DataSourceTransactionManager"> < Propertyname= "DataSource"ref= "DataSource" /> </Bean> <!--Transaction Support - <Tx:annotation-drivenTransaction-manager= "Txmanager" /> <BeanID= "Sqlsessionfactory"class= "Org.mybatis.spring.SqlSessionFactoryBean"> < Propertyname= "DataSource"ref= "DataSource" />
<!--introduce the table mapping configuration file for MyBatis--
< Propertyname= "Mapperlocations"value= "Classpath*:mappers/*.xml" />
<!--mybatis a configuration file in which a paging block extension is added to this file, and the following post this file content-< Propertyname= "Configlocation"value= "Classpath:mybatisConfig.xml"></ Property> </Bean> <BeanID= "Sqlsession"class= "Com.oa.bo.MySqlSessionFactory"> < Propertyname= "Sessionfactory"ref= "Sqlsessionfactory"></ Property> Here, put the sqlsessionfactory in the back, post the code, and look at the same God-like realization ^_^ </Bean>
Mybatisconfig.xml
<Configuration> <Properties> < Propertyname= "dialect"value= "MYSQL" /> </Properties> <Plugins> <pluginInterceptor= "Com.oa.utils.pager.PaginationInterceptor"> here to do an interceptor to handle paged queries </plugin> </Plugins></Configuration>
Mysqlsessionfactory implementation code, do not adore yo.
Public classMysqlsessionfactory {StaticLogger log =Logger.getrootlogger (); Final StaticString CacheName =Constvar.ferever_cache; Final StaticString CACHEKEY = "Sqlsessionfactory"; Privatesqlsessionfactory sqlsessionfactory; Publicsqlsessionfactory getsessionfactory () {Object Object=ehcacheutil.getinstance (). Get (CacheName, CACHEKEY); if(Object! =NULL) {Log.info ("Value from buffer"); Sqlsessionfactory=(sqlsessionfactory) object; } Else{log.info ("No Cache ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!"); } returnsqlsessionfactory; } Public voidsetsessionfactory (sqlsessionfactory sqlsessionfactory) { This. Sqlsessionfactory =sqlsessionfactory; Log.info ("Value of object:" +sqlsessionfactory); Ehcacheutil.getinstance (). Put (CacheName, CACHEKEY, sqlsessionfactory); } Publicsqlsession getsqlsession () {returngetsessionfactory (). Opensession (); }}
Here the session exists in the Ehcache permanent cache, discerning eye a look at this there is a problem. But the specific problem, no measurement, no specific data, it is inconvenient to utter.
The following is used on each business logic
Public Abstract class extends Implements Basebo {...} Public class extends Baseboimp { = Logger.getrootlogger (); /** * Bulk Delete data * /Public returnresult delbyids (String IDs) { = getsqlsession (); ...} .......}
All used are shared with the session in the cache above.
The transaction is manually managed each time you manually close it yourself.
These are the first configurations to be implemented, followed by a second-stage detour.
The Detour in the Spring,mybatis integration configuration (1)