mirror of
https://github.com/wahyd4/Martian.git
synced 2026-08-09 05:16:21 +10:00
update version
This commit is contained in:
@@ -11,4 +11,5 @@ import java.lang.annotation.Target;
|
||||
@Documented
|
||||
public @interface MarsApi {
|
||||
|
||||
String refBean() default "";
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public abstract class MarsConfig {
|
||||
|
||||
/**
|
||||
* jedis配置
|
||||
* @return edis配置
|
||||
* @return jedis配置
|
||||
*/
|
||||
public JedisConfig jedisConfig(){
|
||||
return new JedisConfig();
|
||||
|
||||
@@ -37,6 +37,7 @@ public class LogAop {
|
||||
JSONObject param = JSONObject.parseObject(JSON.toJSONString(obj));
|
||||
jsonObject.putAll(param);
|
||||
}
|
||||
params = jsonObject.toJSONString();
|
||||
}
|
||||
|
||||
StringBuffer buffer = getLogInfo("开始执行","参数",params);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.mars.mvc.proxy;
|
||||
|
||||
import com.mars.core.annotation.MarsApi;
|
||||
import com.mars.core.annotation.MarsReference;
|
||||
import com.mars.core.annotation.enums.RefType;
|
||||
import com.mars.core.load.LoadHelper;
|
||||
@@ -22,24 +23,26 @@ public class ExecuteRef {
|
||||
|
||||
/**
|
||||
* 指定服务层的方法
|
||||
* @param controlCls 被代理的类
|
||||
* @param method 方法
|
||||
* @param args 参数
|
||||
* @return 返回值
|
||||
* @throws Exception 异常
|
||||
*/
|
||||
protected static Object executeRef(Method method, Object[] args) throws Exception {
|
||||
protected static Object executeRef(Class<?> controlCls, Method method, Object[] args) throws Exception {
|
||||
/* 根据注解获取到对应的bean对象实体 */
|
||||
MarsReference marsReference = method.getAnnotation(MarsReference.class);
|
||||
MarsApi marsApi = controlCls.getAnnotation(MarsApi.class);
|
||||
|
||||
/* 获取bean对象的class和实例 */
|
||||
MarsBeanModel marsBeanModel = getMarsBeanModel(marsReference);
|
||||
MarsBeanModel marsBeanModel = getMarsBeanModel(marsReference,marsApi);
|
||||
Class<?> cls = marsBeanModel.getCls();
|
||||
Object obj = marsBeanModel.getObj();
|
||||
|
||||
/* 获取引用的资源名称 */
|
||||
String refName = getRefName(method,marsReference);
|
||||
|
||||
if(marsReference.refType().equals(RefType.METHOD)){
|
||||
if(marsReference == null || marsReference.refType().equals(RefType.METHOD)){
|
||||
/* 如果引用的是一个方法则执行bean里面对应的方法 */
|
||||
Object result = executeRefMethod(cls,obj,args,refName);
|
||||
if(result != null && result.equals("errorRef")){
|
||||
@@ -60,17 +63,25 @@ public class ExecuteRef {
|
||||
/**
|
||||
* 获取要执行的bean对象
|
||||
* @param marsReference 引用注解
|
||||
* @param marsApi api注解
|
||||
* @return bean对象实体类
|
||||
* @throws Exception 异常
|
||||
*/
|
||||
private static MarsBeanModel getMarsBeanModel(MarsReference marsReference) throws Exception {
|
||||
if(marsReference == null || StringUtil.isNull(marsReference.beanName())){
|
||||
throw new Exception("没有配置MarsReference注解或者配置不正确");
|
||||
private static MarsBeanModel getMarsBeanModel(MarsReference marsReference, MarsApi marsApi) throws Exception {
|
||||
String beanName = null;
|
||||
if(marsReference != null && !StringUtil.isNull(marsReference.beanName())){
|
||||
beanName = marsReference.beanName();
|
||||
} else if(marsApi != null || !StringUtil.isNull(marsApi.refBean())){
|
||||
beanName = marsApi.refBean();
|
||||
}
|
||||
|
||||
MarsBeanModel marsBeanModel = beanModelMap.get(marsReference.beanName());
|
||||
if(StringUtil.isNull(beanName)){
|
||||
throw new Exception("请检查您的MarsReference注解或者MarsApi注解是否有指定要引用的bean名称");
|
||||
}
|
||||
|
||||
MarsBeanModel marsBeanModel = beanModelMap.get(beanName);
|
||||
if(marsBeanModel == null){
|
||||
throw new Exception("没有找到name为["+marsReference.beanName()+"]的MarsBean");
|
||||
throw new Exception("没有找到name为["+beanName+"]的MarsBean");
|
||||
}
|
||||
return marsBeanModel;
|
||||
}
|
||||
@@ -104,10 +115,9 @@ public class ExecuteRef {
|
||||
* @return
|
||||
*/
|
||||
private static String getRefName(Method method,MarsReference marsReference){
|
||||
String refName = marsReference.refName();
|
||||
if(StringUtil.isNull(refName)){
|
||||
if(marsReference == null || StringUtil.isNull(marsReference.refName())){
|
||||
return method.getName();
|
||||
}
|
||||
return refName;
|
||||
return marsReference.refName();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class MvcCglibProxy implements MethodInterceptor {
|
||||
}
|
||||
|
||||
try{
|
||||
Object o1 = ExecuteRef.executeRef(method,args);
|
||||
Object o1 = ExecuteRef.executeRef(cls,method,args);
|
||||
|
||||
if(c != null){
|
||||
c.endMethod(args,o1);
|
||||
|
||||
@@ -56,12 +56,12 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat.embed</groupId>
|
||||
<artifactId>tomcat-embed-core</artifactId>
|
||||
<version>8.5.49</version>
|
||||
<version>8.5.50</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat</groupId>
|
||||
<artifactId>tomcat-servlet-api</artifactId>
|
||||
<version>8.5.49</version>
|
||||
<version>8.5.50</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
Reference in New Issue
Block a user