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

com.pig4cloud.plugin.excel.ResponseExcelAutoConfiguration Maven / Gradle / Ivy

There is a newer version: 3.3.1
Show newest version
package com.pig4cloud.plugin.excel;

import com.pig4cloud.plugin.excel.aop.DynamicNameAspect;
import com.pig4cloud.plugin.excel.aop.ResponseExcelReturnValueHandler;
import com.pig4cloud.plugin.excel.config.ExcelConfigProperties;
import com.pig4cloud.plugin.excel.handler.SheetWriteHandler;
import com.pig4cloud.plugin.excel.processor.NameProcessor;
import com.pig4cloud.plugin.excel.processor.NameSpelExpressionProcessor;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lengleng
 * @date 2020/3/29
 * 

* 配置初始化 */ @Import(SheetWriteHandlerAutoConfiguration.class) @RequiredArgsConstructor @Configuration(proxyBeanMethods = false) @EnableConfigurationProperties(ExcelConfigProperties.class) public class ResponseExcelAutoConfiguration implements InitializingBean { private final RequestMappingHandlerAdapter handlerAdapter; private final List sheetWriteHandlerList; /** * SPEL 解析处理器 * @return NameProcessor excel名称解析器 */ @Bean @ConditionalOnMissingBean public NameProcessor nameProcessor() { return new NameSpelExpressionProcessor(); } /** * Excel名称解析处理切面 * @param nameProcessor SPEL 解析处理器 * @return DynamicNameAspect */ @Bean @ConditionalOnMissingBean public DynamicNameAspect dynamicNameAspect(NameProcessor nameProcessor) { return new DynamicNameAspect(nameProcessor); } @Override public void afterPropertiesSet() { List returnValueHandlers = handlerAdapter.getReturnValueHandlers(); List newHandlers = new ArrayList<>(); newHandlers.add(new ResponseExcelReturnValueHandler(sheetWriteHandlerList)); assert returnValueHandlers != null; newHandlers.addAll(returnValueHandlers); handlerAdapter.setReturnValueHandlers(newHandlers); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy