Commit 35159db3 authored by yanzg's avatar yanzg

设置打包时可以通过GIT查看源码

parent 178e8a4b
package com.yanzuoguang.util.helper;
import com.yanzuoguang.util.vo.ResponseResult;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
......@@ -21,8 +19,24 @@ public class TypeHelper {
*/
public static boolean isSubType(Type from, Class to) {
Class returnClass = getClass(from);
boolean isResponseResult = returnClass != null && returnClass.isAssignableFrom(ResponseResult.class);
return isResponseResult;
return isSubClass(returnClass, to);
}
/**
*  判断是否属于子类
*
* @param from
* @param to
* @return
*/
public static boolean isSubClass(Class from, Class to) {
if (from == null) {
return false;
}
if (from.isAssignableFrom(to)) {
return true;
}
return isSubClass(from.getSuperclass(), to);
}
/**
......@@ -40,4 +54,17 @@ public class TypeHelper {
}
return null;
}
/**
* 打印类型
*
* @param returnType
*/
public static void printSuperClass(Class<?> returnType) {
if (returnType == null) {
return;
}
System.out.println(returnType.getName());
printSuperClass(returnType.getSuperclass());
}
}
package helper;
import base.DemoVo;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.TypeHelper;
import com.yanzuoguang.util.vo.ResponseResult;
import helper.vo.ResponseDataMainResult;
import org.junit.Test;
import java.lang.reflect.Method;
import java.util.List;
public class TestTypeHelper {
public ResponseDataMainResult<List<DemoVo>, DemoVo> getReturnType() {
return null;
}
@Test
public void test() throws NoSuchMethodException {
// 获取泛型的返回值类型
Method method = TestTypeHelper.class.getMethod("getReturnType");
Class<?> returnType = method.getReturnType();
TypeHelper.printSuperClass(returnType);
boolean isSub = TypeHelper.isSubType(returnType, ResponseResult.class);
if (!isSub) {
throw new CodeException("泛型继承检测错误");
}
}
}
package helper.vo;
import com.yanzuoguang.util.vo.ResponseResult;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
* 评论结果查看结果
*
* @author 颜佐光
*/
@ApiModel(description = "评论结果查看结果")
public class ResponseDataMainResult<T extends Object, M extends Object> extends ResponseResult<T> {
/**
* 主表数据,在状态成功时有效
*/
@ApiModelProperty(
value = "主表数据",
notes = "主表数据,在状态成功时有效",
required = true
)
private M main;
public M getMain() {
return main;
}
public void setMain(M main) {
this.main = main;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment