1、编写配置文件

  1. #债权转让
  2. #默认周期 必须大于0
  3. credit.defaultDuration=1
  4. #最小转让金额(元)
  5. credit.minBidAmount=1.00
  6. #最小转让时间 到期时间小于此的不让进行转让(小时)
  7. credit.assignThreshold=24
  8. #最小折让率(%)
  9. credit.minDiscountRate=70
  10. #最大折让率(%)
  11. credit.maxDiscountRate=110
2、配置 spring 
  1. <!-- 配置参数 -->
  2. <bean id="configProperties"
  3. class="org.springframework.beans.factory.config.PropertiesFactoryBean">
  4. <property name="locations">
  5. <value>file:${config.root}/admin-config.properties</value>
  6. </property>
  7. </bean>
  8. <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
  9. <property name="properties" ref="configProperties" />
  10. </bean>
3、编写 Java类
可以 注入 静态属性 ,方法 要非静态
  1. package com.netfinworks.fax.admin.web.config;
  2. import org.slf4j.Logger;
  3. import org.slf4j.LoggerFactory;
  4. import org.springframework.beans.factory.annotation.Value;
  5. import org.springframework.stereotype.Component;
  6. import com.netfinworks.common.util.money.Money;
  7. /**
  8. * <p>
  9. * 常量配置
  10. *</p>
  11. * @author weichunhe
  12. * @version $Id: Constant.java, v 0.1 2015年5月28日 下午5:14:22 weichunhe Exp $
  13. */
  14. @Component
  15. public class Constant {
  16. private Logger log = LoggerFactory.getLogger(getClass());
  17. private static final String LOG_PREFIX = "从配置文件中注入常量==>";
  18. /**
  19. * 债权转让 默认周期 周期必须大于0
  20. */
  21. private static int defaultDuration=1;
  22. @Value("#{configProperties['credit.defaultDuration']}")
  23. public void setDefaultDuration(String defaultDuration) {
  24. try {
  25. Constant.defaultDuration = Integer.valueOf(defaultDuration);
  26. } catch (Exception e) {
  27. log.error(LOG_PREFIX+"注入默认周期出错!"+defaultDuration,e);
  28. }
  29. }
  30. /**
  31. * 债权转让 最小转让时间 到期时间小于此的不让进行转让(毫秒)
  32. */
  33. private static long assignThreshold = 24*60*60*1000;
  34. @Value("#{configProperties['credit.assignThreshold']}")
  35. public void setAssignThreshold(String assignThreshold) {
  36. try {
  37. Constant.assignThreshold = Long.valueOf(assignThreshold) * 60 * 60 *1000L;
  38. } catch (Exception e) {
  39. log.error(LOG_PREFIX+"注入 最小转让时间出错!"+assignThreshold,e);
  40. }
  41. }
  42. /**
  43. * 债权转让 最小转让金额(元)
  44. */
  45. private static Money minBidAmount ;
  46. @Value("#{configProperties['credit.minBidAmount']}")
  47. public void setMinBidAmount(Money minBidAmount) {
  48. Constant.minBidAmount = minBidAmount;
  49. }
  50. /**
  51. * 债权转让最小折让率(%)
  52. */
  53. private static int minDiscountRate = 0;
  54. @Value("#{configProperties['credit.minDiscountRate']}")
  55. public void setMinDiscountRate(String minDiscountRate) {
  56. try {
  57. Constant.minDiscountRate =Integer.valueOf(minDiscountRate);
  58. } catch (Exception e) {
  59. log.error(LOG_PREFIX+"注入最小折让率出错!"+minDiscountRate,e);
  60. }
  61. }
  62. /**
  63. * 债权转让最大折让率(%)
  64. */
  65. private static int maxDiscountRate = 110;
  66. @Value("#{configProperties['credit.maxDiscountRate']}")
  67. public void setMaxDiscountRate(String maxDiscountRate) {
  68. try {
  69. Constant.maxDiscountRate =Integer.valueOf(maxDiscountRate);
  70. } catch (Exception e) {
  71. log.error(LOG_PREFIX+"注入最大折让率出错!"+maxDiscountRate,e);
  72. }
  73. }
  74. public static int getMinDiscountRate() {
  75. return minDiscountRate;
  76. }
  77. public static int getMaxDiscountRate() {
  78. return maxDiscountRate;
  79. }
  80. public static long getAssignThreshold() {
  81. return assignThreshold;
  82. }
  83. public static Money getMinBidAmount() {
  84. return minBidAmount;
  85. }
  86. public static int getDefaultDuration() {
  87. return defaultDuration;
  88. }
  89. }
4、使用 
  1. model.put("defaultDuration", Constant.getDefaultDuration());
  2. model.put("minDiscountRate", Constant.getMinDiscountRate());
  3. model.put("maxDiscountRate", Constant.getMaxDiscountRate());

最新文章

  1. 2016-03-04记录 H264.TXT 转成 H264.h264
  2. T-SQL编程练习(带注释)
  3. adeng朝花夕拾
  4. remount failed: Operation not permitted ,怎么办呢?
  5. AS3绘制扇形算法解析
  6. Dynamic CRM 2013学习笔记(四)单据编号及插件批量注册工具
  7. iOS8跳到系统设置页面
  8. java之生产者与消费者
  9. 使用NPOI完成导出Excel文件
  10. 纯CSS3大转盘抽奖(响应式、可配置)
  11. [App]Xamarin学习资料收集
  12. NetAnalyzer笔记 之 六 用C#打造自己的网络连接进程查看器(为进程抓包做准备)
  13. Pojo和JavaBean的区别(转载)
  14. Android应用开发之(通过ClipboardManager, ClipData进行复制粘贴)
  15. smarty模板做人员表信息删除,修改 里面的性别单选按钮民族下拉,另外登录进去可以显示姓名
  16. JS中一些常用的内置对象
  17. 学习笔记TF030:实现AlexNet
  18. Hi3531添加16GByte(128Gbit) NAND Flash支持
  19. memcached 源码阅览 一
  20. NODE 模块 FS-EXTRA

热门文章

  1. Linux下清除DNS缓存
  2. 高数(A)下 第十章
  3. maven 本地配置
  4. FreeMarker与Servlet结合示例
  5. Ubuntu 10.04.3 挂载NTFS移动硬盘
  6. Lotto(DFS处理)
  7. Cocos2d-x3.3RC0载入Android的WebView
  8. HDU2082 找单词 【母函数】
  9. 【bzoj1015】[JSOI2008]星球大战starwar
  10. e.printStackTrace()介绍