MyBatis Learning Note One mybatis combined with spring configuration

Source: Internet
Author: User

These two days, began to learn MyBatis, a little feel, share, here to thank a door blog Link: http://www.yihaomen.com/article/java/426.htm

First of all, the project example diagram gives you a look:


Applicationcontext.xml class:

<?xml version= "1.0" encoding= "Utf-8"?> <beans xmlns= "Http://www.springframework.org/schema/beans" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" xmlns:tx= " Http://www.springframework.org/schema/tx "xmlns:context=" Http://www.springframework.org/schema/context "xmlns:p= "http://www.springframework.org/schema/p" xsi:schemalocation= "Http://www.springframework.org/schema/bean S http://www.springframework.org/schema/beans/spring-beans-3.0.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP Http://www.springframework.org/schema/aop/spring-aop-3.0.xsd Http://www.springframework.org/schema/context HT Tp://www.springframework.org/schema/context/spring-context-3.0.xsd Http://www.springframework.org/schema/jee Http://www.springframework.org/schema/jee/spring-jee-3.0.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/TX/HTTP Www.springframework.org/schema/tx/spring-tx-3.0.xsd "default-autowire=" ByName "default-lazy-init=" false "> <!--automatically scan Web packages, incorporating annotated classes into s Pring Container Management--><context:component-scan base-package= "Com.yihaomen" ></context:component-scan><!-- Introducing the JDBC configuration file--><bean id= "Propertyconfigurer" class= " Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer "><property name=" Locations "> <list><value>classpath:config/jdbc.properties</value></list></property></bean ><!--Configuring the data source One--><bean id= "DataSource" class= "Org.apache.commons.dbcp.BasicDataSource" >< Property Name= "Driverclassname" value= "${jdbc.driver}" ></property><property name= "url" value= "${ Jdbc.url} "></property><property name=" username "value=" ${jdbc.username} "></property>< Property name= "Password" value= "${jdbc.password}" ></property> <!--initialsize: Initialize connection--><proper        Ty name= "InitialSize" value= "5"/> <!--maxidle: Maximum idle connection--><property name= "Maxidle" value= "ten"/><property name= "Minidle" value= "5"/>& Lt;property name= "maxactive" value= "All"/><property name= "removeabandoned" value= "true"/><property name= "Removeabandonedtimeout" value= "/>" <!--maxwait: Timeout wait time in milliseconds 6000 milliseconds/1000 equals 60 seconds--><property name= " Maxwait "value=" "/><property name=" Validationquery "><value>select 1</value></property ><property name= "Testonborrow" ><value>true</value></property></bean> <bean ID = "TransactionManager" class= "Org.springframework.jdbc.datasource.DataSourceTransactionManager" > <property Name= "DataSource" ref= "DataSource"/> </bean> <bean id= "Sqlsessionfactorybeanname" class= " Org.mybatis.spring.SqlSessionFactoryBean "> <!--dataSource properties Specify the connection pool to use--<property name=" DataSource "   ref= "DataSource"/> <!--configlocation properties specify the core profile of MyBatis--   <property name= "configlocation" value= "Classpath:config/configuration.xml"/> <!--all configured mapper files-- <property name= "mapperlocations" value= "Classpath*:com/yihaomen/mapper/*.xml"/> </bean> <bean clas s= "Org.mybatis.spring.mapper.MapperScannerConfigurer" > <property name= "basepackage" value= "  Com.yihaomen.inter "/> </bean> </beans>


Jdbc.properties (Database configuration information):

jdbc.driver=com.mysql.jdbc.driverjdbc.url=jdbc:mysql://localhost:3306/mybatis?characterencoding= utf8jdbc.username=rootjdbc.password=123456

Configuration.xml (mainly reducedThe length of the class name is reduced to set, and the following describes)
<configuration>    <typeAliases>         <typealias alias= "User" type= "Com.yihaomen.model.User"/>    </typeAliases> </configuration>

Log4j.properties (log configuration)




MyBatis Learning Note One mybatis combined with spring configuration

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.