struts2.3.1.1+hibernate3.6.9Final+spring3.1.0+proxool+maven+annotation
==============POM.XML==============
pom.xml
<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>com.tcs.org.demostic</groupId>
<artifactId>mydemo</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>mydemo Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<finalName>mydemo</finalName>
</properties>
<repositories>
<repository>
<id>MavenCentral</id>
<name>Maven repository</name>
<url>http://repo1.maven.org/maven2</url>
</repository>
<repository>
<id>Codehaus Snapshots</id>
<url>http://snapshots.repository.codehaus.org/</url>
</repository>
<repository>
<id>ibiblio</id>
<url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
</repository>
<repository>
<id>datanucleus</id>
<url>http://www.datanucleus.org/downloads/maven2/</url>
</repository>
<repository>
<id>gwt-maven</id>
<url>http://gwt-maven.googlecode.com/svn/trunk/mavenrepo/</url>
</repository>
<repository>
<id>maven2-repository.dev.java.net</id>
<url>http://download.java.net/maven/2/</url>
</repository>
<repository>
<id>jboss</id>
<url>http://repository.jboss.com/maven2</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>apache.snapshots</id>
<name>Apache Snapshot Repository</name>
<url>http://people.apache.org/repo/m2-snapshot-repository</url>
<releases>
<enabled>false</enabled>
</releases>
</pluginRepository>
<pluginRepository>
<id>Codehaus Snapshots</id>
<url>http://snapshots.repository.codehaus.org/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</pluginRepository>
<pluginRepository>
<id>MavenCentral</id>
<name>Maven repository</name>
<url>http://repo1.maven.org/maven2</url>
</pluginRepository>
<pluginRepository>
<id>ibiblio</id>
<url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
</pluginRepository>
<pluginRepository>
<id>datanucleus</id>
<url>http://www.datanucleus.org/downloads/maven2/</url>
</pluginRepository>
<pluginRepository>
<id>gwt-maven</id>
<url>http://gwt-maven.googlecode.com/svn/trunk/mavenrepo/</url>
</pluginRepository>
<pluginRepository>
<id>maven2-repository.dev.java.net</id>
<url>http://download.java.net/maven/2/</url>
</pluginRepository>
<pluginRepository>
<id>jboss</id>
<url>http://repository.jboss.com/maven2</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<!--============J2EE容器所需包===============-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>aopalliance</groupId>
<artifactId>aopalliance</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.6.12</version>
</dependency>
<!--=============commons===================-->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>commons-chain</groupId>
<artifactId>commons-chain</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>commons-digester</groupId>
<artifactId>commons-digester</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<!-- 集合类 -->
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<!--===============dom4j====================-->
<!-- XML配置和映射管理器-->
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
<!--==============字节码库=====================-->
<!-- ASM字节码库 -->
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>3.1</version>
</dependency>
<!-- ASM字节码库-->
<dependency>
<groupId>asm</groupId>
<artifactId>asm-attrs</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm-commons</artifactId>
<version>3.3.1</version>
</dependency>
<!--===================SpringDM Bundle================-->
<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>spring-osgi-core</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>spring-osgi-mock</artifactId>
<version>1.1.3</version>
</dependency>
<!--===================Felix Bundle================-->
<!--===================spring3.1.0.RELEASE================-->
<dependency>
<groupId>quartz</groupId>
<artifactId>quartz</artifactId>
<version>1.5.1</version>
</dependency>
<!-- spring必须包 -->
<!-- spring核心包 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.1.0.RELEASE</version>
<!-- spring-asm-3.1.0.RELEASE.jar -->
<!-- commons-logging-1.1.1.jar -->
</dependency>
<!-- 利用IOC管理Bean的包 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>
<!-- 对bean再次封装后的包,方便性强。 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.1.0.RELEASE</version>
<!-- spring-expression-3.1.0.RELEASE.jar -->
<!-- spring-aop-3.1.0.RELEASE.jar -->
<!-- aopalliance-1.0.jar -->
</dependency>
<!-- spring扩展包 -->
<!-- SpringWeb下的工具包 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>
<!-- 支持hibernate,对对象映射框架的支持 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.1.0.RELEASE</version>
<!-- spring-tx-3.1.0.RELEASE.jar -->
<!-- spring-jdbc-3.1.0.RELEASE.jar -->
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>3.1.0.RELEASE</version>
<!-- spring-tx-3.1.0.RELEASE.jar -->
<!-- spring-jdbc-3.1.0.RELEASE.jar -->
</dependency>
<!--================struts2.3.1.1=================-->
<!-- struts2.3.1.1必须包 --><dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.3.1.1</version>
<!-- ognl-3.0.3.jar -->
<!-- asm-commons-3.1.jar -->
<!-- asm-tree-3.1.jar -->
<!-- commons-lang-2.5.jar -->
<!-- commons-fileupload-1.2.2.jar -->
<!-- commons-io-2.0.1.jar -->
<!-- xwork-core-2.3.1.1.jar -->
<!-- javassist-3.11.0.GA.jar -->
<!-- freemarker-2.3.18.jar -->
</dependency>
<!-- struts2对于spring的支持 -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
<version>2.3.1.1</version>
</dependency>
<!-- struts2对于json的支持 -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-json-plugin</artifactId>
<version>2.3.1.1</version>
</dependency>
<!-- struts2对于spring的支持 -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-jfreechart-plugin</artifactId>
<version>2.3.1.1</version>
</dependency>
<!-- struts2中对于注解的支持 -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-convention-plugin</artifactId>
<version>2.3.1.1</version>
</dependency>
<!--==================hibernate3.6.9.Final===================-->
<!-- hibernate3.6.9必须包 -->
<!-- hibernate核心包 -->
<dependency>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.9.Final</version>
</dependency>
<!-- hibernate使用的一个日志系统 -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.4</version>
</dependency>
<!-- ==============mysql数据库驱动 ===================-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.18</version>
</dependency>
<dependency>
<groupId>oracle</groupId>
<artifactId>ojdbc14_g</artifactId>
<version>10.2.0.4</version>
</dependency>
<!-- ==============dbcp数据库连接池 ===================-->
<!--
<dependency> <groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId> <version>1.4</version>
</dependency>
-->
<!-- cglib字节码解释器-->
<!--
<dependency> <groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId> <version>2.2.2</version>
</dependency>
-->
<!-- ==============c3p0数据库连接池 ===================-->
<!--
<dependency> <groupId>c3p0</groupId> <artifactId>c3p0</artifactId>
<version>0.9.1.2</version> </dependency>
-->
<!-- ==============proxool数据库连接池===================-->
<dependency>
<groupId>proxool</groupId>
<artifactId>proxool</artifactId>
<version>0.9.0RC3</version>
</dependency>
<!-- ==============解决jar包冲突问题===================-->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-embedder</artifactId>
<version>2.0</version>
<exclusions>
<exclusion>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<!-- ==============解决build打包问题===================-->
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat6-maven-plugin</artifactId>
<version>2.0-SNAPSHOT</version>
</plugin>
</plugins>
</pluginManagement>
<finalName>mydemo</finalName>
<sourceDirectory>src/main/java</sourceDirectory>
<outputDirectory>src/main/webapp/WEB-INF/classes</outputDirectory>
<defaultGoal>install</defaultGoal>
<resources>
<resource>
<targetPath></targetPath>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<url>http://localhost:8080/manager</url>
<server>myserver</server>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.0</version>
<extensions>false</extensions>
<inherited>true</inherited>
<configuration>
<classifier>test</classifier>
</configuration>
<dependencies></dependencies>
<executions></executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.6</version>
</plugin>
<plugin>
<!-- 设置javac编译器的版本和编码字符 -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<fork>false</fork>
<verbose>true</verbose>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!--
<plugin> <groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.24</version> </plugin
-->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webappDirectory>target/mydemo/webapp
</webappDirectory>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<stopKey>foo</stopKey>
<stopPort>9999</stopPort>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
</project>
==============================WEB.XML========
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee "
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance "
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd ">
<display-name>Archetype Created Web Application</display-name>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>webapp.root</param-value>
</context-param>
<!-- log4j配置文件地址 -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
<!-- 配置spring的配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</context-param>
<!-- 配置proxool的配置文件 -->
<context-param>
<param-name>proxoolConfigLocation</param-name>
<param-value>/WEB-INF/classes/proxool.xml</param-value>
</context-param>
<!-- proxool监听 -->
<listener>
<listener-class>com.tcs.org.demostic.pub.until.ProxoolListener</listener-class>
</listener>
<!-- log4j监听 -->
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<!-- Spring监听 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Spring 刷新Introspector防止内存泄露 -->
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
<!-- Open Session In View Filter -->
<!--
Spring提供的一个针对Hibernate的一个支持类,
发起一个页面请求时打开Hibernate的Session,一直保持这个Session,直到这个请求结束
-->
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- spring编码过滤器 -->
<filter>
<filter-name>Set Character Encoding</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>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Struts2配置信息 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<!-- 指定配置文件路径 -->
<init-param>
<param-name>config</param-name>
<param-value>platform-web.xml,struts-default.xml,struts-plugin.xml,resources/struts/struts.xml</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- proxool提供的管理监控工具,可查看当前数据库连接情况。如果运行不成功,请删除本行 -->
<servlet>
<servlet-name>Admin</servlet-name>
<servlet-class>org.logicalcobwebs.proxool.admin.servlet.AdminServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Admin</servlet-name>
<url-pattern>/Admin</url-pattern>
</servlet-mapping>
<!--验证码servlet -->
<servlet>
<servlet-name>authImg</servlet-name>
<servlet-class>com.tcs.org.demostic.pub.until.AuthImg</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>authImg</servlet-name>
<url-pattern>/authImg</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>authFontImg</servlet-name>
<servlet-class>com.tcs.org.demostic.pub.until.AuthFontImg</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>authFontImg</servlet-name>
<url-pattern>/authFontImg</url-pattern>
</servlet-mapping>
<!-- 欢迎页面 -->
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
</web-app>
=====================APPLICATIONCONTEXT.XML===========
applicationContext.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:aop="http://www.springframework.org/schema/aop "
xmlns:jee="http://www.springframework.org/schema/jee "
xmlns:tx="http://www.springframework.org/schema/tx "
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd "
default-lazy-init="true">
<!-- aop 注解 -->
<aop:aspectj-autoproxy />
<!--
<bean class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator" />
-->
<!-- 使Spring关注Annotation -->
<context:annotation-config />
<!-- 让Spring通过自动扫描来查询和管理Bean-->
<context:component-scan base-package="com.tcs.org.demostic" />
<!--配置文件导入 -->
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>/WEB-INF/classes/proxool.properties</value>
</property>
</bean>
<!--数据源 1 -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>org.logicalcobwebs.proxool.ProxoolDriver</value>
</property>
<property name="url">
<value>proxool.mydemo</value>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<!-- 后台数据源配置连接池 开始 -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${database.dialect}</prop>
<prop key="connection.provider_class">${database.connection}</prop>
<prop key="hibernate.proxool.xml">/WEB-INF/classes/proxool.xml</prop>
<prop key="hibernate.proxool.pool_alias">mydemo</prop>
<!-- 缓存设置默认是EhCache
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
<prop key="hibernate.cache.provider_configuration_file_resource_path">/WEB-INF/classes/ehcache-hibernate.xml</prop>
<prop key="jdbc.batch_size">20</prop>
<prop key="jdbc.fetch_size">20</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.use_structured_entries">true</prop>
-->
<!--hibernate sql设置 -->
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.bytecode.use_reflection_optimizer">true</prop>
</props>
</property>
<!-- 前台数据源配置连接池 开始 -->
<!-- 前台数据源配置连接池 结束 -->
<!--主键Bean类开始-->
<property name="annotatedClasses">
<list>
<!-- pub start-->
<!-- pub Menu bean start -->
<!-- pub Menu bean over -->
<!-- pub over -->
<value>com.tcs.org.demostic.pub.security.group.bean.Group</value>
<value>com.tcs.org.demostic.pub.security.user.bean.User</value>
<value>com.tcs.org.demostic.pub.security.role.bean.Role</value>
<value>com.tcs.org.demostic.pub.security.auth.bean.Auth</value>
<value>com.tcs.org.demostic.pub.security.module.bean.Module</value>
<value>com.tcs.org.demostic.pub.security.menu.bean.Menu</value>
<value>com.tcs.org.demostic.pub.security.user.bean.UserDetail</value>
<value>com.tcs.org.demostic.pub.security.user.bean.UserSituation</value>
<!-- app start-->
<!-- public user bean start -->
<!-- public user bean over -->
<!-- app over -->
</list>
</property>
<!--主键Bean类结束-->
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- 配置事务的传播特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" read-only="false"/>
<tx:method name="update*" propagation="REQUIRED" read-only="false"/>
<tx:method name="delete*" propagation="REQUIRED" read-only="false"/>
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- 那些类的哪些方法参与事务 -->
<aop:config>
<aop:pointcut id="allServiceMethod" expression="execution(* com.tcs.org.demostic.*.*.dao..*(..))" />
<aop:advisor pointcut-ref="allServiceMethod" advice-ref="txAdvice" />
</aop:config>
<!--
配置拦截器 <bean name="logginaop"
class="com.demo.pub.aops.login.LoggingInterceptor" />
-->
<!--
配置拦截器代理 <bean name="loggingAutoProxy"
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames"> <list> <value>/loginon</value>
<value>/reg</value> </list> </property> <property
name="interceptorNames"> <list> <value>logginaop</value> </list>
</property> </bean>
-->
</beans>
=====================hibernate.cfg.xml====用处是生成表的作用==
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd ">
<!-- Generated by MyEclipse Hibernate Tools. 用不到整合到spring中去了 -->
<hibernate-configuration>
<session-factory>
<!-- mysql -->
<property name="connection.url">
jdbc:mysql://localhost:3306/mydemo?useUnicode=true&characterEncoding=utf-8
</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="connection.username">root</property>
<property name="connection.password">1</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<!-- oracle
<property name="connection.url">
jdbc:oracle:thin:@127.0.0.1:1521:demo
</property>
<property name="connection.driver_class">
oracle.jdbc.driver.OracleDriver
</property>
<property name="dialect">
org.hibernate.dialect.OracleDialect
</property>
<property name="connection.username">demo</property>
<property name="connection.password">1</property>
-->
<property name="connection.autocommit">true</property>
<property name="connection.useUnicode">true</property>
<property name="connection.characterEncoding">utf8</property>
<property name="show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.format_sql">true</property>
<mapping class="com.tcs.org.demostic.pub.security.group.bean.Group"/>
<mapping class="com.tcs.org.demostic.pub.security.user.bean.User"/>
<mapping class="com.tcs.org.demostic.pub.security.role.bean.Role"/>
<mapping class="com.tcs.org.demostic.pub.security.auth.bean.Auth"/>
<mapping class="com.tcs.org.demostic.pub.security.module.bean.Module"/>
<mapping class="com.tcs.org.demostic.pub.security.menu.bean.Menu"/>
<mapping class="com.tcs.org.demostic.pub.security.user.bean.UserDetail"/>
<mapping class="com.tcs.org.demostic.pub.security.user.bean.UserSituation"/>
</session-factory>
</hibernate-configuration>
=================================log4j.properties=========
### set log levels ###
log4j.rootLogger = debug, stdout, D, E
### \u8f93\u51fa\u5230\u63a7\u5236\u53f0 ###
#kong zhi tai
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
#log4j.appender.stdout.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [%t:%r] - [%p] %m%n
### \u8f93\u51fa\u5230\u65e5\u5fd7\u6587\u4ef6 ###
log4j.appender.D = org.apache.log4j.DailyRollingFileAppender
log4j.appender.D.File = ${webapp.root}/log/log.log
log4j.appender.D.Append = true
log4j.appender.D.Threshold = DEBUG
log4j.appender.D.layout = org.apache.log4j.PatternLayout
log4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss} [%t:%r] - [%p] %m%n
### \u4fdd\u5b58\u5f02\u5e38\u4fe1\u606f\u5230\u5355\u72ec\u6587\u4ef6 ###
log4j.appender.E = org.apache.log4j.DailyRollingFileAppender
log4j.appender.E.File = ${webapp.root}/log/error.log
log4j.appender.E.Append = true
log4j.appender.E.Threshold = ERROR
log4j.appender.E.layout = org.apache.log4j.PatternLayout
log4j.appender.E.layout.ConversionPattern =%-d{yyyy-MM-dd HH\:mm\:ss} [%t\:%r] - [%p] %m%n
==========================================
proxool.properties
## ##公用数据库参数配置
show_sql=true
format_sql=true
hbm2ddl.auto=update
cglib.use_reflection_optimizer=true
connection.release_mode=auto
current_session_context_class=thread
connection.autocommit=true
maxActive=300
maxIdle=30
maxWait=500
proxool.house-keeping-test-sql=select sysdate from DUAL
connection.provider_class=org.hibernate.connection.ProxoolConnectionProvider
database.connection=org.hibernate.connection.ProxoolConnectionProvider
proxool.alias=Demostic
## ## mySql ## ##
database.dialect=org.hibernate.dialect.MySQLDialect
database.driver=com.mysql.jdbc.Driver
database.url=jdbc\:mysql\://127.0.0.1\:3306/mydemo?useUnicode\=true&amp;characterEncoding\=utf-8
database.user=root
database.password=1
## ## orcale ## ##
##database.dialect=org.hibernate.dialect.OracleDialect
##database.driver=oracle.jdbc.driver.OracleDriver
##database.url=jdbc:oracle:thin:@127.0.0.1:1521:tcs
##database.user=demostic
##database.password=demostic
## ##缓存设置
hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider,org.hibernate.cache.EhCacheProvider
hibernate.cache.use_query_cache=false
hibernate.cache.use_second_level_cache=true
hibernate.cache.configurationResourceName=ehcache.xml
hibernate.connection.autocommit=true
## ##测试版数据库
=================================proxool.xml=====================
<?xml version="1.0" encoding="UTF-8" ?>
<something-else-entirely>
<proxool>
<alias>mydemo</alias>
<!--mysql -->
<driver-url>jdbc:mysql://localhost:3306/mydemo</driver-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<driver-properties>
<property name="user" value="root" />
<property name="password" value="1" />
</driver-properties>
<!--
oracle <driver-url>jdbc:oracle:thin:@localhost:1521:tcs</driver-url>
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<driver-properties> <property name="user" value="demostic" />
<property name="password" value="demostic" /> </driver-properties>
-->
<!-- 最小的数据库连接数 -->
<minimum-connection-count>10</minimum-connection-count>
<!-- 最大的数据库连接数 -->
<maximum-connection-count>500</maximum-connection-count>
<!-- 最少保持的空闲连接数 -->
<prototype-count>10</prototype-count>
<!-- proxool自动侦察各个连接状态的时间间隔(毫秒),侦察到空闲的连接就马上回收,超时的销毁。 -->
<house-keeping-sleep-time>90000</house-keeping-sleep-time>
<!-- 指因未有空闲连接可以分配而在队列中等候的最大请求数,超过这个请求数的用户连接就不会被接受 -->
<maximum-new-connections>300</maximum-new-connections>
<!-- 某一时间点的最大连接数 -->
<simultaneous-build-throttle>150</simultaneous-build-throttle>
<!-- 一个线程持有一个连接的最长时间5分钟,单位毫秒(默认5分钟) -->
<maximum-active-time>300000</maximum-active-time>
<!-- 一个连接的最长活动时间4小时,单位毫秒(默认4小时) -->
<maximum-connection-lifetime>14400000</maximum-connection-lifetime>
<house-keeping-test-sql>set names 'UTF-8';</house-keeping-test-sql>
<test-before-use>true</test-before-use>
<house-keeping-test-sql>select 1 from dual</house-keeping-test-sql>
</proxool>
</something-else-entirely>
==========================================struts.properties==========
### Struts default properties
###(can be overridden by a struts.properties file in the root of the classpath)
###
### Specifies the Configuration used to configure Struts
### one could extend org.apache.struts2.config.Configuration
### to build one's customize way of getting the configurations parameters into Struts
# struts.configuration=org.apache.struts2.config.DefaultConfiguration
### This can be used to set your default locale and encoding scheme
# struts.locale=en_US
struts.i18n.encoding=UTF-8
### if specified, the default object factory can be overridden here
### Note: short-hand notation is supported in some cases, such as "spring"
### Alternatively, you can provide a com.opensymphony.xwork2.ObjectFactory subclass name here
struts.objectFactory = spring
### specifies the autoWiring logic when using the SpringObjectFactory.
### valid values are: name, type, auto, and constructor (name is the default)
struts.objectFactory.spring.autoWire = name
### indicates to the struts-spring integration if Class instances should be cached
### this should, until a future Spring release makes it possible, be left as true
### unless you know exactly what you are doing!
### valid values are: true, false (true is the default)
struts.objectFactory.spring.useClassCache = true
### if specified, the default object type determiner can be overridden here
### Note: short-hand notation is supported in some cases, such as "tiger" or "notiger"
### Alternatively, you can provide a com.opensymphony.xwork2.util.ObjectTypeDeterminer implementation name here
### Note: By default, com.opensymphony.xwork2.util.DefaultObjectTypeDeterminer is used which handles type detection
### using generics. com.opensymphony.xwork2.util.GenericsObjectTypeDeterminer was deprecated since XWork 2, it's
### functions are integrated in DefaultObjectTypeDeterminer now.
### To disable tiger support use the "notiger" property value here.
#struts.objectTypeDeterminer = tiger
#struts.objectTypeDeterminer = notiger
### Parser to handle HTTP POST requests, encoded using the MIME-type multipart/form-data
# struts.multipart.parser=cos
# struts.multipart.parser=pell
struts.multipart.parser=jakarta
# uses javax.servlet.context.tempdir by default
struts.multipart.saveDir=
struts.multipart.maxSize=2097152
### Load custom property files (does not override struts.properties!)
# struts.custom.properties=application,org/apache/struts2/extension/custom
### How request URLs are mapped to and from actions
#struts.mapper.class=org.apache.struts2.dispatcher.mapper.DefaultActionMapper
### Used by the DefaultActionMapper
### You may provide a comma separated list, e.g. struts.action.extension=action,jnlp,do
#struts.action.extension=do
struts.action.extension = action,do,
### Used by FilterDispatcher
### If true then Struts serves static content from inside its jar.
### If false then the static content must be available at <context_path>/struts
struts.serve.static=true
### Used by FilterDispatcher
### This is good for development where one wants changes to the static content be
### fetch on each request.
### NOTE: This will only have effect if struts.serve.static=true
### If true -> Struts will write out header for static contents such that they will
### be cached by web browsers (using Date, Cache-Content, Pragma, Expires)
### headers).
### If false -> Struts will write out header for static contents such that they are
### NOT to be cached by web browser (using Cache-Content, Pragma, Expires
### headers)
struts.serve.static.browserCache=true
### Set this to false if you wish to disable implicit dynamic method invocation
### via the URL request. This includes URLs like foo!bar.action, as well as params
### like method:bar (but not action:foo).
### An alternative to implicit dynamic method invocation is to use wildcard
### mappings, such as <action name="*/*" method="{2}" class="actions.{1}">
struts.enable.DynamicMethodInvocation = true
### Set this to true if you wish to allow slashes in your action names. If false,
### Actions names cannot have slashes, and will be accessible via any directory
### prefix. This is the traditional behavior expected of WebWork applications.
### Setting to true is useful when you want to use wildcards and store values
### in the URL, to be extracted by wildcard patterns, such as
### <action name="*/*" method="{2}" class="actions.{1}"> to match "/foo/edit" or
### "/foo/save".
struts.enable.SlashesInActionNames = false
### use alternative syntax that requires %{} in most places
### to evaluate expressions for String attributes for tags
struts.tag.altSyntax=true
### when set to true, Struts will act much more friendly for developers. This
### includes:
### - struts.i18n.reload = true
### - struts.configuration.xml.reload = true
### - raising various debug or ignorable problems to errors
### For example: normally a request to foo.action?someUnknownField=true should
### be ignored (given that any value can come from the web and it
### should not be trusted). However, during development, it may be
### useful to know when these errors are happening and be told of
### them right away.
struts.devMode = false
### when set to true, resource bundles will be reloaded on _every_ request.
### this is good during development, but should never be used in production
struts.i18n.reload=false
### Standard UI theme
### Change this to reflect which path should be used for JSP control tag templates by default
struts.ui.theme=simple
struts.ui.templateDir=template
#sets the default template type. Either ftl, vm, or jsp
struts.ui.templateSuffix=ftl
### Configuration reloading
### This will cause the configuration to reload struts.xml when it is changed
struts.configuration.xml.reload=false
### Location of velocity.properties file. defaults to velocity.properties
struts.velocity.configfile = velocity.properties
### Comma separated list of VelocityContext classnames to chain to the StrutsVelocityContext
struts.velocity.contexts =
### Location of the velocity toolbox
struts.velocity.toolboxlocation=
### used to build URLs, such as the UrlTag
struts.url.http.port = 80
struts.url.https.port = 443
### possible values are: none, get or all
struts.url.includeParams = get
### Load custom default resource bundles
struts.custom.i18n.resources=com.myshop.resources.ApplicationResources
### workaround for some app servers that don't handle HttpServletRequest.getParameterMap()
### often used for WebLogic, Orion, and OC4J
struts.dispatcher.parametersWorkaround = false
### configure the Freemarker Manager class to be used
### Allows user to plug-in customised Freemarker Manager if necessary
### MUST extends off org.apache.struts2.views.freemarker.FreemarkerManager
#struts.freemarker.manager.classname=org.apache.struts2.views.freemarker.FreemarkerManager
### Enables caching of FreeMarker templates
### Has the same effect as copying the templates under WEB_APP/templates
struts.freemarker.templatesCache=false
### Enables caching of models on the BeanWrapper
struts.freemarker.beanwrapperCache=false
### See the StrutsBeanWrapper javadocs for more information
struts.freemarker.wrapper.altMap=true
### configure the XSLTResult class to use stylesheet caching.
### Set to true for developers and false for production.
struts.xslt.nocache=false
### A list of configuration files automatically loaded by Struts
struts.configuration.files=struts-default.xml,struts-plugin.xml,struts.xml
### Whether to always select the namespace to be everything before the last slash or not
struts.mapper.alwaysSelectFullNamespace=false
============================================struts.xml=========
<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "[url=http://struts.apache.org/dtds/struts-2.0.dtd]http://struts.apache.org/dtds/struts-2.0.dtd[/url]">
<struts>
<constant name="struts.i18n.encoding" value="GBK" />
<constant name="struts.locale" value="zh_CN" />
<constant name="struts.multipart.maxSize" value="300000000" />
<constant name="struts.action.extension" value="action,struts2,json,html,demo,do,htm," />
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<constant name="struts.enable.SlashesInActionNames" value="true" />
<constant name="struts.ui.theme" value="simple" />
<constant name="struts.convention.relative.result.types" value="dispatcher,freemarker,velocity" />
<constant name="struts.devMode" value="true" />
<constant name="struts.convention.classes.reload" value="true" />
<constant name="struts.convention.action.suffix" value="action,demo" />
<constant name="struts.convention.action.name.lowercase" value="true" />
<constant name="struts.convention.action.name.separator" value="-" />
<constant name="struts.custom.i18n.resources" value="com.demo.resources.ApplicationResources*" />
</struts>
==================================com.tcs.org.demostic.pub.until.ProxoolListener====
package com.tcs.org.demostic.pub.until;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.logicalcobwebs.proxool.ProxoolException;
import org.logicalcobwebs.proxool.ProxoolFacade;
import org.logicalcobwebs.proxool.configuration.JAXPConfigurator;
import org.logicalcobwebs.proxool.configuration.PropertyConfigurator;
import javax.servlet.ServletContextEvent;
import java.io.File;
import java.util.Properties;
/**
* proxool初始化
*/
public class ProxoolListener implements
javax.servlet.ServletContextListener {
private static final Log LOG = LogFactory
.getLog(ProxoolListener.class);
private static final String XML_FILE_PROPERTY = "proxoolConfigLocation";
private boolean autoShutdown = true;
public void contextInitialized(ServletContextEvent servletConfig) {
String appDir = servletConfig.getServletContext().getRealPath("/");
Properties properties = new Properties();
String value = servletConfig.getServletContext().getInitParameter(
XML_FILE_PROPERTY);
LOG.debug("proxoolConfigLocation:" + value);
try {
File file = new File(value);
if (file.isAbsolute()) {
JAXPConfigurator.configure(value, false);
} else {
LOG.debug(appDir + File.separator + value);
JAXPConfigurator.configure(appDir + File.separator + value,
false);
}
} catch (ProxoolException e) {
LOG.error("Problem configuring " + value, e);
}
if (properties.size() > 0) {
try {
PropertyConfigurator.configure(properties);
} catch (ProxoolException e) {
LOG.error("Problem configuring using init properties", e);
}
}
}
public void contextDestroyed(ServletContextEvent s) {
if (autoShutdown) {
ProxoolFacade.shutdown(0);
}
}
}
====================================annotation生成表==============
package com.tcs.org.demostic.pub.until;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
/*
*功能:生成表
*先建mysql数据库(或)
*oracle实例 (demo)
*doc/oracle--mysql create.readme
*
*/
@SuppressWarnings("deprecation")
public class createTable {
public static void main(String[] args) {
Configuration cfg = new AnnotationConfiguration().configure();
SchemaExport export = new SchemaExport(cfg);
export.create(true, true);
// SchemaUpdate update =new SchemaUpdate(cfg);
// update.execute(true, true);
}
}
==================================BASEACTION======
BaseAction.java
package com.tcs.org.demostic.pub.base.action;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONObject;
import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.opensymphony.xwork2.ActionSupport;
/**
*
* @author Jar.lin $<br>
* @notes Created on 2010-01-25 $<br>
* Revision of last commit:$Revision: 01 $<br>
* Author of last commit:$Author: ssydxa219@126.com $<br>
* Date of last commit:$Date: 2010-01-25 16:47:12 +0800 <br>
* <p>
*/
@SuppressWarnings("serial")
@Controller
@Scope("prototype")
public class BaseAction extends ActionSupport {
private int page;
private String msg;
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
}
=========================PageIndex.java===================
package com.tcs.org.demostic.pub.base.bean;
/**
* 页索引,主要是起始页和终止页 $
*
* @author Jar.lin $<br>
*
* @notes Created on 2010-01-25 $<br>
* Revision of last commit:$Revision: 01 $<br>
* Author of last commit:$Author: ssydxa219@126.com $<br>
* Date of last commit:$Date: 2010-01-25 16:47:12 +0800 (周一, 25 一月 2010)$<br>
* <p>
*/
public class PageIndex {
/** 开始索引 **/
private int startIndex;
/** 结束索引 **/
private int endIndex;
public PageIndex(int startIndex, int endIndex) {
this.startIndex = startIndex;
this.endIndex = endIndex;
}
public int getStartIndex() {
return startIndex;
}
public void setStartIndex(int startIndex) {
this.startIndex = startIndex;
}
public int getEndIndex() {
return endIndex;
}
public void setEndIndex(int endIndex) {
this.endIndex = endIndex;
}
/**
* 起始页和终止页
*
* @param viewPageCount
* 显示多少页
* @param currentPage
* 当前页
* @param totalpage
* 总页数
* @return PageIndex 起始页和终止页
*/
public static PageIndex getPageIndex(int viewPageCount, int currentPage,
int totalpage) {
int startpage = currentPage
- (viewPageCount % 2 == 0 ? viewPageCount / 2 - 1
: viewPageCount / 2);
int endpage = currentPage + viewPageCount / 2;
if (startpage < 1) {
startpage = 1;
if (totalpage >= viewPageCount)
endpage = viewPageCount;
else
endpage = totalpage;
}
if (endpage > totalpage) {
endpage = totalpage;
if ((endpage - viewPageCount) > 0)
startpage = endpage - viewPageCount + 1;
else
startpage = 1;
}
return new PageIndex(startpage, endpage);
}
}
==============================PageView.java===================
package com.tcs.org.demostic.pub.base.bean;
import java.util.List;
/**
* * 分页数据包装,包括分页信息和List数据 $<br>
* @author Jar.lin $<br>
* @notes Created on 2010-01-25 $<br>
* Revision of last commit:$Revision: 01 $<br>
* Author of last commit:$Author: ssydxa219@126.com $<br>
* Date of last commit:$Date: 2010-01-25 16:47:12 +0800 (周一, 25 一月 2010)$<br>
* <p>
*/
public class PageView<T> {
/** 分页数据 **/
private List<T> records;
/** 页码开始索引和结束索引 **/
private PageIndex pageIndex;
/** 总页数 **/
private int totalPage = 1;
/** 每页显示记录数 **/
private int maxResult = 10;
/** 当前页 **/
private int currentPage = 1;
/** 总记录数 **/
private int totalRecord;
/** 每次显示多少页,必须保证大于3页,保证左右链接都可以使用 **/
private int viewPageCount = 10;
/** 要获取记录的开始索引 **/
public int getFirstResult() {
return (this.currentPage - 1) * this.maxResult;
}
public int getViewPageCount() {
return viewPageCount;
}
public void setViewPageCount(int viewPageCount) {
this.viewPageCount = viewPageCount;
}
public PageView(int maxResult, int currentPage) {
this.maxResult = maxResult;
this.currentPage = (currentPage <= 0 ? 1 : currentPage);
}
public PageView(int currentPage) {
this.currentPage = (currentPage <= 0 ? 1 : currentPage);
}
public void setQueryResult(QueryResult<T> qr) {
setTotalRecord(qr.getTotalRecord());
setRecords(qr.getResultList());
}
public int getTotalRecord() {
return totalRecord;
}
public void setTotalRecord(int totalRecord) {
this.totalRecord = totalRecord;
setTotalPage(this.totalRecord % this.maxResult == 0 ? this.totalRecord
/ this.maxResult : this.totalRecord / this.maxResult + 1);
}
public List<T> getRecords() {
return records;
}
public void setRecords(List<T> records) {
this.records = records;
}
public PageIndex getPageIndex() {
return pageIndex;
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
this.pageIndex = PageIndex.getPageIndex(viewPageCount, currentPage,
totalPage);
}
public int getMaxResult() {
return maxResult;
}
public int getCurrentPage() {
return currentPage;
}
}
======================QueryResult.java===============================
package com.tcs.org.demostic.pub.base.bean;
import java.util.List;
/**
**查询结果集,包括数据和总数 $<br>
* @author Jar.lin $<br>
* @notes Created on 2010-01-25 $<br>
* Revision of last commit:$Revision: 01 $<br>
* Author of last commit:$Author: ssydxa219@126.com $<br>
* Date of last commit:$Date: 2010-01-25 16:47:12 +0800 (周一, 25 一月 2010)$<br>
* <p>
*/
public class QueryResult<T> {
/** 查询得出的数据List **/
private List<T> resultList;
/** 查询得出的总数 **/
private int totalRecord;
public List<T> getResultList() {
return resultList;
}
public void setResultList(List<T> resultList) {
this.resultList = resultList;
}
public int getTotalRecord() {
return totalRecord;
}
public void setTotalRecord(int totalRecord) {
this.totalRecord = totalRecord;
}
}
==========================BaseDAOImpl.JAVA========================
package com.tcs.org.demostic.pub.base.dao.impl;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.sql.SQLException;
import java.util.LinkedHashMap;
import java.util.List;
import javax.annotation.Resource;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.tcs.org.demostic.pub.base.bean.QueryResult;
import com.tcs.org.demostic.pub.base.dao.IBaseDao;
import com.tcs.org.demostic.pub.base.util.GenericsUtils;
/**
* DAO层封装使用了泛型,包含常用的CURD和分页操作
*
* @author Jar.lin $<br>
* @notes Created on 2010-01-25 $<br>
* Revision of last commit:$Revision: 01 $<br>
* Author of last commit:$Author: ssydxa219@126.com $<br>
* Date of last commit:$Date: 2010-01-25 16:47:12 +0800 (周一, 25 一月 2010)$<br>
* <p>
*/
@SuppressWarnings("unchecked")
public abstract class BaseDaoImpl<T> extends HibernateDaoSupport implements IBaseDao<T> {
protected Class<T> entityClass = GenericsUtils.getSuperClassGenricType(this.getClass());
protected String entityClassName = getEntityName(this.entityClass);
protected String keyFieldName = getKeyFieldName(this.entityClass);
// 为父类HibernateDaoSupport注入sessionFactory的值
@Resource(name = "sessionFactory")
public void setSuperSessionFactory(SessionFactory sessionFactory) {
super.setSessionFactory(sessionFactory);
}
/*
* @see findByEntity(java.lang.Object)
*/
public List<T> findByEntity(Object entiey)throws Exception {
return super.getHibernateTemplate().findByExample(entiey);
}
/*
* Order By
*
*/
public List<T> findByEntityOrderBy(Object entiey,String orderBy,String descasc)throws Exception{
String entieyOrderBy = "from" +entityClassName+ " o Order By " + orderBy +" "+descasc;
return super.getHibernateTemplate().find(entieyOrderBy);
}
/*
* @see findByProperty(java.lang.String, java.lang.Object)
*/
public List<T> findByProperty(String propertyName, Object value)throws Exception {
String queryString = "from " + entityClassName + " o where o."
+ propertyName + "= ?";
return super.getHibernateTemplate().find(queryString, value);
}
/*
* @see find(java.io.Serializable)
*/
public T find(Serializable entityId) throws Exception {
if (null != entityId)
return (T) super.getHibernateTemplate().get(entityClass, entityId);
return null;
}
/*
* @see getCount()
*/
public int getCount() throws Exception {
String hql = "select count( " + keyFieldName + ") from "
+ entityClassName;
int count = Integer.parseInt(super.getHibernateTemplate().find(hql)
.get(0).toString());
return count;
}
public void save(Object entity) throws Exception {
super.getHibernateTemplate().save(entity);
}
/*
* @see update(java.lang.Object)
*/
public void update(Object entity) throws Exception {
super.getHibernateTemplate().update(entity);
}
public void saveOrUpdate(Object entity) {
super.getHibernateTemplate().saveOrUpdate(entity);
}
/*
* @see delete(java.io.Serializable[])
*/
public void delete(Serializable... entityids) throws Exception {
for (Object id : entityids) {
super.getHibernateTemplate().delete(find((Serializable) id));
}
}
/*
* @see getScrollData(int, int, java.lang.String,
* java.lang.Object[], java.util.LinkedHashMap)
*/
public QueryResult<T> getScrollData(final int firstindex,
final int maxresult,
final String wherejpql,
final Object[] queryParams,
final LinkedHashMap<String, String> orderby) throws Exception {
final QueryResult<T> queryResult = new QueryResult<T>();
super.getHibernateTemplate().execute(new HibernateCallback<T>() {
public T doInHibernate(Session session) throws HibernateException,
SQLException {
String hql = "from "
+ entityClassName
+ " o "
+ (wherejpql == null || "".equals(wherejpql.trim()) ? ""
: " where " + wherejpql)
+ buildOrderby(orderby);
Query query = session.createQuery(hql);
setQueryParams(query, queryParams);// where
queryResult.setTotalRecord(query.list().size());// first get
// size
if (firstindex != -1 && maxresult != -1)
query.setFirstResult(firstindex).setMaxResults(maxresult);// last
// page
queryResult.setResultList(query.list());
return null;
}
});
return queryResult;
}
/*
* @see getScrollData(int, int, java.lang.String,
* java.lang.Object[], java.util.LinkedHashMap)
*
* SELECT 语句
SELECT[predicate]{*|table.*|[table.]field [,[table.]field2[,...]]} [AS alias1 [,alias2[,...]]]
FROM tableexpression [,...][IN externaldatabase]
[]
[WHERE...]
[GROUP BY...]
[HAVING...]
[ORDER BY...]
[WITH OWNERACCESS OPTION]
SELECT 语句包括下面几个部分
predicate
*/
/*
* @see getScrollData(int, int, java.lang.String,
* java.lang.Object[])
*/
public QueryResult<T> getScrollData(int firstindex, int maxresult,
String wherejpql, Object[] queryParams)throws Exception {
return getScrollData(firstindex, maxresult, wherejpql, queryParams,
null);
}
/*
* @see getScrollData(int, int, java.util.LinkedHashMap)
*/
public QueryResult<T> getScrollData(final int firstindex,
final int maxresult, final LinkedHashMap<String, String> orderby) throws Exception {
return getScrollData(firstindex, maxresult, null, null, orderby);
}
/*
* @see getScrollData(int, int)
*/
public QueryResult<T> getScrollData(final int firstindex,
final int maxresult) throws Exception {
return getScrollData(firstindex, maxresult, null, null, null);
}
/*
* @see getScrollData()
*/
public QueryResult<T> getScrollData() throws Exception {
return getScrollData(-1, -1, null, null, null);
}
/*
* @see save(java.lang.Object)
*/
/**
* 获取实体的名称
*
* @param <E>
* @param clazz
* 实体类
* @return
*/
protected static <E> String getEntityName(Class<E> clazz) {
String entityname = clazz.getSimpleName();
Entity entity = clazz.getAnnotation(Entity.class);
if (entity.name() != null && !"".equals(entity.name())) {
entityname = entity.name();
}
return entityname;
}
/**
* 获取实体的主键
*
* @param <E>
* @param clazz
* 实体类
* @return 主键名
*/
protected static <E> String getKeyFieldName(Class<E> clazz) {
try {
PropertyDescriptor[] propertyDescriptors = Introspector
.getBeanInfo(clazz).getPropertyDescriptors();
for (PropertyDescriptor propertydesc : propertyDescriptors) {
Method method = propertydesc.getReadMethod();
if (null != method
&& null != method
.getAnnotation(javax.persistence.Id.class)) {
return propertydesc.getName();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return "id";
}
/**
* 设置HQL里边的属性值
*
* @param query
* @param queryParams
*/
protected static void setQueryParams(Query query, Object[] queryParams) {
if (queryParams != null && queryParams.length > 0) {
for (int i = 0; i < queryParams.length; i++) {
query.setParameter(i, queryParams[i]);// 从0开始
}
}
}
/**
* 组装order by语句
*
* @param orderby
* @return
*/
protected static String buildOrderby(LinkedHashMap<String, String> orderby) {
StringBuffer orderbyql = new StringBuffer("");
if (orderby != null && orderby.size() > 0) {
orderbyql.append(" order by ");
for (String key : orderby.keySet()) {
orderbyql.append("o.").append(key).append(" ").append(
orderby.get(key)).append(",");
}
orderbyql.deleteCharAt(orderbyql.length() - 1);
}
return orderbyql.toString();
}
protected static <E> String getCountField(Class<E> clazz) throws Exception {
String out = "o";
try {
PropertyDescriptor[] propertyDescriptors = Introspector
.getBeanInfo(clazz).getPropertyDescriptors();
for (PropertyDescriptor propertydesc : propertyDescriptors) {
Method method = propertydesc.getReadMethod();
if (method != null
&& method.isAnnotationPresent(EmbeddedId.class)) {
PropertyDescriptor[] ps = Introspector.getBeanInfo(
propertydesc.getPropertyType())
.getPropertyDescriptors();
out = "o."
+ propertydesc.getName()
+ "."
+ (!ps[1].getName().equals("class") ? ps[1]
.getName() : ps[0].getName());
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return out;
}
}
=============================IBASEDAO.JAVA========================
package com.tcs.org.demostic.pub.base.dao;
import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.List;
import com.tcs.org.demostic.pub.base.bean.QueryResult;
/**
* DAO层封装接口,包含常用的CURD和分页操作 $<br>
*
* @author Jar.lin $<br>
* @notes Created on 2010-01-25 $<br>
* Revision of last commit:$Revision: 01 $<br>
* Author of last commit:$Author: ssydxa219@126.com $<br>
* Date of last commit:$Date: 2010-01-25 16:47:12 +0800 (周一, 25 一月 2010)$<br>
* <p>
*/
public interface IBaseDao<T> {
/**
* 根据属性查找对象
*
* @param propertyName
* 属性(对应Bean)
* @param value
* 属性
* @return 根据属性查找对象
*/
public List<T> findByProperty(String propertyName, Object value) throws Exception;
/**
* 根据实体查找对象
*
* @param entiey
* 实体(T类型)
* @return 根据属性查找对象
*/
public List<T> findByEntity(Object entiey)throws Exception;
/**
* 获取记录总数
*
* @param entityClass
* 实体类
* @return
*/
public int getCount()throws Exception;
/**
* 保存实体
*
* @param entity
* 实体id
*/
public void save(Object entity)throws Exception;
/**
* 更新实体
*
* @param entity
* 实体id
*/
public void update(Object entity)throws Exception;
/**
* 更新或保存实体
*
* @param entity
* 实体id
*/
public void saveOrUpdate(Object entity)throws Exception;
/**
* 删除实体
*
* @param entityClass
* 实体类
* @param entityids
* 实体id数组
*/
public void delete(Serializable... entityids)throws Exception;
/**
* 获取实体
*
* @param <T>
* @param entityClass
* 实体类
* @param entityId
* 实体id
* @return
*/
public T find(Serializable entityId)throws Exception;
/**
* 获取分页数据
*
* @param firstindex
* 开始索引
* @param maxresult
* 每页显示记录数
* @param wherejpql
* where语句
* @param queryParams
* 查询参数
* @param orderby
* 排序序列
* @return 分页数据
*/
public QueryResult<T> getScrollData(final int firstindex,
final int maxresult, final String wherejpql,
final Object[] queryParams,
final LinkedHashMap<String, String> orderby)throws Exception;
/**
* 获取分页数据
*
* @param firstindex
* 开始索引
* @param maxresult
* 每页显示记录数
* @param wherejpql
* where语句
* @param queryParams
* 查询参数
* @return 分页数据
*/
public QueryResult<T> getScrollData(final int firstindex,
final int maxresult, final String wherejpql,
final Object[] queryParams)throws Exception;
/**
* 获取分页数据
*
* @param firstindex
* 开始索引
* @param maxresult
* 每页显示记录数
* @param orderby
* 排序序列
* @return 分页数据
*/
public QueryResult<T> getScrollData(final int firstindex,
final int maxresult, final LinkedHashMap<String, String> orderby)throws Exception;
/**
* 获取分页数据
*
* @param firstindex
* 开始索引
* @param maxresult
* 每页显示记录数
* @return 分页数据
*/
public QueryResult<T> getScrollData(final int firstindex,
final int maxresult)throws Exception;
/**
* 获取所有对象
*
* @return 所有对象
*/
public QueryResult<T> getScrollData()throws Exception;
}
==========================GENERICEuTILS=============================
package com.tcs.org.demostic.pub.base.util;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
/**
* 泛型工具类 $<br>
*
* @author Jar.lin $<br>
* @notes Created on 2010-01-25 $<br>
* Revision of last commit:$Revision: 01 $<br>
* Author of last commit:$Author: ssydxa219@126.com $<br>
* Date of last commit:$Date: 2010-01-25 16:47:12 +0800 (周一, 25 一月 2010)$<br>
* <p>
*/
public class GenericsUtils {
/**
* 通过反射,获得指定类的父类的泛型参数的实际类型. 如BuyerServiceBean extends DaoSupport<Buyer>
*
* @param clazz
* clazz 需要反射的类,该类必须继承范型父类
* @param index
* 泛型参数所在索引,从0开始.
* @return 范型参数的实际类型, 如果没有实现ParameterizedType接口,即不支持泛型,所以直接返回
* <code>Object.class</code>
*/
@SuppressWarnings("unchecked")
public static Class getSuperClassGenricType(Class clazz, int index) {
Type genType = clazz.getGenericSuperclass();// 得到泛型父类
// 如果没有实现ParameterizedType接口,即不支持泛型,直接返回Object.class
if (!(genType instanceof ParameterizedType)) {
return Object.class;
}
// 返回表示此类型实际类型参数的Type对象的数组,数组里放的都是对应类型的Class, 如BuyerServiceBean extends
// DaoSupport<Buyer,Contact>就返回Buyer和Contact类型
Type[] params = ((ParameterizedType) genType).getActualTypeArguments();
if (index >= params.length || index < 0) {
throw new RuntimeException("你输入的索引"
+ (index < 0 ? "不能小于0" : "超出了参数的总数"));
}
if (!(params[index] instanceof Class)) {
return Object.class;
}
return (Class) params[index];
}
/**
* 通过反射,获得指定类的父类的第一个泛型参数的实际类型. 如BuyerServiceBean extends DaoSupport<Buyer>
*
* @param clazz
* clazz 需要反射的类,该类必须继承泛型父类
* @return 泛型参数的实际类型, 如果没有实现ParameterizedType接口,即不支持泛型,所以直接返回
* <code>Object.class</code>
*/
@SuppressWarnings("unchecked")
public static Class getSuperClassGenricType(Class clazz) {
return getSuperClassGenricType(clazz, 0);
}
/**
* 通过反射,获得方法返回值泛型参数的实际类型. 如: public Map<String, Buyer> getNames(){}
*
* @param Method
* method 方法
* @param int index 泛型参数所在索引,从0开始.
* @return 泛型参数的实际类型, 如果没有实现ParameterizedType接口,即不支持泛型,所以直接返回
* <code>Object.class</code>
*/
@SuppressWarnings("unchecked")
public static Class getMethodGenericReturnType(Method method, int index) {
Type returnType = method.getGenericReturnType();
if (returnType instanceof ParameterizedType) {
ParameterizedType type = (ParameterizedType) returnType;
Type[] typeArguments = type.getActualTypeArguments();
if (index >= typeArguments.length || index < 0) {
throw new RuntimeException("你输入的索引"
+ (index < 0 ? "不能小于0" : "超出了参数的总数"));
}
return (Class) typeArguments[index];
}
return Object.class;
}
/**
* 通过反射,获得方法返回值第一个泛型参数的实际类型. 如: public Map<String, Buyer> getNames(){}
*
* @param Method
* method 方法
* @return 泛型参数的实际类型, 如果没有实现ParameterizedType接口,即不支持泛型,所以直接返回
* <code>Object.class</code>
*/
@SuppressWarnings("unchecked")
public static Class getMethodGenericReturnType(Method method) {
return getMethodGenericReturnType(method, 0);
}
/**
* 通过反射,获得方法输入参数第index个输入参数的所有泛型参数的实际类型. 如: public void add(Map<String,
* Buyer> maps, List<String> names){}
*
* @param Method
* method 方法
* @param int index 第几个输入参数
* @return 输入参数的泛型参数的实际类型集合, 如果没有实现ParameterizedType接口,即不支持泛型,所以直接返回空集合
*/
@SuppressWarnings("unchecked")
public static List<Class> getMethodGenericParameterTypes(Method method,
int index) {
List<Class> results = new ArrayList<Class>();
Type[] genericParameterTypes = method.getGenericParameterTypes();
if (index >= genericParameterTypes.length || index < 0) {
throw new RuntimeException("你输入的索引"
+ (index < 0 ? "不能小于0" : "超出了参数的总数"));
}
Type genericParameterType = genericParameterTypes[index];
if (genericParameterType instanceof ParameterizedType) {
ParameterizedType aType = (ParameterizedType) genericParameterType;
Type[] parameterArgTypes = aType.getActualTypeArguments();
for (Type parameterArgType : parameterArgTypes) {
Class parameterArgClass = (Class) parameterArgType;
results.add(parameterArgClass);
}
return results;
}
return results;
}
/**
* 通过反射,获得方法输入参数第一个输入参数的所有泛型参数的实际类型. 如: public void add(Map<String, Buyer>
* maps, List<String> names){}
*
* @param Method
* method 方法
* @return 输入参数的泛型参数的实际类型集合, 如果没有实现ParameterizedType接口,即不支持泛型,所以直接返回空集合
*/
@SuppressWarnings("unchecked")
public static List<Class> getMethodGenericParameterTypes(Method method) {
return getMethodGenericParameterTypes(method, 0);
}
/**
* 通过反射,获得Field泛型参数的实际类型. 如: public Map<String, Buyer> names;
*
* @param Field
* field 字段
* @param int index 泛型参数所在索引,从0开始.
* @return 泛型参数的实际类型, 如果没有实现ParameterizedType接口,即不支持泛型,所以直接返回
* <code>Object.class</code>
*/
@SuppressWarnings("unchecked")
public static Class getFieldGenericType(Field field, int index) {
Type genericFieldType = field.getGenericType();
if (genericFieldType instanceof ParameterizedType) {
ParameterizedType aType = (ParameterizedType) genericFieldType;
Type[] fieldArgTypes = aType.getActualTypeArguments();
if (index >= fieldArgTypes.length || index < 0) {
throw new RuntimeException("你输入的索引"
+ (index < 0 ? "不能小于0" : "超出了参数的总数"));
}
return (Class) fieldArgTypes[index];
}
return Object.class;
}
/**
* 通过反射,获得Field泛型参数的实际类型. 如: public Map<String, Buyer> names;
*
* @param Field
* field 字段
* @param int index 泛型参数所在索引,从0开始.
* @return 泛型参数的实际类型, 如果没有实现ParameterizedType接口,即不支持泛型,所以直接返回
* <code>Object.class</code>
*/
@SuppressWarnings("unchecked")
public static Class getFieldGenericType(Field field) {
return getFieldGenericType(field, 0);
}
}
=======================================================
<Context path="/mydemo" docBase="D:\dev\myTools\workspace\mydemo\target\mydemo\webapp" debug="3" reloadable="true"/>
相关推荐
这个压缩包文件"struts-2.3.1+spring3.1.1+hibernate3.6.9整合&配置文件"提供了将这三个框架整合使用的配置和依赖。下面我们将详细讨论这三个框架以及它们的整合过程。 **Struts 2** 是一个基于MVC设计模式的Java ...
自己整合了一个可以运行的完整的S2SH框架(struts-2.3.16.1/hibernate-3.6.10/spring-framework-3.2.9),包含了所有的配置文件和所有必需的jar包。以后备用。。。
服务器环境:Ubuntu 18.04.1+Mysql 5.7.29+Python 3.6.9 ** 步骤一:布置环境 mysql安装(sudo apt-get update): 1.1命令安装 (1)sudo apt-get install mysql-server (2)sudo apt-get install mysql-client (3)...
SSH(Struts、Spring、Hibernate)是经典的Java企业级开发框架组合,其中Hibernate作为数据层解决方案,Spring提供依赖注入和事务管理,Struts则处理视图和控制器。了解Hibernate是掌握SSH架构的关键步骤。 本教程...
hibernate-core-3.6.9.Final
- **3.6.9.Final (2011-12-15)**:此版本修复了一些小错误并增强了稳定性。 - **3.6.8.Final (2011-10-27)**:进一步优化了性能并解决了几个安全问题。 - …… - **3.6.0.Final (2010-10-14)**:这是3.6.x系列的...
Apache Maven 是一个强大的项目管理和构建工具,主要用于Java应用程序的开发。它基于项目对象模型(Project Object Model,POM)的概念,能够自动化构建过程,管理依赖关系,并提供了统一的构建过程,使得开发人员的...
hibernate3.6.9
在Java开发领域,Spring、Hibernate和Struts是三个非常重要的框架,它们分别负责不同层面的应用。Spring是一个全面的后端应用程序框架,提供了依赖注入、面向切面编程等特性;Hibernate是一个对象关系映射(ORM)...
全名:Python-3.6.9rc1.tar.xz
Maven不仅可以用于构建传统的Java应用,还可以应用于Web开发,比如结合Spring Boot创建快速开发模板网站。同时,Maven也是系统软件开发的重要工具,它可以轻松地构建复杂的多模块项目,帮助团队协调开发进度和版本...
hibernate4版本的c3p0jar包
凯沃里 :: API org.kevoree/org.kevoree.api/3.6.9/org.kevoree.api-3.6.9.jar
智慧消防云平台融合了无线烟感监测、...springboot2 + mysql 5.7 + redis 5.0.0 + elasticsearch 6.5.4 + rabbitmq 3.6.9 + vue3 使用根目录下maven 配置文件 mysql数据库资源创建好后,执行sql文件创建初始化数据库
apache-maven-3.9.6(含windows和linux版本).zip包含如下内容: apache-maven-3.9.6-bin.tar.gz; apache-maven-3.9.6-bin.zip; apache-maven-3.9.6-src.tar.gz; apache-maven-3.9.6-src.zip; maven安装说明.txt...
java jar包,亲测试可用 安全,可以对其进行数字签名,只让能够识别数字签名的用户使用里面的东西。 加快下载速度; 压缩,使文件变小,与ZIP压缩机制完全相同。 ...能够让JAR包里面的文件依赖于统一版本的类文件。...
在本文件"Python-3.6.9 tar+tar.xz.rar"中,包含的是Linux平台上的Python 3.6.9源代码,以两种不同的压缩格式存储:tgz和tar.xz。 1. **Python 3.6.9**:这个版本引入了诸多新特性,包括但不限于: - **asyncio...
hibernate-c3p0.jar 各个版本,免费下载 C3PO JDBC 连接池工具
Spire.Pdf.jar 截止2020/7/7 最新版本 使用Spire实现pdf指定位置插入图片签章, 前一个资源还实现了通过itext对pdf文件进行关键词定位,定位后,通过Spire进行指定位置图片签章