SSM整合
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_2_5.xsd"
version="2.5">
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>hterp.root</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring.xml</param-value>
</context-param>
<filter>
<filter-name>UserValidationFilter</filter-name>
<filter-class>com.shdl.hterp.filter.UserValidationFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>UserValidationFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.do</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<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>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>com.shdl.hterp.listener.InitSystemListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>/mis/login.jsp</welcome-file>
</welcome-file-list>
<error-page>
<error-code>404</error-code>
<location>/404.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/500.jsp</location>
</error-page>
<session-config>
<session-timeout>480</session-timeout>
</session-config>
<!-- 自定义JSP标签 -->
<jsp-config>
<taglib>
<taglib-uri>/hterp/erp</taglib-uri>
<taglib-location>/WEB-INF/tlds/erp.tld</taglib-location>
</taglib>
</jsp-config>
<!-- 自定义JSP标签结束 -->
</web-app>
2.整体spring+struts+mybatis配置
a. spring配置
<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
<!-- 启用AspectJ对Annotation的支持 -->
<aop:aspectj-autoproxy/>
<!-- <aop:aspectj-autoproxy proxy-target-class="false"/> -->
<bean id="myAspect" class="com.shdl.hterp.business.base.AspectBean"/>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:hterp.cfg</value>
</list>
</property>
</bean>
<bean id="springContextUtil" class="com.shdl.hterp.utils.SpringContextUtil"/>
<!-- 调度服务 -->
<bean id="quartzScheduler" lazy-init="false" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list/>
</property>
</bean>
<bean id="schedulerSrv" class="com.shdl.hterp.common.SchedulerServiceImpl">
<property name="scheduler" ref="quartzScheduler"/>
</bean>
<!-- 调度服务结束 -->
<!-- 导入业务配置文件 -->
<import resource="spring-conf/*.xml"/>
</beans>
b. struts配置
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="false"/>
<constant name="struts.i18n.encoding" value="UTF-8"/>
<constant name="struts.enable.DynamicMethodInvocation" value="true"/>
<constant name="struts.objectFactory" value="spring"/>
<constant name="struts.objectFactory.spring.autoWire" value="type"/>
<constant name="struts.multipart.maxSize" value="314572800"/>
<constant name="struts.multipart.saveDir" value="F:/root/resource/hterp/temp"/>
<constant name="struts.objectFactory.spring.autoWire.alwaysRespect" value="true"/>
<!-- 全局最大上传100M -->
<constant name="struts.action.extension" value="do"/>
<!--系统管理-->
<include file="struts-conf/*.xml"/>
</struts>
c. mybatis配置
<?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>
<settings>
<setting name="jdbcTypeForNull" value="NULL"/>
</settings>
<!-- 全局别名设置,在映射文件中只需写别名,而不必写出整个类路径 -->
<typeAliases>
<package name="com.shdl.hterp.beans"/>
</typeAliases>
</configuration>
PS:mybatis的别名配置:使用注解在POJO配置在类中
@Alias("companyBean")
public class CompanyBean extends Page {
private String companyid; // 主键ID
private String companyname; // 公司名称
private String companycode; // 纳税人识别号
private String companyaddress; // 企业经营地址
private String companyaccount; // 开户行以及账号
private String companytel; // 联系电话
private String companyremark; // 备注
private String companytype; // 公司类型
private String companyorderno; // 排序字段
private String deletetime; // 删除时间