After the transformation of the company framework, individual queries reported an error, the error is as follows
Parameter "xxx" not found.Available parameters are [arg0,collection,list]
Copy the code
The debugging code is as follows:
public ParamNameResolver(Configuration config, Method method) {
this.useActualParamName = config.isUseActualParamName();
finalClass<? >[] paramTypes = method.getParameterTypes();final Annotation[][] paramAnnotations = method.getParameterAnnotations();
final SortedMap<Integer, String> map = new TreeMap<>();
int paramCount = paramAnnotations.length;
// get names from @Param annotations
for (int paramIndex = 0; paramIndex < paramCount; paramIndex++) {
if (isSpecialParameter(paramTypes[paramIndex])) {
// skip special parameters
continue;
}
String name = null;
for (Annotation annotation : paramAnnotations[paramIndex]) {
if (annotation instanceof Param) {
hasParamAnnotation = true;
name = ((Param) annotation).value();
break; }}if (name == null) {
// @Param was not specified.
if (useActualParamName) {
name = getActualParamName(method, paramIndex);
}
if (name == null) {
// use the parameter index as the name ("0", "1", ...)
// gcode issue #71
name = String.valueOf(map.size());
}
}
map.put(paramIndex, name);
}
names = Collections.unmodifiableSortedMap(map);
}
Copy the code
Because the code has only one parameter, the @param annotation is not used, and the compiled plug-in is not in Springboot-starter -parent. In fact, the main parameter here is set to true
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<parameters>true</parameters>
</configuration>
</plugin>
Copy the code
This parameter is a javac parameter. Without this parameter, the compiled parameter is arg0 and arg1. If this parameter is added, the parameter name is used. In the mybatis
if (useActualParamName) {
name = getActualParamName(method, paramIndex);
}
Copy the code
UseActualParamName If this attribute is true, the actual parameter name is obtained through the JVM. This results in the error above. When this parameter is added, it is normal, but the problem is not over, the outsourcing project has its own written DB framework. Parameter “arg0” not found.Available parameters are [param1, XXX,yyy,param2
public class BaseSQLBuilder { public final static String SCRIPT_PREFIX = "<script>"; public final static String SCRIPT_SUFFIX = "</script>"; public final static String ARG_0 = "arg0"; public String buildBySQL(Map<String, Object> params) { Assert.notEmpty(params, "Parameter params cannot be null or empty"); return joinScriptXml(params.get(ARG_0) + StringUtils.EMPTY); } private String joinScriptXml(String value) { StringBuilder builder = new StringBuilder(); builder.append(SCRIPT_PREFIX).append(value).append(SCRIPT_SUFFIX); return builder.toString(); }}Copy the code
What if the DB framework steals a lazy write while building SQL and takes arg0? It doesn’t matter, this is just a product of the compile phase, so compile the DB framework alone without parameters.