配置applicationContext-dao.xml 04

本节操作完成了对spring父容器中dao层扫描加载及其分页的配置。

1、在resources中创建MyBatis-Config.xml

具体操作如下图所示:

创建MyBatis-Config.xml

2、修改MyBatis-Config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <plugins>
        <plugin interceptor="com.github.pagehelper.PageInterceptor">
        </plugin>
    </plugins>
</configuration>

3、创建applicationContext-dao.xmll

具体操作如下图所示:

创建applicationContext-dao.xml

4、修改applicationContext-dao.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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    <!--配置数据库连接池,使用的是druid-->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
        <property name="url" value="jdbc:mysql://localhost:3306/student"></property>
        <property name="username" value="root"></property>
        <property name="password" value="zhangli"></property>
    </bean>

    <!--配置SqlSession的工厂-->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="configLocation"  value="classpath:Mybatis-Config.xml"/>
        <property name="dataSource" ref="dataSource"></property>
    </bean>

    <!--配置数据库操作的接口以及xml所在package-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="net.wanho.mapper"></property>
    </bean>
</beans>

至此,我们完成了spring父容器中dao层扫描加载及其分页的配置。

猜你喜欢

转载自www.cnblogs.com/alichengxuyuan/p/12581685.html
04
今日推荐