The Detour in the Spring,mybatis integration configuration (1)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.