工具类系列-RequestRedirectUtil
来源:互联网 发布:mac怎么下photoshop 编辑:程序博客网 时间:2024/05/22 15:03
public static ResponseVo redirect(Class<?> controllerClazz, String methodName, Object arg) {
if (controllerClazz == null || StringUtils.isBlank(methodName)) {throw new IllegalArgumentException("Argument invalid ...");
}
Method machedMethod = searchMachedMethod(controllerClazz, methodName);
return doRedirect(controllerClazz, machedMethod, arg);
}
/**
* 根据方法名查找第一个匹配的方法对象
* @param controllerClazz
* @param methodName
* @return
*/
private static Method searchMachedMethod(Class<?> controllerClazz, String methodName) {
Method[] methods = controllerClazz.getDeclaredMethods();
if (ArrayUtils.isEmpty(methods)) {
throw new NullPointerException("No method found by: " + methodName);
}
for (Method method : methods) {
if (StringUtils.equals(methodName, method.getName())) {
return method;
}
}
throw new RuntimeException("No mached method found by: " + methodName);
}
private static ResponseVo doRedirect(Class<?> controllerClazz, Method method, Object argObject) {
RequestMapping clazzMapping = controllerClazz.getAnnotation(RequestMapping.class);
RequestMapping methodMapping = method.getAnnotation(RequestMapping.class);
if (clazzMapping == null || methodMapping == null) {
throw new NullPointerException("No @RequestMapping defined for class: " + controllerClazz + " or method: " + method);
}
String qualifiedUrl = new StringBuilder(baseUrl)
.append(clazzMapping.value()[0]).append(methodMapping.value()[0]).toString();
// choose the 1st RequestMethod definition if more than 1 exists
String requestMethod = methodMapping.method()[0].name();
String param = JsonUtil.toString(argObject);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("----- redirect 2 TOF via url: " + qualifiedUrl + ", method: " + requestMethod + ", param: " + param);
}
String returnStr =XXX;//请求
return JsonUtil.toBean(returnStr, ResponseVo.class);
}
- 工具类系列-RequestRedirectUtil
- 工具类系列-JavaBean2Map
- 工具类系列-ClazzReflectUtil
- 工具类系列-GenerateHtml
- 工具类系列-JackJsonStringTrimParser
- 工具类系列-DataFilterQueue
- 工具类系列-StringSimpleRedisUtil
- apache工具类系列
- Android工具类系列-BitmapUtil
- Android工具类系列-ToastUtil
- Android工具类系列-LogUtil
- Android工具类系列-SDCardUtil
- Android工具类系列-KeyBoardUtil
- Android工具类系列-NetUtil
- Android工具类系列-HttpUtil
- Android工具类系列-AppUtil
- Android工具类系列-ScreenUtil
- Android工具类系列-SPUtil(SharedPreferences工具类)
- liunx 安装配置JDK和配置环境变量
- HDU1003 Max Sum(最大连续子序和、贪心、DP)
- Python实现欧拉计划27题
- 在SuperMap DeskPro 6R(2012)中如何批量重新指定数据源?
- 矩阵快速幂
- 工具类系列-RequestRedirectUtil
- Java基础知识: 数组和函数
- Zookeeper集群安装
- JSON数据处理及与echarts结合使用时所需要的问题
- 使用XML布局文件和java代码共同控制UI界面做一个简易图片浏览器
- 使用hibernate获取自增主键的id值
- SSH框架开发流程步骤
- 第十三周--形状类族的中的纯虚函数
- 泛型委托Action与func