diff --git a/mars-core/pom.xml b/mars-core/pom.xml index 0b558de..b20e765 100644 --- a/mars-core/pom.xml +++ b/mars-core/pom.xml @@ -5,7 +5,7 @@ com.github.yuyenews Mars - 3.0.5 + 3.0.6 mars-core diff --git a/mars-jdbc/pom.xml b/mars-jdbc/pom.xml index cb61d94..ab59b2b 100644 --- a/mars-jdbc/pom.xml +++ b/mars-jdbc/pom.xml @@ -5,7 +5,7 @@ Mars com.github.yuyenews - 3.0.5 + 3.0.6 4.0.0 mars-jdbc diff --git a/mars-mvc/pom.xml b/mars-mvc/pom.xml index 7d1f161..1638472 100644 --- a/mars-mvc/pom.xml +++ b/mars-mvc/pom.xml @@ -5,7 +5,7 @@ com.github.yuyenews Mars - 3.0.5 + 3.0.6 mars-mvc diff --git a/mars-mvc/src/main/java/com/mars/mvc/proxy/ExecuteRef.java b/mars-mvc/src/main/java/com/mars/mvc/proxy/ExecuteRef.java index 2c8c847..b5ee96d 100644 --- a/mars-mvc/src/main/java/com/mars/mvc/proxy/ExecuteRef.java +++ b/mars-mvc/src/main/java/com/mars/mvc/proxy/ExecuteRef.java @@ -30,24 +30,27 @@ public class ExecuteRef { protected static Object executeRef(Method method, Object[] args) throws Exception { /* 根据注解获取到对应的bean对象实体 */ MarsReference marsReference = method.getAnnotation(MarsReference.class); - MarsBeanModel marsBeanModel = getMarsBeanModel(marsReference); /* 获取bean对象的class和实例 */ + MarsBeanModel marsBeanModel = getMarsBeanModel(marsReference); Class cls = marsBeanModel.getCls(); Object obj = marsBeanModel.getObj(); + /* 获取引用的资源名称 */ + String refName = getRefName(method,marsReference); + if(marsReference.refType().equals(RefType.METHOD)){ /* 如果引用的是一个方法则执行bean里面对应的方法 */ - Object result = executeRefMethod(cls,obj,args,marsReference); + Object result = executeRefMethod(cls,obj,args,refName); if(result.equals("errorRef")){ - throw new Exception("没有找到名称为["+marsReference.refName()+"]的方法"); + throw new Exception("没有找到名称为["+refName+"]的方法"); } return result; } else { /* 否则就将bean里面对应的属性的值返回 */ - Field field = cls.getDeclaredField(marsReference.refName()); + Field field = cls.getDeclaredField(refName); if(field == null){ - throw new Exception("没有找到名称为["+marsReference.refName()+"]的属性"); + throw new Exception("没有找到名称为["+refName+"]的属性"); } field.setAccessible(true); return field.get(obj); @@ -61,8 +64,7 @@ public class ExecuteRef { * @throws Exception 异常 */ private static MarsBeanModel getMarsBeanModel(MarsReference marsReference) throws Exception { - if(marsReference == null || StringUtil.isNull(marsReference.beanName()) - || StringUtil.isNull(marsReference.refName())){ + if(marsReference == null || StringUtil.isNull(marsReference.beanName())){ throw new Exception("没有配置MarsReference注解或者配置不正确"); } @@ -78,14 +80,14 @@ public class ExecuteRef { * @param cls 类 * @param obj 对象 * @param args 参数 - * @param marsReference 引用注解 + * @param refName 引用的资源 * @return 返回值 * @throws Exception 异常 */ - private static Object executeRefMethod(Class cls,Object obj,Object[] args, MarsReference marsReference) throws Exception { + private static Object executeRefMethod(Class cls,Object obj,Object[] args, String refName) throws Exception { Method[] methods = cls.getDeclaredMethods(); for(Method methodItem : methods){ - if(methodItem.getName().equals(marsReference.refName())){ + if(methodItem.getName().equals(refName)){ Class[] paramTypes = methodItem.getParameterTypes(); Object[] refMethodParams = ParamUtil.getServiceParams(paramTypes,args); if(refMethodParams == null){ @@ -96,4 +98,18 @@ public class ExecuteRef { } return "errorRef"; } + + /** + * 获取引用的资源名称 + * @param method api的方法 + * @param marsReference 引用注解配置 + * @return + */ + private static String getRefName(Method method,MarsReference marsReference){ + String refName = marsReference.refName(); + if(StringUtil.isNull(refName)){ + return method.getName(); + } + return refName; + } } diff --git a/mars-netty/pom.xml b/mars-netty/pom.xml index a1374c0..18f257d 100644 --- a/mars-netty/pom.xml +++ b/mars-netty/pom.xml @@ -5,7 +5,7 @@ com.github.yuyenews Mars - 3.0.5 + 3.0.6 mars-netty diff --git a/mars-redis/pom.xml b/mars-redis/pom.xml index 3e6e778..9e13b6c 100644 --- a/mars-redis/pom.xml +++ b/mars-redis/pom.xml @@ -5,7 +5,7 @@ Mars com.github.yuyenews - 3.0.5 + 3.0.6 4.0.0 diff --git a/mars-server/pom.xml b/mars-server/pom.xml index 7d7a67c..414da2c 100644 --- a/mars-server/pom.xml +++ b/mars-server/pom.xml @@ -5,7 +5,7 @@ com.github.yuyenews Mars - 3.0.5 + 3.0.6 mars-server diff --git a/pom.xml b/pom.xml index e281da9..50b7f63 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.github.yuyenews Mars - 3.0.5 + 3.0.6 pom mars-core