image.png

    1、spring.xml:

    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <beans xmlns="http://www.springframework.org/schema/beans"
    3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    4. xmlns:context="http://www.springframework.org/schema/context"
    5. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
    6. <!-- 数据库连接池 -->
    7. <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close">
    8. <property name="url" value="jdbc:mysql://localhost:3306/myb?useUnicode=true&amp;characterEncoding=utf8"/>
    9. <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    10. <property name="username" value="root"/>
    11. <property name="password" value="941941"/>
    12. </bean>
    13. <!-- JdbcTemplate 对象 -->
    14. <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    15. <property name="dataSource" ref="dataSource"/>
    16. </bean>
    17. <!-- 组件扫描,扫描四个创建对象的注解 与 四个自动注入的注解-->
    18. <context:component-scan base-package="com.wzy.jdbctemplate"/>
    19. </beans>