Skip to content

When resolving constructor args, @Param should precede actual name ev… #1093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ language: java
sudo: false
dist: precise

addons:
hosts:
- mybatisci
hostname: mybatisci

jdk:
- oraclejdk8
- oraclejdk7
Expand Down
35 changes: 20 additions & 15 deletions src/main/java/org/apache/ibatis/mapping/ResultMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,24 +185,29 @@ private boolean argTypesMatch(final List<String> constructorArgNames,
}

private List<String> getArgNames(Constructor<?> constructor) {
if (resultMap.configuration.isUseActualParamName() && Jdk.parameterExists) {
return ParamNameUtil.getParamNames(constructor);
} else {
List<String> paramNames = new ArrayList<String>();
final Annotation[][] paramAnnotations = constructor.getParameterAnnotations();
int paramCount = paramAnnotations.length;
for (int paramIndex = 0; paramIndex < paramCount; paramIndex++) {
String name = null;
for (Annotation annotation : paramAnnotations[paramIndex]) {
if (annotation instanceof Param) {
name = ((Param) annotation).value();
break;
}
List<String> paramNames = new ArrayList<String>();
List<String> actualParamNames = null;
final Annotation[][] paramAnnotations = constructor.getParameterAnnotations();
int paramCount = paramAnnotations.length;
for (int paramIndex = 0; paramIndex < paramCount; paramIndex++) {
String name = null;
for (Annotation annotation : paramAnnotations[paramIndex]) {
if (annotation instanceof Param) {
name = ((Param) annotation).value();
break;
}
}
if (name == null && resultMap.configuration.isUseActualParamName() && Jdk.parameterExists) {
if (actualParamNames == null) {
actualParamNames = ParamNameUtil.getParamNames(constructor);
}
if (actualParamNames.size() > paramIndex) {
name = actualParamNames.get(paramIndex);
}
paramNames.add(name != null ? name : "arg" + paramIndex);
}
return paramNames;
paramNames.add(name != null ? name : "arg" + paramIndex);
}
return paramNames;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public User(@Param("id") String id) {
this.id = Integer.valueOf(id);
}

public User(Integer userId, String name) {
public User(Integer userId, @Param("name") String userName) {
super();
this.id = userId;
this.name = name;
this.name = userName;
}

public User(@Param("id") int id, @Param("name") String name, @Param("team") String team) {
Expand Down