public class DataSourceConst {
public static final String MANAGER = "MANAGER";
public static final String STMT = "STMT";
public static final String NODB = "NODB";
}
2. 建立一个获得和设置上下文环境的类,主要负责改变上下文数据源的名称:
public class DataSourceHandle {
private static final ThreadLocal contextHolder = new ThreadLocal(); // 线程本地环境
// 设置数据源类型
public static void setDataSourceType(String dataSourceType) {
contextHolder.set(dataSourceType);
}
select a.id,a.parentid,a.cname,a.priority,a.ifactive from hopetas_manager.dbo.dictionary a inner join zj.dbo.dictionary b on a.id=b.id where a.parentid= #{id,jdbcType=INTEGER}
</select>
6.程序调用: 在DAO操作前处理set setDataSourceType 的值
// 利用递归来处理字段
public void getDict0(Eement element, Integer id,Integer j) {
//设置数据源
DataSourceHandle.setDataSourceType(DataSourceConst.NODB);
ArrayList list = (ArrayList) this.dictMapper
.selectDBDictionary(id);
String str = "dir";
j++;
if (list.size() != 0 && list != null) {
for (Iterator iter = list.iterator(); iter.hasNext();) {
Dictionary dict = (Dictionary) iter.next();
Element el = element.addElement(str+j);
Element prop1 = el.addAttribute("id", dict.getId().toString());
Element prop2 = el.addAttribute("name", dict.getCname()
.toString());
getDict0(el, dict.getId(),j);
}
}