package com.vineetmanohar.util;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
* Extend this class to implement a server side method that takes arguments that
* you would like to call via expression language.
*
* @author Vineet Manohar
*/
public abstract class ELMethod extends HashMap
Call.java:
package com.vineetmanohar.util;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* This class lets you call static methods from EL
*
* Step 1) Create an instance of this class and bind it to the "call" variable
* in your EL. For example, in a JSP do the following:
* request.setAttribute("call", new Call());
*
* Step 2) Call any static method as follows:
*
* ${call["some.package.SomeClass.methodName"]["arg1"][arg2]}
*
* The first argument is the fully qualified class and method name. The
* remaining arguments are arguments to the method that you are calling.
*
* Note: method overloading not supported
*
* Note: method must be static
*
* @author Vineet Manohar
*/
public class Call extends HashMap {
private static final long serialVersionUID = 1L;
@Override
public Object get(Object key) {
String fullyQualifiedMethodName = (String) key;
// format of key is package.Class.method
Pattern pattern = Pattern.compile("(.+)\\.([^\\.]+)");
Matcher m = pattern.matcher(fullyQualifiedMethodName);
if (m.matches()) {
String fqClassName = m.group(1);
String methodName = m.group(2);
Class clazz;
try {
clazz = (Class) Class.forName(fqClassName);
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Invalid method name: "
+ key, e);
}
Method[] methods = clazz.getMethods();
for (final Method method : methods) {
if ((method.getModifiers() & Modifier.STATIC) == 0) {
continue;
}
if (method.getName().equals(methodName)) {
// return the first method found
int numParameters = method.getParameterTypes().length;
if (numParameters == 0) {
return invokeMethod(method);
}
return new ELMethod(numParameters) {
@Override
public Object result(Object[] args) {
return invokeMethod(method, args);
}
};
}
}
}
throw new IllegalArgumentException("Invalid method name: " + key
+ ". Must be a fully qualified class and method name");
}
private Object invokeMethod(final Method method, Object... args) {
try {
return method.invoke(null, args);
} catch (IllegalArgumentException e) {
throw new RuntimeException("Exception while executing method", e);
} catch (IllegalAccessException e) {
throw new RuntimeException("Exception while executing method", e);
} catch (InvocationTargetException e) {
throw new RuntimeException("Exception while executing method", e);
}
}
}
为了将数据访问与业务逻辑分离,提高业务精度,降低代码之间的耦合,模型层又细分为 DAO 层与 Service 业务层,DAO 全称为 Data Access Object(数据访问对象),将数据库访问代码封闭起来,MyBatis API 也在此封装,不再出现在其他层或向其他层暴露;业务层是整个系统最核心也最具价值的一层,该层对应用程序的业务逻辑进行封装,务求关注客户需求,在业务处理过程中会访问原始数据或产生新数据,或者需要持久化数据,DAO 层提供的 DAO 类能很好地帮助业务层完成数据处理,业务层本身则侧重于对客户需求的理解和业务规则的适应,自然也包括大部分的计算。
MyBatis 封装在 DAO 层,负责数据访问操作;Spring MVC 充当控制器角色,对用户数据进行合法性检验和类型转换,为视图层提供标签简化页面显示,提供国际化支持等等;Spring是应用程序的管家,DAO、Service(业务)、Action 等对象由 Spring 创建并维护各对象之间关系,同时提供声明式事务管理,简化事务编程。
1、网络上现成的资料
格式: sed -i "s/查找字段/替换字段/g" `grep 查找字段 -rl 路径`
linux sed 批量替换多个文件中的字符串
sed -i "s/oldstring/newstring/g" `grep oldstring -rl yourdir`
例如:替换/home下所有文件中的www.admi
对于AJAX应用(使用XMLHttpRequests)来说,向服务器发起请求的传统方式是:获取一个XMLHttpRequest对象的引用、发起请求、读取响应、检查状态码,最后处理服务端的响应。整个过程示例如下:
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange
Hive中的排序语法 2014.06.22 ORDER BY
hive中的ORDER BY语句和关系数据库中的sql语法相似。他会对查询结果做全局排序,这意味着所有的数据会传送到一个Reduce任务上,这样会导致在大数量的情况下,花费大量时间。
与数据库中 ORDER BY 的区别在于在hive.mapred.mode = strict模式下,必须指定 limit 否则执行会报错。
post-commit hook failed (exit code 1) with output:
svn: E155004: Working copy 'D:\xx\xxx' locked
svn: E200031: sqlite: attempt to write a readonly database
svn: E200031: sqlite: attempt to write a