daoconfig.java

来自「ajax博客系统,该文件内容部分综合网上的资源,自己进行了改进,转载请注明 汪建」· Java 代码 · 共 45 行

JAVA
45
字号
package cn.hxex.blog.config;

import org.apache.commons.lang.builder.ReflectionToStringBuilder;

import cn.hxex.blog.exception.BlogException;

public class DaoConfig {
	
	private String id;
	private String type;
	private Object instance;
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	
	public Object getInstance(){
		if(instance != null)
		{
			return instance;
		}
		try {
			Class cls = Class.forName(this.getType());
			instance = cls.newInstance();
			return instance;
		} catch (Exception e) {
			throw new BlogException("Couldn't find class:" + getType());
		}
	}
	
	public String toString(){
		return ReflectionToStringBuilder.toString(this);
	}

}

⌨️ 快捷键说明

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