mybatis-config.xml配置文件内容
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<!-- 开启下划线转驼峰 -->
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
</configuration>
db.properties数据库连接配置文件内容
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.jdbcUrl=jdbc:mysql://localhost/jzfw?useSSL=false
jdbc.user=root
jdbc.password=123
spring-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" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.ncwu"></context:component-scan>
<context:property-placeholder location="classpath:spring/db.properties" />
<!-- c3p0 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driverClass}"></property>
<property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
<property name="user" value="${jdbc.user}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean>
<!-- 配置 SqlSessionFactoryBean 对象 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 注入数据源 -->
<property name="dataSource" ref="dataSource"/>
<!-- 设置 mybatis 配置文件的路径 -->
<property name="configLocation" value="classpath:mybatis/mybatis-config.xml"/>
<!-- 自动起别名 -->
<property name="typeAliasesPackage" value="com.ncwu.model"/>
<!-- 设置 mapper 文件的路径 -->
<property name="mapperLocations" value="classpath*:com/ncwu/mapper/*.xml"/>
</bean>
<!-- 把 Dao 接口的实现类注入到 spring 容器中,通过名字或者类型获取对象 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 把 dao 包下 interface 的实现类注入到 spring 容器中 -->
<property name="basePackage" value="com.ncwu.dao"/>
</bean>
</beans>
spring-service.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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 针对于 service 层的 spring 配置 -->
<!-- 1. 包扫描,扫描 @Service 标签 -->
<context:component-scan base-package="com.ncwu.service"/>
<!-- 2. 为方法提供事务支持 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- 注入数据库连接池,事务是数据库中的操作 -->
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 使用最简单的声明式事务,通过注解来完成 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
spring-web.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:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- 识别 controller 包中与 SpringMVC 相关的注解:@RequestMapping, @RequestParam... -->
<context:component-scan base-package="com.ncwu.controller" />
<!-- 使用系统默认的设置,简化配置流程 -->
<!--
1. 使用默认的 handlerMapping 和 handlerAdapter 查询 request 和对应的 controller
2. @RequestMapping, @RequestParam 等注解的支持
3. 支持 json,restful
-->
<mvc:annotation-driven/>
<!-- 设置页面路径前缀和后缀 -->
<!-- 放在 WEB-INF 下的文件,别人不能通过 url 访问,可以提高数据的安全性 -->
<!-- 只能通过请求转发获取 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<!-- 使用默认的 handler,支持静态资源的访问 -->
<mvc:default-servlet-handler/>
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />
</beans>