从struts2源码学到的技巧

1把字符串转为set集合

includeMethods=“abc,ext,spring”;

com.opensymphony.xwork2.util.TextParseUtil.commaDelimitedStringToSet(includeMethods);

 

2正则表达式过滤方法

method方法的名称

excludeMethods不包括的正则表达(Set<String>集合)

includeMethods包括的正则表达(Set<String>集合)

com.opensymphony.xwork2.interceptor.MethodFilterInterceptorUtil.applyMethod(excludeMethods, includeMethods, method);

 

3equals写法

@Override
public boolean equals(Object o) {
if (!(o instanceof Key)) {
return false;
}
if (o == this) {
return true;
}
Key other = (Key) o;
return name.equals(other.name) && type.equals(other.type);
}

 

4将字符的true或false变为布尔型

throwException为true或false的字串

 this.throwExceptionOnELFailure = "true".equals(throwException);

 

5 判定此 Class 对象(clazz)所表示的类或接口与指定的 Class 参数所表示的类或接口是否相同,或是否是其超类或超接口。

clazz.isAssignableFrom(component.getClass()) 

 

6先获取实现TemplateEngine接口的类的名字。然后构造它们的对象,放到map里面去。

Set<String> prefixes = container.getInstanceNames(TemplateEngine.class);
for (String prefix : prefixes) {
map.put(prefix, new LazyEngineFactory(prefix));
}

 

7解析字符串

configPaths="struts-default.xml,struts-plugin.xml,struts.xml";

String[] files = configPaths.split("\\s*[,]\\s*");

 

Java交流群 241351407         可能满了

posted on 2012-11-12 09:25  angelshelter  阅读(190)  评论(0编辑  收藏  举报

导航