部分源代码和数据库在博客文件中db和src
web.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>OA</display-name>
<servlet>
<servlet-name>spring-mvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 指定SpringMVC配置文件的位置及名称 -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:resources/spring-*.xml</param-value>// 设置spring-mvc.jsp在项目中的位置,默认情况下是放在WEB-INF下的
</init-param>
<!-- 启动应用时创建当前servlet实例 -->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-mvc</servlet-name>
<!--
<url-pattern>的值不能写为/*,不建议写为/,最好写为扩展名方式,比如:.do,.go
-->
<url-pattern>*.do</url-pattern>
</servlet-mapping>
//配置乱码过滤器
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
//当用户在浏览器中输入的URL不包含某个servlet名或JSP页面时,welcome-file-list元素可指定显示的默认文件。
<welcome-file-list>
<welcome-file>/html/login.jsp</welcome-file>
</welcome-file-list>
</web-app>
//mybatis.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>
//定义别名
<typeAliases>
<package name="com.edu.aynu.oa.commons.bean"/>
</typeAliases>
//引入的映射文件包名
<mappers>
<package name="com.edu.aynu.oa.index.news.lablemanager.dao"/>
</mappers>
</configuration>
spring-mvc.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.edu.aynu.oa.index.news.lablemanager.handler"/>
//JDBC数据源
<bean id="myDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driver}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.user}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<context:property-placeholder location="classpath:resources/jdbc.properties"/>
<!-- 生成sqlSessionFactory -->
<bean id="mySqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="myDataSource"/>
<property name="configLocation" value="classpath:resources/mybatis.xml"/>
</bean>
<!-- 定义dao对象 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="mySqlSessionFactory"/>
<property name="basePackage" value="com.edu.aynu.oa.index.news.lablemanager.dao"/>
</bean>
<!-- 定义service对象 -->
<bean id="newslableService" class="com.edu.aynu.oa.index.news.lablemanager.service.NewslableServiceImp">
<property name="dao" ref="INewslableDao"/>
</bean>
</beans>
JDBC配置文件
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql:///oa
jdbc.user=root
jdbc.password=12345678