SSH:1
阿新 • • 發佈:2018-12-19
https://download.csdn.net/download/qq_43532342/10811031
自來水+電力專案
SSH整合使用。
<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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>WaterAdmin</groupId> <artifactId>WaterAdmin</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>WaterAdmin Maven Webapp</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.4</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>4.3.10.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> <version>4.3.10.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> <version>4.3.10.RELEASE</version> </dependency> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-spring-plugin</artifactId> <version>2.3.33</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.1</version> </dependency> <dependency> <groupId>com.mchange</groupId> <artifactId>c3p0</artifactId> <version>0.9.5.2</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>4.0.0-b07</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>5.2.10.Final</version> </dependency> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-core</artifactId> <version>2.3.33</version> <exclusions> <exclusion> <artifactId>javassist</artifactId> <groupId>javassist</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>2.8.2</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-ehcache</artifactId> <version>5.2.10.Final</version> </dependency> </dependencies> <build> <finalName>WaterAdmin</finalName> </build> </project>
pom
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app> <display-name>Archetype Created Web Application</display-name> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext-*.xml</param-value> </context-param> <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>/*</url-pattern> </filter-mapping> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <welcome-file-list> <welcome-file>workspace.jsp</welcome-file> </welcome-file-list> <error-page> <error-code>404</error-code> <location>/error.jsp</location> </error-page> <error-page> <error-code>500</error-code> <location>/error.jsp</location> </error-page> </web-app>
web
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="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/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/cn?characterEncoding=utf-8"></property> <property name="driverClass" value="com.mysql.jdbc.Driver"></property> <property name="user" value="root"></property> <property name="password" value="root"></property> <property name="initialPoolSize" value="3"></property> <property name="maxPoolSize" value="20"></property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"></property> <property name="configLocation" value="classpath:hibernate.cfg.xml"></property> <property name="mappingLocations" value="classpath:com/cn/entity/*.hbm.xml"></property> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <tx:advice id="txadvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="save*" propagation="REQUIRED" /> <tx:method name="delete*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="*" read-only="true" /> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut expression="execution(* com.cn.biz.impl.*.*(..))" id="aoppointcut" /> <aop:advisor advice-ref="txadvice" pointcut-ref="aoppointcut" /> </aop:config> </beans>
Spring
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="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/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<bean id="pyDaoImpl" class="com.cn.dao.impl.PyDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="pyBizImpl" class="com.cn.biz.impl.PyBizImpl">
<property name="pyDao" ref="pyDaoImpl"></property>
</bean>
<bean id="PayAction" class="com.cn.action.PayAction"
scope="prototype">
<property name="pyBiz" ref="pyBizImpl"></property>
</bean>
<bean id="syDaoImpl" class="com.cn.dao.impl.SyDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="syBizImpl" class="com.cn.biz.impl.SyBizImpl">
<property name="syDao" ref="syDaoImpl"></property>
</bean>
<bean id="EmpAction" class="com.cn.action.EmpAction"
scope="prototype">
<property name="syBiz" ref="syBizImpl"></property>
</bean>
<bean id="PowerAction" class="com.cn.action.PowerAction"
scope="prototype">
<property name="syBiz" ref="syBizImpl"></property>
</bean>
<bean id="AreaSetAction" class="com.cn.action.AreaSetAction"
scope="prototype">
<property name="syBiz" ref="syBizImpl"></property>
</bean>
<bean id="MenuAction" class="com.cn.action.MenuAction"
scope="prototype">
<property name="syBiz" ref="syBizImpl"></property>
</bean>
<bean id="PermAction" class="com.cn.action.PermAction"
scope="prototype">
<property name="syBiz" ref="syBizImpl"></property>
</bean>
<bean id="usDaoImpl" class="com.cn.dao.impl.UsDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="usBizImpl" class="com.cn.biz.impl.UsBizImpl">
<property name="usDao" ref="usDaoImpl"></property>
</bean>
<bean id="SearchUserAction" class="com.cn.action.SearchUserAction"
scope="prototype">
<property name="usBiz" ref="usBizImpl"></property>
</bean>
<bean id="SaveUserAction" class="com.cn.action.SaveUserAction"
scope="prototype">
<property name="usBiz" ref="usBizImpl"></property>
</bean>
<bean id="UserMeterAction" class="com.cn.action.UserMeterAction"
scope="prototype">
<property name="usBiz" ref="usBizImpl"></property>
</bean>
<bean id="UsersAction" class="com.cn.action.UsersAction"
scope="prototype">
<property name="usBiz" ref="usBizImpl"></property>
</bean>
</beans>
Bean