需求
在maven编译过程中,获取mybatis的sql
核心基础
org.apache.ibatis.binding.MapperMethod#getParam
private Object getParam(Object[] args) {
final int paramCount = paramPositions.size();
if (args == null || paramCount == 0) {
return null;
} else if (!hasNamedParameters && paramCount == 1) {
return args[paramPositions.get(0)];
} else {
Map<String, Object> param = new MapperParamMap<Object>();
for (int i = 0; i < paramCount; i++) {
param.put(paramNames.get(i), args[paramPositions.get(i)]);
}
// issue #71, add param names as param1, param2...but ensure backward compatibility
for (int i = 0; i < paramCount; i++) {
String genericParamName = "param" + String.valueOf(i + 1);
if (!param.containsKey(genericParamName)) {
param.put(genericParamName, args[paramPositions.get(i)]);
}
}
return param;
}
}
核心代码
获取参数
private Object getMethodParamValues(Method method){
int paraCount = method.getParameterTypes().length;
if(paraCount <= 1){
return null;
}
return Maps.newHashMap();
}
获取sql
mappedStatement.getBoundSql(paramValues).getSql();
网友评论