- 配置application.xml
- <?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:context="http://www.springframework.org/schema/context"
- xmlns:jdbc="http://www.springframework.org/schema/jdbc"
- xmlns:jee="http://www.springframework.org/schema/jee"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:mvc="http://www.springframework.org/schema/mvc"
- xmlns:util="http://www.springframework.org/schema/util"
- xmlns:jpa="http://www.springframework.org/schema/data/jpa"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
- http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
- http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
- http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
- http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
- http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd">
- <!-- 数据源-->
- <bean id="ds"class="org.apache.commons.dbcp.BasicDataSource">
- <property name="url" value="jdbc:oracle:thin:@localhost:1521:xe"/>
- <property name="driverClassName" value="oracle.jdbc.OracleDriver"/>
- <property name="username" value="lhh"/>
- <property name="password" value="123456"/>
- </bean>
- <!-- session工厂-->
- <bean id="sqlSessionFactory"class="org.mybatis.spring.SqlSessionFactoryBean">
- <property name="dataSource" ref="ds"/>
- <property name="mapperLocations"
- value="classpath:com/tarena/dao/*.xml"/>
- </bean>
- <!-- 扫描指定包下所有的接口-->
- <beanclass="org.mybatis.spring.mapper.MapperScannerConfigurer">
- <property name="basePackage" value="com.tarena.dao"/>
- </bean>
- </beans>
2. 创建映射文件Empmapper.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC"-//ibatis.apache.org//DTD Mapper 3.0//EN"
- "http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">
- <mapper namespace="com.tarena.dao.EmpMapper">
- <select id="findAll"
- resultType="com.tarena.entity.Emp">
- select* from t_emp
- </select>
- </mapper>