Compared to the usual wording of MyBatis, Spring uses mybatis without mybatis-config.xml configuration and Mybatisfactory factory, which can be configured in Applicationcontext.xml.
Or use the last case: MyBatis Portal
Attached applicationcontext.xml:
<beans xmlns="Http://www.springframework.org/schema/beans"xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="Http://www.springframework.org/schema/beans http://www.springframework.org/ Schema/beans/spring-beans-3.2.xsd "> <!--configuring Sqlsessionfactory in an IOC container using Sqlsessionfactorybean factory Bean 1 Configuration Data source 2 configuration Map File Note CLASSPATH prefixes each add a mapping file to the project, you need to add a value element to the list-- <bean id="SSF" class="Org.mybatis.spring.SqlSessionFactoryBean" > < property name="DataSource" ref="ds"></Property > < property name="Mapperlocations"> <list> <value>Classpath:com/etoak/dao/citydaoif-mapper.xml</value> </list> </Property > </Bean> <bean id= "ds" class=" Org.springframework.jdbc.datasource.DriverManagerDataSource "> < property name= "driverclassname" value=" Com.mysql.jdbc.Driver "></Property > < property name="url" value="Jdbc:mysql://localhost:3306/yitu" ></Property > < property name="username" value="root"></Property > < property name="password" value="root"></Property > </Bean> < Instance bean object corresponding to the!--configuration interface spring in order to configure the interface instance, provide Mapperfactorybean factory bean-- <bean id="DAO" class=" Org.mybatis.spring.mapper.MapperFactoryBean "> < property name="Sqlsessionfactory" ref="SSF"></Property > < property name= "mapperinterface" value=" Com.etoak.dao.CityDaoIf "></Property > </Bean> <!--each add an interface to the project, you need to add a separate bean node to the IOC container using the Mapperinterface instantiation interface--</Beans>
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Spring Learning (vii) Spring integration MyBatis