springMVC框架搭建
we.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" version="2.5">
<servlet>
<servlet-name>SpringMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:springMVC.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>SpringMVC</servlet-name>
<url-pattern>*.do</url-pattern>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:mybatis-confg.xml</param-value>
</context-param>
</web-app>
pom.xom文件配置
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>pei.com</groupId>
<artifactId>test1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!--二维码-->
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>javase</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.4</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<!-- page分页的包 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<!-- spring的配置 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>4.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.1.1.RELEASE</version>
</dependency>
<!-- spring aop的一部分-->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.4</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.9.4</version>
</dependency>
<!-- java对象和json相互转化的工具包-->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
<!-- apache commons类库-->
<!-- Commons-DBCP 提供数据库连接池服务-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.7.0</version>
</dependency>
<!-- Commons-Lang 提供了许多许多通用的工具类集,提供了一些java.lang中类的扩展功能-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
<!-- Commons-Collections 提供一个类包来扩展和增加标准的 Java Collection框架-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.4</version>
</dependency>
<!-- ftp功能实现 -->
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.6</version>
</dependency>
<!-- FileUpload 使得在你可以在应用和Servlet中容易的加入强大和高性能的文件上传能力-->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.4</version>
</dependency>
<!-- i/o工具集 -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<!-- mybatis 页面 -->
<!-- mybatis分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.10</version>
</dependency>
<dependency>
<groupId>com.github.miemiedev</groupId>
<artifactId>mybatis-paginator</artifactId>
<version>1.2.17</version>
</dependency>
<!-- SQL语法解释器:SQL解析样例-->
<dependency>
<groupId>com.github.jsqlparser</groupId>
<artifactId>jsqlparser</artifactId>
<version>3.0</version>
</dependency>
<!-- Joda-Time 处理日期时间的库 -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.10.4</version>
</dependency>
<!-- Hashids是一个小型的开源库,它从数字生成简短的、惟一的、非顺序的id。-->
<dependency>
<groupId>org.hashids</groupId>
<artifactId>hashids</artifactId>
<version>1.0.3</version>
</dependency>
<!-- log4j的改进版日志模块logback-classic-->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.3.0-alpha4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.3.0-alpha4</version>
</dependency>
<!-- mysql的包-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.18</version>
</dependency>
<!-- google guava 一个谷歌提供的工具类-->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>28.1-jre</version>
</dependency>
<!-- mybatis的配置-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
</project>
springMVC.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:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd">
<!--1、开启注解模式-->
<!-- <mvc:annotation-driven/> -->
<!--2、配置默认servlet处理器-->
<mvc:default-servlet-handler/>
<mvc:annotation-driven>
</mvc:annotation-driven>
<!--4、扫描所有的控制器类-->
<context:component-scan base-package="controller"/>
<context:component-scan base-package="dao"/>
<context:component-scan base-package="service"/>
<context:component-scan base-package="serviceimpl"/>
<context:component-scan base-package="bean"/>
<!--配置WEB-INF下面的资源可以访问-->
<mvc:resources mapping="/css/**" location="/easyui/css/"/>
<mvc:resources mapping="/js/**" location="/easyui/js/"/>
<!--3项目中引入图片->
<mvc:resources mapping="/qrcode/**" location="/WEB-INF/classes/file/qrcode/" />
<!--3、视图解析器-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> -->
<property name="prefix" value="/WEB-INF/me"/>
<property name="suffix" value=".jsp"/>
</bean>
<!-- 第一步:配置数据库连接资源 文件和数据库连接池-->
<!-- 加载数据库连接资源文件 -->
<context:property-placeholder location="classpath:db.properties"/>
<!-- 配置数据库连接池 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${mysql.driver}"></property>
<property name="jdbcUrl" value="${mysql.url}"></property>
<property name="user" value="${mysql.user}"></property>
<property name="password" value="${mysql.password}"></property>
</bean>
<!-- 第二步:创建SqlSessionFactory,生产sqlSession -->
<bean id="SqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="configLocation" value="classpath:mybatis-confg.xml"></property>
<property name="mapperLocations" value="classpath:mapper/**/*.xml"></property>
</bean>
<!-- 配置mapper扫描器、映射文件,由于映射文件mybatis.xml可以为空,此处需要配置dao接口的具体映射文件路径 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="dao"></property>
<property name="SqlSessionFactoryBeanName" value="SqlSessionFactory"></property>
</bean>
<!-- 上传文件拦截,设置最大上传文件大小 10M=10*1024*1024(B)=10485760 bytes -->
<!-- <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8" />
<property name="maxUploadSize" value="104857600"/>
<property name="maxInMemorySize" value="4096"/>
</bean> -->
<!-- SpringMVC上传文件时,需要配置MultipartResolver处理器 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8"/>
<!-- 指定所上传文件的总大小不能超过200KB。注意maxUploadSize属性的限制不是针对单个文件,而是所有文件的容量之和 -->
<property name="maxUploadSize" value="200000"/>
<!-- 最大内存大小 (10240)-->
<property name="maxInMemorySize" value="40960" />
</bean>
<!-- SpringMVC在超出上传文件限制时,会抛出org.springframework.web.multipart.MaxUploadSizeExceededException -->
<!-- 该异常是SpringMVC在检查上传的文件信息时抛出来的,而且此时还没有进入到Controller方法中 -->
<bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<!-- 遇到MaxUploadSizeExceededException异常时,自动跳转到/WEB-INF/jsp/error_fileupload.jsp页面 -->
<prop key="org.springframework.web.multipart.MaxUploadSizeExceededException">error_fileupload</prop>
</props>
</property>
</bean>
</beans>
db.properties文件配置
#mysql.driver=com.mysql.jdbc.Driver
#mysql.url=jdbc:mysql://localhost:3306/xxx
#mysql.user=xxx
#mysql.password=xxx
#\u52A0\u8F7D\u9A71\u52A8
mysql.driver=com.mysql.cj.jdbc.Driver
#\u52A0\u8F7D\u6570\u636E\u5E93
mysql.url=jdbc:mysql://localhost:3306/peixian?serverTimezone=UTC&characterEncoding=utf-8
#\u7528\u6237\u540D
mysql.user=root
#\u5BC6\u7801
mysql.password=
maven中settings.xml文件配置
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>D:\peiEclipse\peizhongxianOneselfWorkspace\repository</localRepository>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</settings>
2.=====================
java web项目配置文件
1.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_3_0.xsd"
id="WebApp_ID" version="3.0">
<!-- 配置Spring配置文件路径 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:applicationContext.xml
</param-value>
</context-param>
<!-- 配置Spring上下文监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 配置Spring字符编码过滤器 -->
<filter>
<filter-name>encodingFilter</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>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 防注入 -->
<filter>
<filter-name>sqlfilter</filter-name>
<filter-class>com.zw.framework.interceptor.SqlFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sqlfilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<filter>
<filter-name>xssfilter</filter-name>
<filter-class>com.zw.framework.interceptor.XssFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>xssfilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>xssfilter</filter-name>
<url-pattern>*.html</url-pattern>
</filter-mapping>
<!-- 页面交互拦截器 -->
<filter>
<filter-name>validloginfilter</filter-name>
<filter-class>com.zw.framework.interceptor.ValidLoginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>validloginfilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>validloginfilter</filter-name>
<url-pattern>*.html</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>validloginfilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<!-- springMVC核心配置 -->
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/actservice/*</url-pattern>
</servlet-mapping>
<!-- 首页 -->
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
//拦截器======
ValidLoginFilter.java
package com.zw.framework.interceptor;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.zw.framework.bean.ErrorType;
import com.zw.framework.bean.ResultBean;
import com.zw.framework.bean.UserBean;
import com.zw.framework.context.ContextAware.SContextAware;
import com.zw.framework.critical.CriticalObject;
import com.zw.framework.critical.Local;
import com.zw.framework.utils.CommonUtils;
import com.zw.framework.utils.Globals;
import com.zw.framework.utils.ProjectUtils;
import com.zw.framework.utils.SessionUtils;
public class ValidLoginFilter implements Filter {
public void doFilter(ServletRequest requ, ServletResponse resp, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) requ;
final HttpServletResponse response = (HttpServletResponse) resp;
String url = request.getRequestURL().toString();
boolean beFilter = true;
//
if (request.getRequestURI().startsWith("/tiantian/ceshi/") || request.getRequestURI().startsWith("/tiantian/kankan/") || request.getRequestURI().startsWith("/tiantian/nihao/") || request.getRequestURI().startsWith("/tiantian/shijie/")
|| request.getRequestURI().startsWith("/sup/useragreement/") ) {
beFilter = false;
} else
for (String s : Globals.NOFILTERS) {
if (url.endsWith(s)) {
beFilter = false;
break;
}
}
if (beFilter) {
HttpSession session = request.getSession();
UserBean bean = (UserBean) session.getAttribute(Globals.SYSTEM_USER);
if (bean == null || CommonUtils.isEmpty(bean.getUserid())) {
String sessionid = request.getParameter("JSESSIONID");
String systemtype = request.getParameter("systemtype");
if (!CommonUtils.isEmpty(sessionid)) {
HttpSession old_session = SessionUtils.SessionContext.get(sessionid);
session.setAttribute(Globals.SYSTEM_USER, old_session.getAttribute(Globals.SYSTEM_USER));
} else {
if (!CommonUtils.isEmpty(systemtype)) {
ResultBean retVal = new ResultBean(false, "未登录");
ProjectUtils.writeJson(retVal);
} else {
ProjectUtils.sendError(ErrorType.E999, request, response);
}
return;
}
}
}
setBasePath(request);
setCriticalObject(request, response);
chain.doFilter(request, response);
}
@Override
public void destroy() {
}
@Override
public void init(FilterConfig arg0) throws ServletException {
}
/**
* 设置项目路径到request中
*
* @param request
*/
private void setBasePath(HttpServletRequest request) {
request.setAttribute(Globals.BASE_PATH, request.getContextPath());
}
/**
* 设置当前线程环境
*
* @param req
* @param res
*/
private void setCriticalObject(final HttpServletRequest req, final HttpServletResponse res) {
Local.setCriticalObject(new CriticalObject() {
private final HttpServletResponse response = res;
private final HttpServletRequest request = req;
public String getRoot() {
return SContextAware.getServletContext().getRealPath("/");
}
public String getBasePath() {
return request.getContextPath();
}
public HttpServletResponse getResponse() {
return response;
}
public HttpSession getSession() {
return request.getSession(false);
}
public String getContextPath() {
return request.getContextPath();
}
public HttpServletRequest getRequest() {
return request;
}
public UserBean getUserBean() {
return (UserBean) request.getSession(false).getAttribute("TIANTIAN");
}
});
}
}
2.applicationContext.xml 文件配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:cache="http://www.springframework.org/schema/cache" xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://www.springframework.org/schema/cache
http://www.springframework.org/schema/cache/spring-cache.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task.xsd">
<!-- 自动扫描组件,这里要把web下面的 controller去除,他们是在spring-mvc.xml中配置的,如果不去除会影响事务管理的。 -->
<context:component-scan base-package="com.zw">
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<!-- 定时器开关 -->
<task:annotation-driven />
<!-- 扫描任务 -->
<context:component-scan base-package="com.zw.task" />
<!-- 引入配置文件 -->
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath*:application.properties</value>
</list>
</property>
</bean>
<!-- dataSource 配置 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<!-- 基本属性 url、user、password -->
<property name="driverClassName" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="dbType" value="${jdbc.dbType}" />
<!-- 初始化连接大小 -->
<property name="initialSize" value="${ds.initialSize}" />
<!-- 连接池最小空闲 -->
<property name="minIdle" value="${ds.minIdle}" />
<!-- 连接池最大使用连接数 -->
<property name="maxActive" value="${ds.maxActive}" />
<!-- 配置获取连接等待超时的时间 -->
<property name="maxWait" value="${ds.maxWait}" />
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="${ds.timeBetweenEvictionRunsMillis}" />
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="${ds.minEvictableIdleTimeMillis}" />
<!-- 自动清除无用连接 -->
<property name="removeAbandoned" value="${ds.removeAbandoned}" />
<!-- 清除无用连接的等待时间 -->
<property name="removeAbandonedTimeout" value="${ds.removeAbandonedTimeout}" />
<!--<property name="validationQuery" value="select 'x'"/> -->
<property name="testWhileIdle" value="true" />
<property name="testOnBorrow" value="false" />
<property name="testOnReturn" value="false" />
<!-- 打开PSCache,并且指定每个连接上PSCache的大小 -->
<property name="poolPreparedStatements" value="false" />
<property name="maxPoolPreparedStatementPerConnectionSize"
value="20" />
<!-- 配置监控统计拦截的filters -->
<property name="filters" value="wall,stat" />
</bean>
<!-- 初始化dbutil -->
<bean class="com.zw.framework.engine.mybatis.jdbc.DBUtil" id="dbUtil">
<property name="driverClassName" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<!-- 初始化WeChatUtil -->
<bean class="com.zw.wechat.utils.WeChatUtil" id="weChatUtil">
<property name="token" value="${weChat.token}" />
<property name="appid" value="${weChat.appid}" />
<property name="secret" value="${weChat.secret}" />
<property name="mch_id" value="${weChat.mch_id}" />
<property name="api_key" value="${weChat.api_key}" />
</bean>
<!-- 初始化SapUtil -->
<bean class="com.zw.framework.utils.SapUtil" id="sapUtil">
<property name="ip" value="${sap.id}" />
<property name="port" value="${sap.port}" />
</bean>
<!-- 初始化MailUtil -->
<bean class="com.zw.wechat.utils.MailUtil" id="mailUtil">
<property name="mail_host" value="${mail.host}" />
<property name="mail_username" value="${mail.username}" />
<property name="mail_password" value="${mail.password}" />
<property name="mail_emp_username" value="${mail.emp.username}" />
<property name="mail_mgr_username" value="${mail.mgr.username}" />
</bean>
<!-- mybatis文件配置,扫描所有mapper文件 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"
p:dataSource-ref="dataSource" p:configLocation="classpath:mybatis-config.xml"
p:mapperLocations="classpath:com/tiantian/**/*.xml" />
<!-- spring与mybatis整合配置,扫描所有dao -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"
p:sqlSessionFactoryBeanName="sqlSessionFactory" p:basePackage="com.tiantian.**" />
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate"
scope="prototype">
<constructor-arg index="0" ref="sqlSessionFactory" />
</bean>
<bean class="tk.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage"
value="com.zw.platform.mapper,com.zw.business.**.mapper" />
</bean>
<!-- 对dataSource 数据源进行事务管理 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
p:dataSource-ref="dataSource" />
<!-- 事务管理 通知 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!-- 定义以下开头的方法名都是只读的模式 -->
<tx:method name="select*" read-only="true" />
<tx:method name="count*" read-only="true" />
<tx:method name="get*" read-only="true" />
<tx:method name="query*" read-only="true" />
<tx:method name="find*" read-only="true" />
<tx:method name="load*" read-only="true" />
<!-- 其他所有方法都使用事务 -->
<tx:method name="*" propagation="REQUIRED" read-only="false"
rollback-for="Exception" />
</tx:attributes>
</tx:advice>
<!-- 事务 aop 配置 -->
<aop:config>
<!-- 定义一个切入点 -->
<aop:pointcut id="serviceMethods"
expression="execution(* com.zw.**.service.*Service.*(..))" />
<!-- 对切入点和事务的通知,进行适配 -->
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethods" />
</aop:config>
<!-- 启动对@AspectJ注解的支持 -->
<aop:aspectj-autoproxy />
<!-- 启用对事务注解的支持 -->
<tx:annotation-driven transaction-manager="transactionManager" />
<!-- 本地资源配置文件 -->
<bean class="com.zw.framework.context.LocalSpace" id="localSpace">
<property name="localSpaceRoot" value="${file.localspace}" />
</bean>
<!-- 项目环境资源 -->
<bean class="com.zw.framework.context.ProjectContext" id="projectContext">
<property name="localSpace" ref="localSpace" />
</bean>
<!-- 获取项目配置 -->
<bean id="contextAware" class="com.zw.framework.context.ContextAware.SContextAware" />
<bean id="appContextAware" class="com.zw.framework.context.ContextAware.AppContextAware" />
<!-- 系统初始化 -->
<bean class="com.zw.framework.global.ProjectInitialize" />
<!-- 文件上传 -->
<bean
class="org.springframework.web.multipart.commons.CommonsMultipartResolver"
id="multipartResolver" p:defaultEncoding="utf-8" />
<!-- aop拦截控制 -->
<bean class="com.zw.framework.interceptor.annotation.SystemLogAspect" />
</beans>
//初始化实例==================
<!-- 初始化MailUtil -->
<bean class="com.zw.wechat.utils.MailUtil" id="mailUtil">
<property name="mail_host" value="${mail.host}" />
<property name="mail_username" value="${mail.username}" />
<property name="mail_password" value="${mail.password}" />
<property name="mail_emp_username" value="${mail.emp.username}" />
<property name="mail_mgr_username" value="${mail.mgr.username}" />
</bean>
//java类
public class MailUtil {
// #服务器主机名
public static String mail_host = "";
// #发送邮箱地址
public static String mail_username = "";
// #你的授权码
public static String mail_password = "";
// #接受邮箱地址
public static String mail_emp_username = "";
// #接受邮箱地址
public static String mail_mgr_username = "";
public static String getMail_host() {
return mail_host;
}
public static void setMail_host(String mail_host) {
MailUtil.mail_host = mail_host;
}
public static String getMail_username() {
return mail_username;
}
public static void setMail_username(String mail_username) {
MailUtil.mail_username = mail_username;
}
public static String getMail_password() {
return mail_password;
}
public static void setMail_password(String mail_password) {
MailUtil.mail_password = mail_password;
}
public static String getMail_emp_username() {
return mail_emp_username;
}
public static void setMail_emp_username(String mail_emp_username) {
MailUtil.mail_emp_username = mail_emp_username;
}
public static String getMail_mgr_username() {
return mail_mgr_username;
}
public static void setMail_mgr_username(String mail_mgr_username) {
MailUtil.mail_mgr_username = mail_mgr_username;
}
}
//application.properties 文件配置
#############################数据库连接#############################
jdbc.dbType=oracle
jdbc.driver=oracle.jdbc.driver.OracleDriver
#jdbc.driver=net.sf.log4jdbc.DriverSpy
#jdbc.url=jdbc:oracle:thin:@haitundao.com.cn:1999:orcl 118.66.149.88
jdbc.url=jdbc:oracle:thin:@188.16.180.7:1633:ORCL
jdbc.username=tiantian
jdbc.password=tiantian
#############################基本配置#############################
#资源路径
file.localspace=D:/D_document/tian
#一个用户只能同时一个人在线
sys.singleOnline=true
#############################微信配置#############################
weChat.token=tiantian
weChat.appid=d146b685cc78b90b12abb
weChat.secret=685cc78b90b12abb70de5
weChat.mch_id=123456987
weChat.api_key=U4CvmuYvHwzDYX27xPQpLNuWBv7ISS4f
#############################SAP配置#############################
sap.id=133.266.222.00
sap.port=3050
############################OpenOffice配置,屏蔽office.home后默认为不转pdf,无法预览文件。#############################
office.home=
office.port=9600
office.profile=
office.format=PDF,DOC,DOCX,PPT,PPTX,XLS,XLSX,TXT,WPS,ODT,PNG,GIF,JPG,HTML
#######################数据源的全局设置#########################################
#配置初始化大小、最小、最大
ds.initialSize=1
ds.minIdle=1
ds.maxActive=20
#配置获取连接等待超时的时间
ds.maxWait=60000
#配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
ds.timeBetweenEvictionRunsMillis=60000
#配置一个连接在池中最小生存的时间,单位是毫秒
ds.minEvictableIdleTimeMillis=300000
#自动清除无用连接
ds.removeAbandoned=true
#清除无用连接的等待时间
ds.removeAbandonedTimeout=180
######################邮件发送设置#####################################
#服务器主机名
mail.host=mail.tiantian.com
#发送邮箱地址
mail.username=tiantian_service@tiantian.com
#你的授权码
mail.password=tiantian123456
#接受邮箱地址-员工
mail.emp.username=tiantian_service@tiantian.com
#接受邮箱地址-管理
mail.mgr.username=tiantian_service@tiantian.com
//spring-mvc.xml文件配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
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
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 把标记了@Controller注解的类转换为bean -->
<context:component-scan base-package="com.zw.**.controller">
<context:exclude-filter type="annotation"
expression="org.springframework.stereotype.Service" />
</context:component-scan>
<!-- <mvc:annotation-driven /> -->
<!--通知spring使用cglib而不是jdk的来生成代理方法 AOP可以拦截到Controller -->
<aop:aspectj-autoproxy proxy-target-class="true" />
<!-- 国际化 -->
<bean class="org.springframework.context.support.ResourceBundleMessageSource"
id="messageSource">
<property name="basename" value="messages/messages" />
</bean>
<!-- Cookie -->
<bean class="org.springframework.web.servlet.i18n.CookieLocaleResolver"
id="localeResolver" />
<bean
class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"
id="rmhp" />
<!-- 支持返回json(避免IE在ajax请求时,返回json出现下载 ) -->
<bean
class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<!-- 请求日期格式转换 -->
<property name="webBindingInitializer">
<bean class="com.zw.framework.interceptor.DateConverter" />
</property>
<property name="messageConverters">
<list>
<ref bean="mappingJackson2HttpMessageConverter" /> <!-- 处理json -->
<bean
class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter" />
</list>
</property>
<property name="customArgumentResolvers">
<list>
<bean
class="com.zw.framework.interceptor.transcoding.BeanArgumentResolver"></bean>
<bean
class="com.zw.framework.interceptor.transcoding.ListArgumentResolver"></bean>
</list>
</property>
</bean>
<!-- 处理json -->
<bean id="mappingJackson2HttpMessageConverter"
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="objectMapper">
<bean class="com.fasterxml.jackson.databind.ObjectMapper">
<property name="dateFormat">
<bean class="java.text.SimpleDateFormat">
<constructor-arg type="java.lang.String" value="yyyy-MM-dd HH:mm:ss" />
</bean>
</property>
<!-- 为null字段时不显示 -->
<property name="serializationInclusion">
<value type="com.fasterxml.jackson.annotation.JsonInclude.Include">NON_NULL</value>
</property>
</bean>
</property>
<property name="tianportedMediaTypes">
<list>
<value>text/plain;charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
<!-- 对模型视图添加前后缀-->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/" p:suffix=".jsp"/>
<!-- 配置springMVC处理上传文件的信息 10485760000 -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="utf-8" />
<property name="maxUploadSize" value="10485760000" />
<property name="maxInMemorySize" value="40960" />
</bean>
<!-- ContextAware对象获取 -->
<bean id="mvcContextAware" class="com.zw.framework.context.ContextAware.MvcContextAware" />
<!-- 注册XmlViewResolver,用于iReport & JasperReports报表生成 -->
<beans:bean id="jasperReportResolver" class="org.springframework.web.servlet.view.XmlViewResolver">
<beans:property name="order">
<beans:value>0</beans:value>
</beans:property>
<beans:property name="location">
<beans:value>WEB-INF/jasper/jasper-defs.xml</beans:value>
</beans:property>
</beans:bean>
</beans>
//generatorConfig.xml 文件配置=======
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<!-- classPathEntry:数据库的JDBC驱动的jar包地址 -->
<classPathEntry
location="E:\code\git\tian\tiantian\WebContent\WEB-INF\lib\ojdbc14.jar" />
<context id="DB2Tables" targetRuntime="MyBatis3">
<commentGenerator>
<!-- 抑制警告 -->
<property name="suppressTypeWarnings" value="true" />
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true" />
<!-- 是否生成注释代时间戳 -->
<property name="suppressDate" value="true" />
</commentGenerator>
<!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver"
connectionURL="jdbc:oracle:thin:@192.168.91.778:1533:orcl" userId="tiantian"
password="tiantian">
</jdbcConnection>
<javaModelGenerator targetPackage="com.zw.sp.model"
targetProject="sup/JavaSource">
<property name="enableSubPackages" value="false" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<sqlMapGenerator targetPackage="com.zw.sp.mapper"
targetProject="tian/JavaSource">
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<javaClientGenerator type="XMLMAPPER" targetPackage="com.zw.sp.mapper"
targetProject="tian/JavaSource">
<property name="enableSubPackages" value="false"/>
</javaClientGenerator>
<!-- tableName:用于自动生成代码的数据库表;domainObjectName:对应于数据库表的javaBean类名 -->
<!-- <table schema="untodo" tableName="T_USER" domainObjectName="User"/> -->
<!-- 要生成那些表(更改tableName和domainObjectName就可以) -->
<!-- <table schema="untodo" tableName="T_USER" domainObjectName="User"
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false"/> -->
<!--生成对应表及类名 -->
<table tableName="TDLZHXX" domainObjectName="Tdlzhxx" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
<!--domain字段的命名规则,false:默认为驼峰命名 true:按数据库真实命名 -->
<property name="useActualColumnNames" value="false" />
<!-- 忽略列,不生成bean 字段 -->
<!-- <ignoreColumn column="FRED" /> -->
<!-- 指定列的java数据类型 -->
<!-- <columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" /> -->
</table>
<table tableName="TKCYJ" domainObjectName="Tkcyj" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
<property name="useActualColumnNames" value="false" />
</table>
<table tableName="TKFXX" domainObjectName="Tkfxx" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
<property name="useActualColumnNames" value="false" />
</table>
<table tableName="TKHDJXX" domainObjectName="Tkhdjxx" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
<property name="useActualColumnNames" value="false" />
</table>
<table tableName="TKHXX" domainObjectName="Tkhxx" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
<property name="useActualColumnNames" value="false" />
</table>
<table tableName="TKWXX" domainObjectName="Tkwxx" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
<property name="useActualColumnNames" value="false" />
</table>
<table tableName="TSPXX" domainObjectName="Tspxx" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
<property name="useActualColumnNames" value="false" />
</table>
<table tableName="TSPXX_HD" domainObjectName="TspxxHd" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
<property name="useActualColumnNames" value="false" />
</table>
<table tableName="TSPXX_PF" domainObjectName="TspxxPf" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
<property name="useActualColumnNames" value="false" />
</table>
<table tableName="TSPXX_TC" domainObjectName="TspxxTc" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
<property name="useActualColumnNames" value="false" />
</table>
</context>
</generatorConfiguration>
//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>
<!-- 配置mybatis的缓存,延迟加载等等一系列属性 -->
<settings>
<!-- 全局映射器启用缓存 -->
<setting name="cacheEnabled" value="true" />
<!-- 查询时,关闭关联对象即时加载以提高性能 -->
<setting name="lazyLoadingEnabled" value="true" />
<!-- 对于未知的SQL查询,允许返回不同的结果集以达到通用的效果 -->
<setting name="multipleResultSetsEnabled" value="true" />
<!-- 允许使用列标签代替列名 -->
<setting name="useColumnLabel" value="true" />
<!-- 不允许使用自定义的主键值(比如由程序生成的UUID 32位编码作为键值),数据表的PK生成策略将被覆盖 -->
<setting name="useGeneratedKeys" value="false" />
<!-- 给予被嵌套的resultMap以字段-属性的映射支持 FULL,PARTIAL -->
<setting name="autoMappingBehavior" value="PARTIAL" />
<!-- 对于批量更新操作缓存SQL以提高性能 BATCH,SIMPLE -->
<!-- <setting name="defaultExecutorType" value="BATCH" /> -->
<!-- 数据库超过25000秒仍未响应则超时 -->
<!-- <setting name="defaultStatementTimeout" value="25000" /> -->
<!-- Allows using RowBounds on nested statements -->
<setting name="safeRowBoundsEnabled" value="false" />
<!-- Enables automatic mapping from classic database column names A_COLUMN
to camel case classic Java property names aColumn. -->
<setting name="mapUnderscoreToCamelCase" value="true" />
<!-- MyBatis uses local cache to prevent circular references and speed
up repeated nested queries. By default (SESSION) all queries executed during
a session are cached. If localCacheScope=STATEMENT local session will be
used just for statement execution, no data will be shared between two different
calls to the same SqlSession. -->
<setting name="localCacheScope" value="SESSION" />
<!-- Specifies the JDBC type for null values when no specific JDBC type
was provided for the parameter. Some drivers require specifying the column
JDBC type but others work with generic values like NULL, VARCHAR or OTHER. -->
<setting name="jdbcTypeForNull" value="NULL" />
<!-- Specifies which Object's methods trigger a lazy load -->
<setting name="lazyLoadTriggerMethods" value="equals,clone,hashCode,toString" />
<!-- 设置关联对象加载的形态,此处为按需加载字段(加载字段由SQL指 定),不会加载关联表的所有字段,以提高性能 -->
<setting name="aggressiveLazyLoading" value="false" />
<!-- 如果字段为空也进行结果集映射 -->
<setting name="callSettersOnNulls" value="true"/>
</settings>
<!-- mybatis的xml中引用的对象 -->
<typeAliases>
<package name="com.zw.**.model" />
<package name="com.zw.framework.bean" />
</typeAliases>
<plugins>
<plugin interceptor="com.github.pagehelper.PageHelper">
</plugin>
</plugins>
</configuration>