接口配置表设计逻辑

接口配置,比如接口地址,
一般为4中方式:

第一种

直接在代码中写 String address="" ,

第二种

将接口地址写入配置文件中 dataconfig.properties

package nc.bs.pub.constants;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import nc.bs.framework.common.RuntimeEnv;

public class PubConstants {
    public static String homePath=RuntimeEnv.getInstance().getNCHome();//获取home路径
    private static Properties props = null ;//配置文件
    public static int   punitcurrdigit=4;//单价小数位换算
    public static int   munitcurrdigit=2;//金额小数位换算
  
  /**
   * 读取文件获取配置信息
   * getDataConfig:  
   * @return  Properties  TODO(参数说明)
   * 创  建  人 :lihy
   * 创建时间:2019年5月15日-下午12:38:35
   */
  public static Properties getDataConfig() {
    props = new Properties();
    String filePath =homePath+ "/modules/yuantong/dataconfig.properties";
    InputStream in = null ;
      try {
        in = new BufferedInputStream (new FileInputStream(filePath));
        props.load(in);
             } catch (IOException e) {
        e.printStackTrace();
      }
      return props;
  }
  
  /**
   * 获取配置文件的参数
   * getParameter:  
   * @param key
   * @return  String  TODO(参数说明)
   * 创  建  人 :lihy
   * 创建时间:2019年5月15日-下午12:39:03
   */
  public synchronized static String getParameter(String key){
    if(props != null ){
      
      return props.getProperty(key);
    } else {
      return getDataConfig().getProperty(key);
    }
  }

}
第三种

将接口地址写入 前台参数自定义档案维护中
通过查询数据库 获取接口地址
sql:

select  code  from bd_defdoc where code ='' and nvl(dr,0)=0 and   pk_defdoclist in (select pk_defdoclist from bd_defdoclist where code ='1183-0005' and nvl(dr,0)=0;
第四种

创建一张接口配置表,类似于第三种 ,不过更灵活,不用局限与系统限制。

总结

获取配置数据,大体分为三种,

第一种 程序中写死

优点:最简单的方式
缺点:也是最危险的方式,极其容易将测试与正式搞错
建议:最好不要用

第一种 将参数写入配置文件

将参数写入配置文件中,不管是.properties 还是.xml .yml
都是配置文件的一种。
优点:读取速度一般比将参数写到数据库中读取快很多。
缺点:修改配置文件需要重启服务。
建议:不经常改动的参数添加到配置文件中

第二种,将配置参数写入数据库中

优点: 修改参数不需要重启服务器。直接修改数据就可以实现配置修改
缺点: 读取速度一般比读取配置文件慢。
建议:不想写配置文件可以写入数据库中读取。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。