layoutconfig.java

来自「struts spring ibatis」· Java 代码 · 共 43 行

JAVA
43
字号
package com.struts2.framework.util;

import java.io.IOException;
import java.util.Properties;

/**
 * @author Jecky Luo
 * 
 * Layout类用来读取layout属性表的内容
 *
 */
public class LayoutConfig {

	private static LayoutConfig config = new LayoutConfig(); //存放LayoutConfig单一实例

	private static Properties layoutProps = new Properties();

	/**
	 * 构造方法设置为private类型,保证Layout类只有一个实例被创建
	 */
	public LayoutConfig() {
		//从属性文件读取配置信息
		try {
			layoutProps.load(
				LayoutConfig.class.getClassLoader().getResourceAsStream(
					"layout.properties"));
		} catch (IOException ioe) {
			System.out.println("LayoutConfig file load error: " + ioe.getMessage());
		}
	}

	public static LayoutConfig getInstance() {
		return config;
	}
	
	/**
	 * 根据key返回属性值
	 */
	public String getProperty (String key) {
		return layoutProps.getProperty(key);
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?