spring整合mybatis配置文件

  1. 配置application.xml
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <beans xmlns="http://www.springframework.org/schema/beans"
  4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5.     xmlns:context="http://www.springframework.org/schema/context"
  6.     xmlns:jdbc="http://www.springframework.org/schema/jdbc"
  7.     xmlns:jee="http://www.springframework.org/schema/jee"
  8.     xmlns:tx="http://www.springframework.org/schema/tx"
  9.     xmlns:aop="http://www.springframework.org/schema/aop"
  10.     xmlns:mvc="http://www.springframework.org/schema/mvc"
  11.     xmlns:util="http://www.springframework.org/schema/util"
  12.     xmlns:jpa="http://www.springframework.org/schema/data/jpa"
  13.     xsi:schemaLocation="
  14.         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
  15.         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
  16.         http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
  17.         http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
  18.         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
  19.         http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
  20.         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
  21.         http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
  22.         http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd">
  23.     
  24.     <!-- 数据源-->
  25.     <bean id="ds"class="org.apache.commons.dbcp.BasicDataSource">
  26.         <property name="url" value="jdbc:oracle:thin:@localhost:1521:xe"/>
  27.         <property name="driverClassName" value="oracle.jdbc.OracleDriver"/>
  28.         <property name="username" value="lhh"/>
  29.         <property name="password" value="123456"/>
  30.     </bean>
  31.     
  32.     <!-- session工厂-->
  33.     <bean id="sqlSessionFactory"class="org.mybatis.spring.SqlSessionFactoryBean">
  34.         <property name="dataSource" ref="ds"/>
  35.         <property name="mapperLocations"
  36.             value="classpath:com/tarena/dao/*.xml"/>
  37.     </bean>
  38.     
  39.     <!-- 扫描指定包下所有的接口-->    
  40.     <beanclass="org.mybatis.spring.mapper.MapperScannerConfigurer">
  41.         <property name="basePackage" value="com.tarena.dao"/>
  42.     </bean>
  43.     
  44. </beans>









2. 创建映射文件Empmapper.xml
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC"-//ibatis.apache.org//DTD Mapper 3.0//EN"
  3. "http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">
  4. <mapper namespace="com.tarena.dao.EmpMapper">
  5.     <select id="findAll"
  6.         resultType="com.tarena.entity.Emp">
  7.         select* from t_emp
  8.     </select>
  9.     
  10. </mapper>




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值