-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v0.0.4 release. 修复获取方法参数名错误:'arg0,arg1,argN...'。使用 DefaultParameterNa…
…meDiscoverer 获取正确的参数名。
- Loading branch information
1 parent
b76cdfb
commit 365fbf1
Showing
12 changed files
with
20 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,28 @@ | ||
package cn.dustlight.captcha; | ||
|
||
import org.springframework.beans.factory.BeanFactory; | ||
import org.springframework.core.DefaultParameterNameDiscoverer; | ||
|
||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Parameter; | ||
import java.util.Collections; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
public class Util { | ||
|
||
private static final DefaultParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer(); | ||
|
||
public static <T> T getBean(BeanFactory factory, String name, Class<? extends T> clazz) { | ||
return factory.getBean(name, clazz); | ||
} | ||
|
||
public static Map<String, Object> getParameters(Method method, Object[] arguments) { | ||
String[] names; | ||
if (arguments == null || (names = parameterNameDiscoverer.getParameterNames(method)) == null) | ||
return Collections.EMPTY_MAP; | ||
Map<String, Object> parameters = new LinkedHashMap<>(); | ||
if (method.getParameterCount() > 0) { | ||
Parameter[] parameters1 = method.getParameters(); | ||
for (int i = 0, len = Math.min(arguments.length, parameters1.length); i < len; i++) | ||
parameters.put(parameters1[i].getName(), arguments[i]); | ||
} | ||
for (int i = 0, len = Math.min(names.length, arguments.length); i < len; i++) | ||
parameters.put(names[i], arguments[i]); | ||
return parameters; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters