zoukankan      html  css  js  c++  java
  • JavaWeb项目开发案例精粹-第6章报价管理系统-002辅助类及配置文件

    1.

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <beans xmlns="http://www.springframework.org/schema/beans"
     3        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     4        xmlns:context="http://www.springframework.org/schema/context"
     5        xmlns:aop="http://www.springframework.org/schema/aop"
     6        xmlns:tx="http://www.springframework.org/schema/tx"
     7        xsi:schemaLocation="http://www.springframework.org/schema/beans
     8            http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
     9            http://www.springframework.org/schema/context
    10            http://www.springframework.org/schema/context/spring-context-2.5.xsd
    11            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
    12            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
    13     <!-- 配置哪些包下的类需要自动扫描 -->
    14     <context:component-scan base-package="com.sanqing"/>    
    15    
    16     <!-- 这里的jun要与persistence.xml中的 <persistence-unit name="jun" transaction-type="RESOURCE_LOCAL">
    17     中的name值要一致,这样才能找到相关的数据库连接
    18      -->
    19    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
    20          <property name="persistenceUnitName" value="jun"/>
    21    </bean>  
    22    <!-- 配置事物管理器 --> 
    23    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    24         <property name="entityManagerFactory" ref="entityManagerFactory"/>
    25    </bean>
    26    <!-- 配置使用注解来管理事物 -->
    27    <tx:annotation-driven transaction-manager="transactionManager"/>
    28     
    29 </beans>

    2.

      1 <?xml version="1.0" encoding="UTF-8" ?>
      2 <!DOCTYPE struts PUBLIC
      3     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
      4     "http://struts.apache.org/dtds/struts-2.0.dtd">
      5 
      6 <struts>
      7     <constant name="struts.enable.DynamicMethodInvocation"
      8         value="false" />
      9     <constant name="struts.devMode" value="false" />
     10     <!-- 与spring集成 -->
     11     <constant name="struts.objectFactory" value="spring" />
     12     <!-- 改变后缀名 -->
     13     <constant name="struts.action.extension" value="do" />
     14     <!-- 配置国际化资源文件 -->
     15     <constant name="struts.custom.i18n.resources"
     16         value="globalMessages" />
     17     <!-- 处理编码问题 -->
     18     <constant name="struts.i18n.encoding" value="GBK" />
     19     <!-- 当修改配置文件不需要重启服务,开发比较有用 -->
     20     <constant name="struts.configuration.xml.reload" value="true" />
     21     <!-- 报表 -->
     22     <!--  
     23     <package name="lee" namespace="/" extends="jasperreports-default">
     24         <action name="jasper" class="jasperAction">
     25             <result name="success" type="jasper">
     26                 <param name="location">reportjasperorder.jrxml</param>
     27                 <param name="format">HTML</param>
     28                 <param name="dataSource">order</param>
     29             </result>
     30         </action>
     31     </package>
     32     -->
     33     <!-- 用户登录 -->
     34     <package name="san" namespace="/" extends="struts-default">
     35             <action name="login" class="loginAction" >
     36                 <result name="success">/back_index.html</result>
     37                 <result name="input">/index.jsp</result>
     38             </action>
     39     </package>
     40     <!-- 控制相关模块 -->
     41     <package name="qing" namespace="/control" extends="struts-default">
     42         <interceptors><!--配置拦截器 -->
     43             <interceptor name="loginIntercepter"            
     44                 class="com.sanqing.intercepter.LoginIntercepter" /><!--配置登录判断拦截器-->
     45             <interceptor-stack name="mydefault"><!--配置拦截器栈-->
     46                 <interceptor-ref name="defaultStack" /><!--Struts 2默认拦截器 -->
     47                 <interceptor-ref name="loginIntercepter" /><!--登录判断拦截器 -->
     48             </interceptor-stack>
     49         </interceptors>
     50         <default-interceptor-ref name="mydefault" /><!--配置默认拦截器-->
     51         <global-results>
     52             <result name="pub_add_success">/share/pub_add_success.jsp</result>
     53             <result name="pub_update_success">/share/pub_update_success.jsp</result>
     54             <result name="pub_del_success">/share/pub_del_success.jsp</result>
     55             <result name="input">/index.jsp</result>
     56         </global-results>
     57         <!-- 客户显示 -->
     58         <action name="customer" class="customerAction">
     59             <result name="success">
     60                 /customer/customer_list.jsp
     61             </result>
     62         </action>
     63         <!-- 客户管理 -->
     64         <action name="customermanage_*" class="customerManageAction" method="{1}">
     65             <result name="add">/customer/customer_add.jsp</result>
     66             <result name="update">/customer/customer_update.jsp</result>
     67             <result name="query">/customer/customer_query.jsp</result>
     68         </action>
     69         <!-- 产品类别显示 -->
     70         <action name="producttype" class="productTypeAction">
     71             <result name="success">
     72                 /product/producttype_list.jsp
     73             </result>
     74         </action>
     75         <!-- 产品类别管理 -->
     76         <action name="producttypemanage_*" class="productTypeManageAction" method="{1}">
     77             <result name="add">/product/producttype_add.jsp</result>
     78             <result name="update">/product/producttype_update.jsp</result>
     79             <result name="query">/product/producttype_query.jsp</result>
     80         </action>
     81         <!-- 产品显示 -->
     82         <action name="product" class="productAction">
     83             <result name="success">
     84                 /product/product_list.jsp
     85             </result>
     86         </action>
     87         <!-- 产品管理 -->
     88         <action name="productmanage_*" class="productManageAction" method="{1}">
     89             <result name="add">/product/product_add.jsp</result>
     90             <result name="update">/product/product_update.jsp</result>
     91             <result name="query">/product/product_query.jsp</result>
     92         </action>
     93         <!-- 订单显示 -->
     94         <action name="order" class="orderAction">
     95             <result name="success">
     96                 /order/order_list.jsp
     97             </result>
     98         </action>
     99         <!-- 订单管理 -->
    100         <action name="ordermanage_*" class="orderManageAction" method="{1}">
    101             <result name="add">/order/order_add.jsp</result>
    102             <result name="update">/order/order_update.jsp</result>
    103             <result name="query">/order/order_query.jsp</result>
    104         </action>
    105         <!-- 报价显示 -->
    106         <action name="quotation" class="quotationAction">
    107             <result name="success">
    108                 /quotation/quotation_list.jsp
    109             </result>
    110         </action>
    111         <!-- 报价管理 -->
    112         <action name="quotationmanage_*" class="quotationManageAction" method="{1}">
    113             <result name="add">/quotation/quotation_add.jsp</result>
    114             <result name="update">/quotation/quotation_update.jsp</result>
    115             <result name="query">/quotation/quotation_query.jsp</result>
    116         </action>
    117         <!-- 用户显示 -->
    118         <action name="user" class="userAction">
    119             <result name="success">
    120                 /user/user_list.jsp
    121             </result>
    122         </action>
    123         <!-- 用户管理 -->
    124         <action name="usermanage_*" class="userManageAction" method="{1}">
    125             <result name="add">/user/user_add.jsp</result>
    126             <result name="update">/user/user_update.jsp</result>
    127             <result name="query">/user/user_query.jsp</result>
    128         </action>
    129     </package>
    130 </struts>

    3.

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
     3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     4     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
     5     http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
     6     <display-name>hibernate的jpa实现</display-name>
     7     <context-param>
     8         <param-name>contextConfigLocation</param-name>
     9         <param-value>classpath:beans.xml</param-value>
    10     </context-param>
    11     <!-- 对Spring容器进行实例化 -->
    12     <listener>
    13         <listener-class>
    14             org.springframework.web.context.ContextLoaderListener
    15         </listener-class>
    16     </listener>
    17     <!-- 把jpa的EntityManager设为开启状态 解决延迟加载的问题-->
    18     <filter>
    19         <filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
    20         <filter-class>
    21             org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter
    22         </filter-class>
    23     </filter>
    24     <filter-mapping>
    25         <filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
    26         <url-pattern>/*</url-pattern>
    27     </filter-mapping>
    28     <!-- 利用的spring的过滤器来设置编码方式 -->
    29     <filter>
    30         <filter-name>Spring character encoding filter</filter-name>
    31         <filter-class>
    32             org.springframework.web.filter.CharacterEncodingFilter
    33         </filter-class>
    34         <init-param>
    35             <param-name>encoding</param-name>
    36             <param-value>UTF-8</param-value>
    37         </init-param>
    38     </filter>
    39     <filter-mapping>
    40         <filter-name>Spring character encoding filter</filter-name>
    41         <url-pattern>/*</url-pattern>
    42     </filter-mapping>
    43     <!-- struts2.1配置 start 注意我们陪着struts2的时候一定把这个过滤器ActionContextCleanUp陪在FilterDispatcher的前面-->
    44     <display-name>Struts Blank</display-name>
    45     <filter>
    46         <filter-name>struts-cleanup</filter-name>
    47         <filter-class>
    48             org.apache.struts2.dispatcher.ActionContextCleanUp
    49         </filter-class>
    50     </filter>
    51     <filter>
    52         <filter-name>struts2</filter-name>
    53         <filter-class>
    54             org.apache.struts2.dispatcher.FilterDispatcher
    55         </filter-class>
    56     </filter>
    57     <filter-mapping>
    58         <filter-name>struts-cleanup</filter-name>
    59         <url-pattern>/*</url-pattern>
    60     </filter-mapping>
    61     <filter-mapping>
    62         <filter-name>struts2</filter-name>
    63         <url-pattern>/*</url-pattern>
    64     </filter-mapping>
    65     <display-name>Struts Blank</display-name>
    66     <!-- struts2.1 end -->
    67     <welcome-file-list>
    68         <welcome-file>index.html</welcome-file>
    69         <welcome-file>index.htm</welcome-file>
    70         <welcome-file>index.jsp</welcome-file>
    71     </welcome-file-list>
    72 </web-app>

    4.META-INF/persistence.xml

     1 <?xml version="1.0"?>
     2 <persistence xmlns="http://java.sun.com/xml/ns/persistence"
     3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     4     xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
     5     http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
     6   <persistence-unit name="jun" transaction-type="RESOURCE_LOCAL">
     7       <provider>org.hibernate.ejb.HibernatePersistence</provider>
     8     <properties>
     9          <property name="hibernate.dialect" 
    10              value="org.hibernate.dialect.MySQLDialect"/><!--数据库方言-->
    11          <property name="hibernate.connection.driver_class" 
    12              value="com.mysql.jdbc.Driver"/><!--数据库驱动类-->
    13          <property name="hibernate.connection.username" value="root"/><!--数据库用户名-->
    14          <property name="hibernate.connection.password" value="1234"/>
    15          <property name="hibernate.connection.url" 
    16              value="jdbc:mysql://localhost:3306/quote"/><!--数据库连接URL-->
    17          <property name="hibernate.max_fetch_depth" value="3"/><!--外连接抓取树的最大深度 -->
    18          <property name="hibernate.hbm2ddl.auto" value="update"/><!-- 自动输出schema创建DDL语句 -->
    19          <property name="hibernate.jdbc.fetch_size" value="18"/><!-- JDBC的获取量大小 -->
    20          <property name="hibernate.jdbc.batch_size" value="10"/><!-- 开启Hibernate使用JDBC2的批量更新功能  -->
    21          <property name="hibernate.show_sql" value="true"/><!-- 在控制台输出SQL语句 -->
    22       </properties>
    23   </persistence-unit>
    24 </persistence>

    5.

     1 package com.sanqing.intercepter;
     2 
     3 
     4 import java.util.Map;
     5 
     6 import com.opensymphony.xwork2.ActionContext;
     7 import com.opensymphony.xwork2.ActionInvocation;
     8 import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
     9 import com.sanqing.po.User;
    10 
    11 public class LoginIntercepter extends AbstractInterceptor {
    12     private static final long serialVersionUID = 6203506362291764836L;
    13     @Override
    14     public String intercept(ActionInvocation invocation) throws Exception {
    15         ActionContext ctx=invocation.getInvocationContext();//获得ActionContext对象
    16         Map session=ctx.getSession();        //获得session对象
    17         User user = (User)session.get("user");//获得用户登录信息
    18         if(user != null) {    //如果不为空,则表示已经登录
    19             return invocation.invoke();//继续执行后面的操作
    20         }
    21         return "input";//跳转到登录页面
    22     }
    23 }

    6.

     1 package com.sanqing.util;
     2 
     3 import java.text.DateFormat;
     4 import java.text.SimpleDateFormat;
     5 import java.util.Date;
     6 import java.util.Map;
     7 
     8 
     9 import com.opensymphony.xwork2.conversion.impl.DefaultTypeConverter;
    10 
    11 public class DateConverter extends DefaultTypeConverter {
    12     private static final DateFormat[] ACCEPT_DATE_FORMATS = {
    13             new SimpleDateFormat("dd/MM/yyyy"),
    14             new SimpleDateFormat("yyyy-MM-dd"),
    15             new SimpleDateFormat("yyyy/MM/dd") }; // 支持转换的日期格式
    16     @SuppressWarnings("unchecked")
    17     public Object convertValue(Map context, Object value, Class toType) {
    18         if (toType == Date.class) { //进行String到Date的转换
    19             Date date = null;
    20             String dateString = null;
    21             String[] params = (String[]) value;    //获得参数列表
    22             dateString = params[0];             //获取日期的字符串
    23             for (DateFormat format : ACCEPT_DATE_FORMATS) {
    24                 try {
    25                     date = format.parse(dateString);//对字符串进行转换
    26                     return date;                     //返回Date类型日期
    27                 } catch (Exception e) {
    28                     continue;
    29                 }
    30             }
    31             return null;
    32         } else if (toType == String.class) { //进行Date到String的转换
    33             Date date = (Date) value;//强制类型转换
    34             return new SimpleDateFormat("yyyy-MM-dd").format(date);//返回String类型日期
    35         }
    36         return null;
    37     }
    38 }

    7.

      1 package com.sanqing.util;
      2 
      3 import java.lang.reflect.Field;
      4 import java.lang.reflect.Method;
      5 import java.lang.reflect.ParameterizedType;
      6 import java.lang.reflect.Type;
      7 import java.util.ArrayList;
      8 import java.util.List;
      9 /**
     10  * 泛型工具类
     11  *
     12  */
     13 public class GenericsUtils {
     14     /**  
     15      * 通过反射,获得指定类的父类的泛型参数的实际类型. 如BuyerServiceBean extends DaoSupport<Buyer>  
     16      *  
     17      * @param clazz clazz 需要反射的类,该类必须继承范型父类
     18      * @param index 泛型参数所在索引,从0开始.  
     19      * @return 范型参数的实际类型, 如果没有实现ParameterizedType接口,即不支持泛型,所以直接返回<code>Object.class</code>
     20      */  
     21     @SuppressWarnings("unchecked")
     22     public static Class getSuperClassGenricType(Class clazz, int index) {    
     23         Type genType = clazz.getGenericSuperclass();//得到泛型父类  
     24         //如果没有实现ParameterizedType接口,即不支持泛型,直接返回Object.class   
     25         if (!(genType instanceof ParameterizedType)) {
     26             return Object.class;   
     27         }  
     28         //返回表示此类型实际类型参数的Type对象的数组,数组里放的都是对应类型的Class, 如BuyerServiceBean extends DaoSupport<Buyer,Contact>就返回Buyer和Contact类型   
     29         Type[] params = ((ParameterizedType) genType).getActualTypeArguments();                   
     30         if (index >= params.length || index < 0) { 
     31              throw new RuntimeException("你输入的索引"+ (index<0 ? "不能小于0" : "超出了参数的总数"));
     32         }      
     33         if (!(params[index] instanceof Class)) {
     34             return Object.class;   
     35         }   
     36         return (Class) params[index];
     37     }
     38     /**  
     39      * 通过反射,获得指定类的父类的第一个泛型参数的实际类型. 如BuyerServiceBean extends DaoSupport<Buyer>  
     40      *  
     41      * @param clazz clazz 需要反射的类,该类必须继承泛型父类
     42      * @return 泛型参数的实际类型, 如果没有实现ParameterizedType接口,即不支持泛型,所以直接返回<code>Object.class</code>
     43      */  
     44     @SuppressWarnings("unchecked")
     45     public static Class getSuperClassGenricType(Class clazz) {
     46         return getSuperClassGenricType(clazz,0);
     47     }
     48     /**  
     49      * 通过反射,获得方法返回值泛型参数的实际类型. 如: public Map<String, Buyer> getNames(){}
     50      *  
     51      * @param Method method 方法
     52      * @param int index 泛型参数所在索引,从0开始.
     53      * @return 泛型参数的实际类型, 如果没有实现ParameterizedType接口,即不支持泛型,所以直接返回<code>Object.class</code>
     54      */ 
     55     @SuppressWarnings("unchecked")
     56     public static Class getMethodGenericReturnType(Method method, int index) {
     57         Type returnType = method.getGenericReturnType();
     58         if(returnType instanceof ParameterizedType){
     59             ParameterizedType type = (ParameterizedType) returnType;
     60             Type[] typeArguments = type.getActualTypeArguments();
     61             if (index >= typeArguments.length || index < 0) { 
     62                  throw new RuntimeException("你输入的索引"+ (index<0 ? "不能小于0" : "超出了参数的总数"));
     63             } 
     64             return (Class)typeArguments[index];
     65         }
     66         return Object.class;
     67     }
     68     /**  
     69      * 通过反射,获得方法返回值第一个泛型参数的实际类型. 如: public Map<String, Buyer> getNames(){}
     70      *  
     71      * @param Method method 方法
     72      * @return 泛型参数的实际类型, 如果没有实现ParameterizedType接口,即不支持泛型,所以直接返回<code>Object.class</code>
     73      */ 
     74     @SuppressWarnings("unchecked")
     75     public static Class getMethodGenericReturnType(Method method) {
     76         return getMethodGenericReturnType(method, 0);
     77     }
     78     
     79     /**  
     80      * 通过反射,获得方法输入参数第index个输入参数的所有泛型参数的实际类型. 如: public void add(Map<String, Buyer> maps, List<String> names){}
     81      *  
     82      * @param Method method 方法
     83      * @param int index 第几个输入参数
     84      * @return 输入参数的泛型参数的实际类型集合, 如果没有实现ParameterizedType接口,即不支持泛型,所以直接返回空集合
     85      */ 
     86     @SuppressWarnings("unchecked")
     87     public static List<Class> getMethodGenericParameterTypes(Method method, int index) {
     88         List<Class> results = new ArrayList<Class>();
     89         Type[] genericParameterTypes = method.getGenericParameterTypes();
     90         if (index >= genericParameterTypes.length ||index < 0) {
     91              throw new RuntimeException("你输入的索引"+ (index<0 ? "不能小于0" : "超出了参数的总数"));
     92         } 
     93         Type genericParameterType = genericParameterTypes[index];
     94         if(genericParameterType instanceof ParameterizedType){
     95              ParameterizedType aType = (ParameterizedType) genericParameterType;
     96              Type[] parameterArgTypes = aType.getActualTypeArguments();
     97              for(Type parameterArgType : parameterArgTypes){
     98                  Class parameterArgClass = (Class) parameterArgType;
     99                  results.add(parameterArgClass);
    100              }
    101              return results;
    102         }
    103         return results;
    104     }
    105     /**  
    106      * 通过反射,获得方法输入参数第一个输入参数的所有泛型参数的实际类型. 如: public void add(Map<String, Buyer> maps, List<String> names){}
    107      *  
    108      * @param Method method 方法
    109      * @return 输入参数的泛型参数的实际类型集合, 如果没有实现ParameterizedType接口,即不支持泛型,所以直接返回空集合
    110      */ 
    111     @SuppressWarnings("unchecked")
    112     public static List<Class> getMethodGenericParameterTypes(Method method) {
    113         return getMethodGenericParameterTypes(method, 0);
    114     }
    115     /**  
    116      * 通过反射,获得Field泛型参数的实际类型. 如: public Map<String, Buyer> names;
    117      *  
    118      * @param Field field 字段
    119      * @param int index 泛型参数所在索引,从0开始.
    120      * @return 泛型参数的实际类型, 如果没有实现ParameterizedType接口,即不支持泛型,所以直接返回<code>Object.class</code>
    121      */ 
    122     @SuppressWarnings("unchecked")
    123     public static Class getFieldGenericType(Field field, int index) {
    124         Type genericFieldType = field.getGenericType();
    125         
    126         if(genericFieldType instanceof ParameterizedType){
    127             ParameterizedType aType = (ParameterizedType) genericFieldType;
    128             Type[] fieldArgTypes = aType.getActualTypeArguments();
    129             if (index >= fieldArgTypes.length || index < 0) { 
    130                 throw new RuntimeException("你输入的索引"+ (index<0 ? "不能小于0" : "超出了参数的总数"));
    131             } 
    132             return (Class)fieldArgTypes[index];
    133         }
    134         return Object.class;
    135     }
    136     /**  
    137      * 通过反射,获得Field泛型参数的实际类型. 如: public Map<String, Buyer> names;
    138      *  
    139      * @param Field field 字段
    140      * @param int index 泛型参数所在索引,从0开始.
    141      * @return 泛型参数的实际类型, 如果没有实现ParameterizedType接口,即不支持泛型,所以直接返回<code>Object.class</code>
    142      */ 
    143     @SuppressWarnings("unchecked")
    144     public static Class getFieldGenericType(Field field) {
    145         return getFieldGenericType(field, 0);
    146     }
    147 }

    8.

     1 package com.sanqing.util;
     2 
     3 public class PageIndex {
     4     private long startindex;
     5     private long endindex;
     6     
     7     public PageIndex(long startindex, long endindex) {
     8         this.startindex = startindex;
     9         this.endindex = endindex;
    10     }
    11     public long getStartindex() {
    12         return startindex;
    13     }
    14     public void setStartindex(long startindex) {
    15         this.startindex = startindex;
    16     }
    17     public long getEndindex() {
    18         return endindex;
    19     }
    20     public void setEndindex(long endindex) {
    21         this.endindex = endindex;
    22     }
    23      
    24     public static PageIndex getPageIndex(long viewpagecount, int currentPage, long totalpage){
    25             long startpage = currentPage-(viewpagecount%2==0? viewpagecount/2-1 : viewpagecount/2);
    26             long endpage = currentPage+viewpagecount/2;
    27             if(startpage<1){
    28                 startpage = 1;
    29                 if(totalpage>=viewpagecount) endpage = viewpagecount;
    30                 else endpage = totalpage;
    31             }
    32             if(endpage>totalpage){
    33                 endpage = totalpage;
    34                 if((endpage-viewpagecount)>0) startpage = endpage-viewpagecount+1;
    35                 else startpage = 1;
    36             }
    37             return new PageIndex(startpage, endpage);        
    38     }
    39 }

    9.

     1 package com.sanqing.util;
     2 
     3 import java.util.List;
     4 
     5 public class PageView<T> {
     6     /** 分页数据 **/
     7     private List<T> records;
     8     /** 页码开始索引和结束索引 **/
     9     private PageIndex pageindex;
    10     /** 总页数 **/
    11     private long totalpage = 1;
    12     /** 每页显示记录数 **/
    13     private int maxresult = 12;
    14     /** 当前页 **/
    15     private int currentpage = 1;
    16     /** 总记录数 **/
    17     private long totalrecord;
    18     /** 页码数量 **/
    19     private int pagecode = 10;
    20     /** 要获取记录的开始索引 **/
    21     public int getFirstResult() {
    22         return (this.currentpage-1)*this.maxresult;
    23     }
    24     public int getPagecode() {
    25         return pagecode;
    26     }
    27 
    28     public void setPagecode(int pagecode) {
    29         this.pagecode = pagecode;
    30     }
    31 
    32     public PageView(int maxresult, int currentpage) {
    33         this.maxresult = maxresult;
    34         this.currentpage = currentpage;
    35     }
    36     
    37     public void setQueryResult(QueryResult<T> qr){
    38         setTotalrecord(qr.getTotalrecord());
    39         setRecords(qr.getResultlist());
    40     }
    41     
    42     public long getTotalrecord() {
    43         return totalrecord;
    44     }
    45     public void setTotalrecord(long totalrecord) {
    46         this.totalrecord = totalrecord;
    47         setTotalpage(this.totalrecord%this.maxresult==0? this.totalrecord/this.maxresult : this.totalrecord/this.maxresult+1);
    48     }
    49     public List<T> getRecords() {
    50         return records;
    51     }
    52     public void setRecords(List<T> records) {
    53         this.records = records;
    54     }
    55     public PageIndex getPageindex() {
    56         return pageindex;
    57     }
    58     public long getTotalpage() {
    59         return totalpage;
    60     }
    61     public void setTotalpage(long totalpage) {
    62         this.totalpage = totalpage;
    63         this.pageindex = PageIndex.getPageIndex(pagecode, currentpage, totalpage);
    64     }
    65     public int getMaxresult() {
    66         return maxresult;
    67     }
    68     public int getCurrentpage() {
    69         return currentpage;
    70     }
    71 }

    10.

     1 package com.sanqing.util;
     2 
     3 import java.util.List;
     4 /**
     5  * 分页实体类封装
     6  *
     7  */
     8 public class QueryResult<T> {
     9     /** 获得结果集 **/
    10     private List<T> resultlist;
    11     /** 获得总的记录数 **/
    12     private long totalrecord;
    13     
    14     public List<T> getResultlist() {
    15         return resultlist;
    16     }
    17     public void setResultlist(List<T> resultlist) {
    18         this.resultlist = resultlist;
    19     }
    20     public long getTotalrecord() {
    21         return totalrecord;
    22     }
    23     public void setTotalrecord(long totalrecord) {
    24         this.totalrecord = totalrecord;
    25     }
    26 }

    11.

     1 ### direct log messages to stdout ###
     2 log4j.appender.stdout=org.apache.log4j.ConsoleAppender
     3 log4j.appender.stdout.Target=System.out
     4 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
     5 log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
     6 
     7 ### direct messages to file hibernate.log ###
     8 log4j.appender.file=org.apache.log4j.FileAppender
     9 log4j.appender.file.File=d:/crm.log
    10 log4j.appender.file.layout=org.apache.log4j.PatternLayout
    11 log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
    12 
    13 ### set log levels - for more verbose logging change 'info' to 'debug' ###
    14 
    15 log4j.rootLogger=warn, stdout,file
    16 
    17 #log4j.logger.org.hibernate=info
    18 #log4j.logger.org.hibernate=debug
    19 
    20 ### log HQL query parser activity
    21 #log4j.logger.org.hibernate.hql.ast.AST=debug
    22 
    23 ### log just the SQL
    24 #log4j.logger.org.hibernate.SQL=debug
    25 
    26 ### log JDBC bind parameters ###
    27 log4j.logger.org.hibernate.type=info
    28 #log4j.logger.org.hibernate.type=debug
    29 
    30 ### log schema export/update ###
    31 log4j.logger.org.hibernate.tool.hbm2ddl=debug
    32 
    33 ### log HQL parse trees
    34 #log4j.logger.org.hibernate.hql=debug
    35 
    36 ### log cache activity ###
    37 #log4j.logger.org.hibernate.cache=debug
    38 
    39 ### log transaction activity
    40 #log4j.logger.org.hibernate.transaction=debug
    41 
    42 ### log JDBC resource acquisition
    43 #log4j.logger.org.hibernate.jdbc=debug
    44 
    45 ### enable the following line if you want to track down connection ###
    46 ### leakages when using DriverManagerConnectionProvider ###
    47 #log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace
    48 log4j.logger.com.quote = debug
  • 相关阅读:
    缓存服务Ehcache方案
    sql的一点总结<一>
    消息队列-ActiveMQ
    Kettle数据抽取解决方案
    在VMware上安装VMTools
    数组去重方法
    横向tab计算滚动位置
    无高度内容垂直居中
    常见富文本处理方法
    极简触感反馈Button组件
  • 原文地址:https://www.cnblogs.com/shamgod/p/5328266.html
Copyright © 2011-2022 走看看