如何获取.properties配置文件中的参数,我在网上查了半天没弄明白,后来在以前的项目中找到了,就写下来,避免遗忘。
1.配置文件:message_product.properties
total_product=2
service1=1,新股发行短信提醒服务,发行的详细信息
service2=2,配股短信提醒服务&增发短信提醒服务,增发的详细信息
validatecode_temp=验证码:${vilidateCode}。
#消息持续发送时间,单位”小时“
message_constant_time=24
#消息的编码格式 15 GBK编码 30 彩信 31 wappush 32 长短信 33个性彩信'
message_formart=15
#'消息的优先级: 0 最低 --- 3 最高';
message_priority=3
#'消息的下发类型: 0 免费下发 1 按条下发 2 包月下发 3 订阅请求 4 取消请求 5 包月扣费';
message_type=0
#产品ID numproductid
message_product_id=724
#numchannelid
message_channelid=0
2.java 类
package com.margin.utils;
import java.io.UnsupportedEncodingException;
import java.util.ResourceBundle;
import com.margin.po.MessageProduct;
public class MessageProperties {
private static ResourceBundle rb;
static {
rb = ResourceBundle.getBundle("message_product");
}
/**
* 得到短信服务总数
* @return
*/
public static int getTotalProduct() {
return Integer.parseInt(rb.getString("total_product"));
}
/**
* 消息持续发送时间
* @return
*/
public static int getMessageConstantTime()
{
return Integer.parseInt(rb.getString("message_constant_time").trim());
}
/**
* 消息格式
* @return
*/
public static int getMessageFormat()
{
return Integer.parseInt(rb.getString("message_formart").trim());
}
/**
* 消息发送优先级
* @return
*/
public static int getMessagePriority()
{
return Integer.parseInt(rb.getString("message_priority").trim());
}