源代码下载地址:http://www.zuidaima.com/share/1550463705844736.htm
Spring配置文件中
<!-- 扫描常量类-->
<bean id="constants" class="com.support.Constants"/>
类中调用 Constants.DEFAULT_PAGE
属性文件(filed.propertites)
#2*1024*1024 file.thresholdSize=2097152
#100*1024*1024 file.maxSize=104857600
# 分页参数
#默认页数从0开始 DEFAULT_PAGE=0
#默认每页记录数 DEFAULT_SIZE=10
package com.zuidaima.megalith.support; import java.io.IOException; import java.io.InputStream; import java.util.Properties; /** * * <p> * 项目常量定义 * </p> * * * * * * @version V1.0.0 * * @author www.zuidaima.com * * @date 2013-7-10 上午11:36:34 * * @class com.support.Constants * */ public class Constants { /*---------------------- 默认分页参数 ---------------------*/ /** * 默认页数从0开始 */ public static Integer DEFAULT_PAGE; /** * 默认每页记录数 */ public static Integer DEFAULT_SIZE; /*----------------------Session key ----------------------*/ public static String SESSION_USER; public static String SESSION_USER_NAME; /*---------------------FileUpload fileds ----------------*/ public static Integer FILE_THRESHOLD_SIZE; public static String FILE_TEMP_PATH; public static Integer FILE_MAX_SIZE; public static String FILE_REAL_PATH; /*---------------------ResouceUpload Path ----------------*/ public static String ZIPPATH_UPLOAD;//默认资源文件zip包上传目录 public static String ZIPPATH_UNZIP;//默认资源文件解压后目录 public static String TEMPLATE_PATH;//默认模板文件上传后路径 Properties props = new Properties(); InputStream inputStream = null; public Constants() { try { inputStream = getClass().getResourceAsStream("/filed.properties"); props.load(inputStream); } catch (IOException e) { e.printStackTrace(); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } FILE_TEMP_PATH = props.getProperty("file.tempPath"); FILE_THRESHOLD_SIZE = Integer.parseInt(props.getProperty("file.thresholdSize")); FILE_MAX_SIZE = Integer.parseInt(props.getProperty("file.maxSize")); FILE_REAL_PATH = props.getProperty("file.realPath"); DEFAULT_PAGE = Integer.parseInt(props.getProperty("DEFAULT_PAGE")); DEFAULT_SIZE = Integer.parseInt(props.getProperty("DEFAULT_SIZE")); SESSION_USER = props.getProperty("SESSION_USER"); SESSION_USER_NAME = props.getProperty("SESSION_USER_NAME"); ZIPPATH_UNZIP = props.getProperty("ZIPPATH_UNZIP"); ZIPPATH_UPLOAD = props.getProperty("ZIPPATH_UPLOAD"); TEMPLATE_PATH = props.getProperty("TEMPLATE_PATH"); } }
原文地址:http://blog.csdn.net/springmvc_springdata/article/details/44452789