「Spring入門」SchemaContextHolderの使い方

1.SchemaContextHolder.java
public class SchemaContextHolder {
private static ThreadLocal<SchemaType> contextHolder = new ThreadLocal<SchemaType>();

public static void setSchemaType(SchemaType datasourcename) {
Assert.notNull(datasourcename, “Schema type cannot be null.");
contextHolder.set(datasourcename);
}

public static SchemaType getSchemaType() {
return contextHolder.get();
}

public static void clear() {
contextHolder.remove();
}
}

2.enumクラス
public enum SchemaType {
ADMIN,
MASTER
}

3.Javaコード
public List<Employee> listinfo(@RequestParam(“ds") String ds){
if(ds.equals(“ds1")){
SchemaContextHolder.setSchemaType(SchemaType.ADMIN);
}else{
SchemaContextHolder.setSchemaType(SchemaType.MASTER);
}
return empService.listInfo();
}

Java

Posted by arkgame