All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.obatis.config.response.ResponseResultHandleFactory Maven / Gradle / Ivy

There is a newer version: 3.0.1-release
Show newest version
package com.obatis.config.response;

import com.google.common.collect.Lists;
import com.obatis.config.response.result.ResponseBodyWrapHandler;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
import org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor;

import java.util.List;

/**
 * 处理框架数据返回,进行结果封装
 * @author HuangLongPu
 */
public class ResponseResultHandleFactory {
	
	private ResponseResultHandleFactory() {}

    public static void handleResponseResultInfo(RequestMappingHandlerAdapter requestMappingHandlerAdapter) {
        List returnValueHandlers = requestMappingHandlerAdapter.getReturnValueHandlers();
        List handlerMethodReturnValueHandlers = Lists.newArrayList(returnValueHandlers);
        handlers(handlerMethodReturnValueHandlers);
        requestMappingHandlerAdapter.setReturnValueHandlers(handlerMethodReturnValueHandlers);
    }

    private static void handlers(List handlerMethodReturnValueHandlers) {
        for (HandlerMethodReturnValueHandler handlerMethodReturnValueHandler : handlerMethodReturnValueHandlers) {
            if (handlerMethodReturnValueHandler instanceof RequestResponseBodyMethodProcessor) {
                // 封装处理返回结果集
                ResponseBodyWrapHandler responseBodyWrapHandler = new ResponseBodyWrapHandler(handlerMethodReturnValueHandler);
                int index = handlerMethodReturnValueHandlers.indexOf(handlerMethodReturnValueHandler);
                handlerMethodReturnValueHandlers.set(index, responseBodyWrapHandler);
                break;
            }
        }
    }

}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy