欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Springboot獲取文件內(nèi)容如何將MultipartFile轉(zhuǎn)File

 更新時(shí)間:2024年01月08日 16:42:28   作者:Alex_81D  
本文給大家介紹Springboot獲取文件內(nèi)容,將MultipartFile轉(zhuǎn)File方法,本文結(jié)合示例代碼給大家介紹的非常詳細(xì),感興趣的朋友一起看看吧

文件上傳以前是噩夢(mèng)一樣的存在,覺得很少麻煩,后來仔細(xì)研究后發(fā)現(xiàn)通過前端傳文件去調(diào)取后端接口并不是特別復(fù)雜,接下來我詳細(xì)說一下通過接口的方式接收前端傳過來的文件,并且解析文件中內(nèi)容的方法

話不多說,開整代碼

@RestController
@RequestMapping("/api/invoice")
public class InvoiceController {
    private static Logger logger = LoggerUtil.getLogger();
    @Autowired
    private InvoiceService invoiceService;
    @RequestMapping(value = "/getInvoiceInfo", method = RequestMethod.POST)
    @ResponseBody
    private String getInvoiceInfo(@RequestParam("file") MultipartFile file) {
        logger.info("/getInvoiceInfo接口調(diào)用");
        return invoiceService.getInvoiceInfo(file);
    }
}

剩下的寫業(yè)務(wù)層,就不多謝業(yè)務(wù)了,主要寫一下怎么轉(zhuǎn)換并獲取內(nèi)容

/**
 * 將MultipartFile轉(zhuǎn)換為File
 * @param multiFile
 * @return
 */
public File multipartFileToFile(MultipartFile multiFile) {
    // 獲取文件名
    String fileName = multiFile.getOriginalFilename();
    // 獲取文件后綴(.xml)
    String suffix = fileName.substring(fileName.lastIndexOf("."));
    // 若要防止生成的臨時(shí)文件重復(fù),需要在文件名后添加隨機(jī)碼
    try {
        //"tmp", ".txt"
        //fileName這塊可以根據(jù)自己的業(yè)務(wù)需求進(jìn)行修改,我這里沒有做任何處理
        File file = File.createTempFile(fileName, suffix);
        multiFile.transferTo(file);
        return file;
    } catch (Exception e) {
        logger.error("MultipartFile轉(zhuǎn)File失敗",e);
    }
    return null;
}
//在業(yè)務(wù)側(cè)寫代碼時(shí)記得處理掉這個(gè)臨時(shí)文件
if (file!=null){
    file.deleteOnExit();
}

以上代碼就是將MultipartFile轉(zhuǎn)換為File的相關(guān)代碼

再說說怎么把txt文件內(nèi)容和excel讀取出來處理

上代碼:讀取txt

@RequestMapping(value = "/uploadFileTxt", method = RequestMethod.POST)
@ResponseBody
private AjaxResult uploadFileTxt(@RequestParam("file") MultipartFile file) throws Exception {
    System.out.println("uploadFileTxt");
    telephoneService.uploadFileTxt(file);
    return AjaxResult.success();
}
@Override
public void uploadFileTxt(MultipartFile txtFile) {
    Set<String> txtFileSet = new HashSet<>();
    String fileName = txtFile.getOriginalFilename();
    try {
        txtFileSet = uploadRtnMap(txtFile);
    }catch (IOException e){
        e.printStackTrace();
    }
    //業(yè)務(wù)代碼
    //remove(new QueryWrapper<>());
//     txtMapper.deleteTxtdata();
//    for(String txt:txtFileSet){
//         TxtVO txtVO = new TxtVO();
//         txtVO.setTelephone(txt);
//         txtVO.setFilename(fileName);
//         txtVO.setCreateTime(new Date());
//         save(txtVO);
//     }
}
public static Set<String> uploadRtnMap(MultipartFile file) throws IOException {
    InputStream is = null;
    InputStreamReader isReader = null;
    BufferedReader br = null;
    Set<String> phoneList = new HashSet<String>();
    try {
        is = file.getInputStream();
        isReader = new InputStreamReader(is, StandardCharsets.UTF_8);
        br = new BufferedReader(isReader);
        //循環(huán)逐行讀取
        String str;
        while ((str = br.readLine()) != null) {
            System.out.println(str);
            phoneList.add(str);
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (is != null) {
            is.close();
        }
        if (isReader != null) {
            isReader.close();
        }
        if (br != null) {
            br.close();
        }
    }
    return phoneList;
}

讀取excel

@Override
public void uploadFileExcel(MultipartFile excelFile) {
    ExcelUtil<ExcelVO> util = new ExcelUtil<ExcelVO>(ExcelVO.class);
    List<ExcelVO> excelList = new ArrayList<>();
    try{
        //excel里面的內(nèi)容
        excelList = util.importExcel(excelFile.getInputStream());
    } catch (Exception e) {
        e.printStackTrace();
    }
 // 業(yè)務(wù)
 // excelService.saveExcel(excelList);
}

提供幾個(gè)工具類給大家

ExcelVO對(duì)象

@Data
@TableName("exceldata")
public class ExcelVO {
    //id
    @TableId(type= IdType.AUTO)
    private String id;
    //手機(jī)號(hào)
    @Excel(name = "手機(jī)號(hào)")
    private String telephone;
    //QQ號(hào)
    @Excel(name = "QQ號(hào)")
    private String qq;
    //創(chuàng)建時(shí)間
    private Date createTime;
}

ExcelUtil.java工具類

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.RegExUtils;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.util.IOUtils;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.*;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
/**
 * Excel相關(guān)處理
 */
public class ExcelUtil<T>
{
    private static final Logger log = LoggerFactory.getLogger(ExcelUtil.class);
    public static final String FORMULA_REGEX_STR = "=|-|\\+|@";
    public static final String[] FORMULA_STR = { "=", "-", "+", "@" };
    /**
     * Excel sheet最大行數(shù),默認(rèn)65536
     */
    public static final int sheetSize = 65536;
    /**
     * 工作表名稱
     */
    private String sheetName;
    /**
     * 導(dǎo)出類型(EXPORT:導(dǎo)出數(shù)據(jù);IMPORT:導(dǎo)入模板)
     */
    private Type type;
    /**
     * 工作薄對(duì)象
     */
    private Workbook wb;
    /**
     * 工作表對(duì)象
     */
    private Sheet sheet;
    /**
     * 樣式列表
     */
    private Map<String, CellStyle> styles;
    /**
     * 導(dǎo)入導(dǎo)出數(shù)據(jù)列表
     */
    private List<T> list;
    /**
     * 注解列表
     */
    private List<Object[]> fields;
    /**
     * 當(dāng)前行號(hào)
     */
    private int rownum;
    /**
     * 標(biāo)題
     */
    private String title;
    /**
     * 最大高度
     */
    private short maxHeight;
    /**
     * 統(tǒng)計(jì)列表
     */
    private Map<Integer, Double> statistics = new HashMap<Integer, Double>();
    /**
     * 數(shù)字格式
     */
    private static final DecimalFormat DOUBLE_FORMAT = new DecimalFormat("######0.00");
    /**
     * 實(shí)體對(duì)象
     */
    public Class<T> clazz;
    /**
     * 需要排除列屬性
     */
    public String[] excludeFields;
    public ExcelUtil(Class<T> clazz)
    {
        this.clazz = clazz;
    }
    /**
     * 隱藏Excel中列屬性
     *
     * @param fields 列屬性名 示例[單個(gè)"name"/多個(gè)"id","name"]
     * @throws Exception
     */
    public void hideColumn(String... fields)
    {
        this.excludeFields = fields;
    }
    public void init(List<T> list, String sheetName, String title, Type type)
    {
        if (list == null)
        {
            list = new ArrayList<T>();
        }
        this.list = list;
        this.sheetName = sheetName;
        this.type = type;
        this.title = title;
        createExcelField();
        createWorkbook();
        createTitle();
    }
    /**
     * 創(chuàng)建excel第一行標(biāo)題
     */
    public void createTitle()
    {
        if (StringUtils.isNotEmpty(title))
        {
            Row titleRow = sheet.createRow(rownum == 0 ? rownum++ : 0);
            titleRow.setHeightInPoints(30);
            Cell titleCell = titleRow.createCell(0);
            titleCell.setCellStyle(styles.get("title"));
            titleCell.setCellValue(title);
            sheet.addMergedRegion(new CellRangeAddress(titleRow.getRowNum(), titleRow.getRowNum(), titleRow.getRowNum(),
                    this.fields.size() - 1));
        }
    }
    /**
     * 對(duì)excel表單默認(rèn)第一個(gè)索引名轉(zhuǎn)換成list
     * 
     * @param is 輸入流
     * @return 轉(zhuǎn)換后集合
     */
    public List<T> importExcel(InputStream is) throws Exception
    {
        return importExcel(is, 0);
    }
    /**
     * 對(duì)excel表單默認(rèn)第一個(gè)索引名轉(zhuǎn)換成list
     * 
     * @param is 輸入流
     * @param titleNum 標(biāo)題占用行數(shù)
     * @return 轉(zhuǎn)換后集合
     */
    public List<T> importExcel(InputStream is, int titleNum) throws Exception
    {
        return importExcel(StringUtils.EMPTY, is, titleNum);
    }
    /**
     * 對(duì)excel表單指定表格索引名轉(zhuǎn)換成list
     * 
     * @param sheetName 表格索引名
     * @param titleNum 標(biāo)題占用行數(shù)
     * @param is 輸入流
     * @return 轉(zhuǎn)換后集合
     */
    public List<T> importExcel(String sheetName, InputStream is, int titleNum) throws Exception
    {
        this.type = Excel.Type.IMPORT;
        this.wb = WorkbookFactory.create(is);
        List<T> list = new ArrayList<T>();
        // 如果指定sheet名,則取指定sheet中的內(nèi)容 否則默認(rèn)指向第1個(gè)sheet
        Sheet sheet = StringUtils.isNotEmpty(sheetName) ? wb.getSheet(sheetName) : wb.getSheetAt(0);
        if (sheet == null)
        {
            throw new IOException("文件sheet不存在");
        }
        boolean isXSSFWorkbook = !(wb instanceof HSSFWorkbook);
        Map<String, PictureData> pictures;
        if (isXSSFWorkbook)
        {
            pictures = getSheetPictures07((XSSFSheet) sheet, (XSSFWorkbook) wb);
        }
        else
        {
            pictures = getSheetPictures03((HSSFSheet) sheet, (HSSFWorkbook) wb);
        }
        // 獲取最后一個(gè)非空行的行下標(biāo),比如總行數(shù)為n,則返回的為n-1
        int rows = sheet.getLastRowNum();
        if (rows > 0)
        {
            // 定義一個(gè)map用于存放excel列的序號(hào)和field.
            Map<String, Integer> cellMap = new HashMap<String, Integer>();
            // 獲取表頭
            Row heard = sheet.getRow(titleNum);
            for (int i = 0; i < heard.getPhysicalNumberOfCells(); i++)
            {
                Cell cell = heard.getCell(i);
                if (StringUtils.isNotNull(cell))
                {
                    String value = this.getCellValue(heard, i).toString();
                    cellMap.put(value, i);
                }
                else
                {
                    cellMap.put(null, i);
                }
            }
            // 有數(shù)據(jù)時(shí)才處理 得到類的所有field.
            List<Object[]> fields = this.getFields();
            Map<Integer, Object[]> fieldsMap = new HashMap<Integer, Object[]>();
            for (Object[] objects : fields)
            {
                Excel attr = (Excel) objects[1];
                Integer column = cellMap.get(attr.name());
                if (column != null)
                {
                    fieldsMap.put(column, objects);
                }
            }
            for (int i = titleNum + 1; i <= rows; i++)
            {
                // 從第2行開始取數(shù)據(jù),默認(rèn)第一行是表頭.
                Row row = sheet.getRow(i);
                // 判斷當(dāng)前行是否是空行
                if (isRowEmpty(row))
                {
                    continue;
                }
                T entity = null;
                for (Map.Entry<Integer, Object[]> entry : fieldsMap.entrySet())
                {
                    Object val = this.getCellValue(row, entry.getKey());
                    // 如果不存在實(shí)例則新建.
                    entity = (entity == null ? clazz.newInstance() : entity);
                    // 從map中得到對(duì)應(yīng)列的field.
                    Field field = (Field) entry.getValue()[0];
                    Excel attr = (Excel) entry.getValue()[1];
                    // 取得類型,并根據(jù)對(duì)象類型設(shè)置值.
                    Class<?> fieldType = field.getType();
                    if (String.class == fieldType)
                    {
                        String s = Convert.toStr(val);
                        if (StringUtils.endsWith(s, ".0"))
                        {
                            val = StringUtils.substringBefore(s, ".0");
                        }
                        else
                        {
                            String dateFormat = field.getAnnotation(Excel.class).dateFormat();
                            if (StringUtils.isNotEmpty(dateFormat))
                            {
                                val = parseDateToStr(dateFormat, val);
                            }
                            else
                            {
                                val = Convert.toStr(val);
                            }
                        }
                    }
                    else if ((Integer.TYPE == fieldType || Integer.class == fieldType) && StringUtils.isNumeric(Convert.toStr(val)))
                    {
                        val = Convert.toInt(val);
                    }
                    else if ((Long.TYPE == fieldType || Long.class == fieldType) && StringUtils.isNumeric(Convert.toStr(val)))
                    {
                        val = Convert.toLong(val);
                    }
                    else if (Double.TYPE == fieldType || Double.class == fieldType)
                    {
                        val = Convert.toDouble(val);
                    }
                    else if (Float.TYPE == fieldType || Float.class == fieldType)
                    {
                        val = Convert.toFloat(val);
                    }
                    else if (BigDecimal.class == fieldType)
                    {
                        val = Convert.toBigDecimal(val);
                    }
                    else if (Date.class == fieldType)
                    {
                        if (val instanceof String)
                        {
                            val = DateUtils.parseDate(val);
                        }
                        else if (val instanceof Double)
                        {
                            val = DateUtil.getJavaDate((Double) val);
                        }
                    }
                    else if (Boolean.TYPE == fieldType || Boolean.class == fieldType)
                    {
                        val = Convert.toBool(val, false);
                    }
                    if (StringUtils.isNotNull(fieldType))
                    {
                        String propertyName = field.getName();
                        if (StringUtils.isNotEmpty(attr.targetAttr()))
                        {
                            propertyName = field.getName() + "." + attr.targetAttr();
                        }
                        else if (StringUtils.isNotEmpty(attr.readConverterExp()))
                        {
                            val = reverseByExp(Convert.toStr(val), attr.readConverterExp(), attr.separator());
                        }
                        /*else if (StringUtils.isNotEmpty(attr.dictType()))
                        {
                            val = reverseDictByExp(Convert.toStr(val), attr.dictType(), attr.separator());
                        }*/
                        else if (!attr.handler().equals(ExcelHandlerAdapter.class))
                        {
                            val = dataFormatHandlerAdapter(val, attr);
                        }
                        else if (ColumnType.IMAGE == attr.cellType() && StringUtils.isNotEmpty(pictures))
                        {
                            PictureData image = pictures.get(row.getRowNum() + "_" + entry.getKey());
                            if (image == null)
                            {
                                val = "";
                            }
                            else
                            {
                                byte[] data = image.getData();
                                //val = FileUtils.writeImportBytes(data);
                            }
                        }
                        ReflectUtils.invokeSetter(entity, propertyName, val);
                    }
                }
                list.add(entity);
            }
        }
        return list;
    }
    /**
     * 對(duì)list數(shù)據(jù)源將其里面的數(shù)據(jù)導(dǎo)入到excel表單
     * 
     * @param list 導(dǎo)出數(shù)據(jù)集合
     * @param sheetName 工作表的名稱
     * @return 結(jié)果
     */
    public AjaxResult exportExcel(List<T> list, String sheetName)
    {
        return exportExcel(list, sheetName, StringUtils.EMPTY);
    }
    /**
     * 對(duì)list數(shù)據(jù)源將其里面的數(shù)據(jù)導(dǎo)入到excel表單
     * 
     * @param list 導(dǎo)出數(shù)據(jù)集合
     * @param sheetName 工作表的名稱
     * @param title 標(biāo)題
     * @return 結(jié)果
     */
    public AjaxResult exportExcel(List<T> list, String sheetName, String title)
    {
        this.init(list, sheetName, title, Type.EXPORT);
        return exportExcel();
    }
    /**
     * 對(duì)list數(shù)據(jù)源將其里面的數(shù)據(jù)導(dǎo)入到excel表單
     * 
     * @param response 返回?cái)?shù)據(jù)
     * @param list 導(dǎo)出數(shù)據(jù)集合
     * @param sheetName 工作表的名稱
     * @return 結(jié)果
     */
    public void exportExcel(HttpServletResponse response, List<T> list, String sheetName)
    {
        exportExcel(response, list, sheetName, StringUtils.EMPTY);
    }
    /**
     * 對(duì)list數(shù)據(jù)源將其里面的數(shù)據(jù)導(dǎo)入到excel表單
     * 
     * @param response 返回?cái)?shù)據(jù)
     * @param list 導(dǎo)出數(shù)據(jù)集合
     * @param sheetName 工作表的名稱
     * @param title 標(biāo)題
     * @return 結(jié)果
     */
    public void exportExcel(HttpServletResponse response, List<T> list, String sheetName, String title)
    {
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        this.init(list, sheetName, title, Type.EXPORT);
        exportExcel(response);
    }
    /**
     * 對(duì)list數(shù)據(jù)源將其里面的數(shù)據(jù)導(dǎo)入到excel表單
     * 
     * @param sheetName 工作表的名稱
     * @return 結(jié)果
     */
    public AjaxResult importTemplateExcel(String sheetName)
    {
        return importTemplateExcel(sheetName, StringUtils.EMPTY);
    }
    /**
     * 對(duì)list數(shù)據(jù)源將其里面的數(shù)據(jù)導(dǎo)入到excel表單
     * 
     * @param sheetName 工作表的名稱
     * @param title 標(biāo)題
     * @return 結(jié)果
     */
    public AjaxResult importTemplateExcel(String sheetName, String title)
    {
        this.init(null, sheetName, title, Type.IMPORT);
        return exportExcel();
    }
    /**
     * 對(duì)list數(shù)據(jù)源將其里面的數(shù)據(jù)導(dǎo)入到excel表單
     * 
     * @param sheetName 工作表的名稱
     * @return 結(jié)果
     */
    public void importTemplateExcel(HttpServletResponse response, String sheetName)
    {
        importTemplateExcel(response, sheetName, StringUtils.EMPTY);
    }
    /**
     * 對(duì)list數(shù)據(jù)源將其里面的數(shù)據(jù)導(dǎo)入到excel表單
     * 
     * @param sheetName 工作表的名稱
     * @param title 標(biāo)題
     * @return 結(jié)果
     */
    public void importTemplateExcel(HttpServletResponse response, String sheetName, String title)
    {
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        this.init(null, sheetName, title, Type.IMPORT);
        exportExcel(response);
    }
    /**
     * 對(duì)list數(shù)據(jù)源將其里面的數(shù)據(jù)導(dǎo)入到excel表單
     * 
     * @return 結(jié)果
     */
    public void exportExcel(HttpServletResponse response)
    {
        try
        {
            writeSheet();
            wb.write(response.getOutputStream());
        }
        catch (Exception e)
        {
            log.error("導(dǎo)出Excel異常{}", e.getMessage());
        }
        finally
        {
            IOUtils.closeQuietly(wb);
        }
    }
    /**
     * 對(duì)list數(shù)據(jù)源將其里面的數(shù)據(jù)導(dǎo)入到excel表單
     * 
     * @return 結(jié)果
     */
    public AjaxResult exportExcel()
    {
        OutputStream out = null;
        try
        {
            writeSheet();
            String filename = encodingFilename(sheetName);
            out = new FileOutputStream(getAbsoluteFile(filename));
            wb.write(out);
            return AjaxResult.success(filename);
        }
        catch (Exception e)
        {
            log.error("導(dǎo)出Excel異常{}", e.getMessage());
            //throw new UtilException("導(dǎo)出Excel失敗,請(qǐng)聯(lián)系網(wǎng)站管理員!");
            AjaxResult.success("導(dǎo)出Excel失敗,請(qǐng)聯(lián)系網(wǎng)站管理員!");
        }
        finally
        {
            IOUtils.closeQuietly(wb);
            IOUtils.closeQuietly(out);
            return  AjaxResult.success("導(dǎo)出Excel失敗,請(qǐng)聯(lián)系網(wǎng)站管理員!");
        }
    }
    /**
     * 創(chuàng)建寫入數(shù)據(jù)到Sheet
     */
    public void writeSheet()
    {
        // 取出一共有多少個(gè)sheet.
        int sheetNo = Math.max(1, (int) Math.ceil(list.size() * 1.0 / sheetSize));
        for (int index = 0; index < sheetNo; index++)
        {
            createSheet(sheetNo, index);
            // 產(chǎn)生一行
            Row row = sheet.createRow(rownum);
            int column = 0;
            // 寫入各個(gè)字段的列頭名稱
            for (Object[] os : fields)
            {
                Excel excel = (Excel) os[1];
                this.createCell(excel, row, column++);
            }
            if (Type.EXPORT.equals(type))
            {
                fillExcelData(index, row);
                addStatisticsRow();
            }
        }
    }
    /**
     * 填充excel數(shù)據(jù)
     * 
     * @param index 序號(hào)
     * @param row 單元格行
     */
    public void fillExcelData(int index, Row row)
    {
        int startNo = index * sheetSize;
        int endNo = Math.min(startNo + sheetSize, list.size());
        for (int i = startNo; i < endNo; i++)
        {
            row = sheet.createRow(i + 1 + rownum - startNo);
            // 得到導(dǎo)出對(duì)象.
            T vo = (T) list.get(i);
            int column = 0;
            for (Object[] os : fields)
            {
                Field field = (Field) os[0];
                Excel excel = (Excel) os[1];
                this.addCell(excel, row, vo, field, column++);
            }
        }
    }
    /**
     * 創(chuàng)建表格樣式
     * 
     * @param wb 工作薄對(duì)象
     * @return 樣式列表
     */
    private Map<String, CellStyle> createStyles(Workbook wb)
    {
        // 寫入各條記錄,每條記錄對(duì)應(yīng)excel表中的一行
        Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
        CellStyle style = wb.createCellStyle();
        style.setAlignment(HorizontalAlignment.CENTER);
        style.setVerticalAlignment(VerticalAlignment.CENTER);
        Font titleFont = wb.createFont();
        titleFont.setFontName("Arial");
        titleFont.setFontHeightInPoints((short) 16);
        titleFont.setBold(true);
        style.setFont(titleFont);
        styles.put("title", style);
        style = wb.createCellStyle();
        style.setAlignment(HorizontalAlignment.CENTER);
        style.setVerticalAlignment(VerticalAlignment.CENTER);
        style.setBorderRight(BorderStyle.THIN);
        style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
        style.setBorderLeft(BorderStyle.THIN);
        style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
        style.setBorderTop(BorderStyle.THIN);
        style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
        style.setBorderBottom(BorderStyle.THIN);
        style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
        Font dataFont = wb.createFont();
        dataFont.setFontName("Arial");
        dataFont.setFontHeightInPoints((short) 10);
        style.setFont(dataFont);
        styles.put("data", style);
        style = wb.createCellStyle();
        style.setAlignment(HorizontalAlignment.CENTER);
        style.setVerticalAlignment(VerticalAlignment.CENTER);
        Font totalFont = wb.createFont();
        totalFont.setFontName("Arial");
        totalFont.setFontHeightInPoints((short) 10);
        style.setFont(totalFont);
        styles.put("total", style);
        styles.putAll(annotationHeaderStyles(wb, styles));
        styles.putAll(annotationDataStyles(wb));
        return styles;
    }
    /**
     * 根據(jù)Excel注解創(chuàng)建表格頭樣式
     * 
     * @param wb 工作薄對(duì)象
     * @return 自定義樣式列表
     */
    private Map<String, CellStyle> annotationHeaderStyles(Workbook wb, Map<String, CellStyle> styles)
    {
        Map<String, CellStyle> headerStyles = new HashMap<String, CellStyle>();
        for (Object[] os : fields)
        {
            Excel excel = (Excel) os[1];
            String key = StringUtils.format("header_{}_{}", excel.headerColor(), excel.headerBackgroundColor());
            if (!headerStyles.containsKey(key))
            {
                CellStyle style = wb.createCellStyle();
                style = wb.createCellStyle();
                style.cloneStyleFrom(styles.get("data"));
                style.setAlignment(HorizontalAlignment.CENTER);
                style.setVerticalAlignment(VerticalAlignment.CENTER);
                style.setFillForegroundColor(excel.headerBackgroundColor().index);
                style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
                Font headerFont = wb.createFont();
                headerFont.setFontName("Arial");
                headerFont.setFontHeightInPoints((short) 10);
                headerFont.setBold(true);
                headerFont.setColor(excel.headerColor().index);
                style.setFont(headerFont);
                headerStyles.put(key, style);
            }
        }
        return headerStyles;
    }
    /**
     * 根據(jù)Excel注解創(chuàng)建表格列樣式
     * 
     * @param wb 工作薄對(duì)象
     * @return 自定義樣式列表
     */
    private Map<String, CellStyle> annotationDataStyles(Workbook wb)
    {
        Map<String, CellStyle> styles = new HashMap<String, CellStyle>();
        for (Object[] os : fields)
        {
            Excel excel = (Excel) os[1];
            String key = StringUtils.format("data_{}_{}_{}", excel.align(), excel.color(), excel.backgroundColor());
            if (!styles.containsKey(key))
            {
                CellStyle style = wb.createCellStyle();
                style = wb.createCellStyle();
                style.setAlignment(excel.align());
                style.setVerticalAlignment(VerticalAlignment.CENTER);
                style.setBorderRight(BorderStyle.THIN);
                style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
                style.setBorderLeft(BorderStyle.THIN);
                style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
                style.setBorderTop(BorderStyle.THIN);
                style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
                style.setBorderBottom(BorderStyle.THIN);
                style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
                style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
                style.setFillForegroundColor(excel.backgroundColor().getIndex());
                Font dataFont = wb.createFont();
                dataFont.setFontName("Arial");
                dataFont.setFontHeightInPoints((short) 10);
                dataFont.setColor(excel.color().index);
                style.setFont(dataFont);
                styles.put(key, style);
            }
        }
        return styles;
    }
    /**
     * 創(chuàng)建單元格
     */
    public Cell createCell(Excel attr, Row row, int column)
    {
        // 創(chuàng)建列
        Cell cell = row.createCell(column);
        // 寫入列信息
        cell.setCellValue(attr.name());
        setDataValidation(attr, row, column);
        cell.setCellStyle(styles.get(StringUtils.format("header_{}_{}", attr.headerColor(), attr.headerBackgroundColor())));
        return cell;
    }
    /**
     * 設(shè)置單元格信息
     * 
     * @param value 單元格值
     * @param attr 注解相關(guān)
     * @param cell 單元格信息
     */
    public void setCellVo(Object value, Excel attr, Cell cell)
    {
        if (Excel.ColumnType.STRING == attr.cellType())
        {
            String cellValue = Convert.toStr(value);
            // 對(duì)于任何以表達(dá)式觸發(fā)字符 =-+@開頭的單元格,直接使用tab字符作為前綴,防止CSV注入。
            if (StringUtils.startsWithAny(cellValue, FORMULA_STR))
            {
                cellValue = RegExUtils.replaceFirst(cellValue, FORMULA_REGEX_STR, "\t$0");
            }
            cell.setCellValue(StringUtils.isNull(cellValue) ? attr.defaultValue() : cellValue + attr.suffix());
        }
        else if (Excel.ColumnType.NUMERIC == attr.cellType())
        {
            if (StringUtils.isNotNull(value))
            {
                cell.setCellValue(StringUtils.contains(Convert.toStr(value), ".") ? Convert.toDouble(value) : Convert.toInt(value));
            }
        }
        /*else if (Excel.ColumnType.IMAGE == attr.cellType())
        {
            ClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1), cell.getRow().getRowNum() + 1);
            String imagePath = Convert.toStr(value);
            if (StringUtils.isNotEmpty(imagePath))
            {
                byte[] data = ImageUtils.getImage(imagePath);
                getDrawingPatriarch(cell.getSheet()).createPicture(anchor,
                        cell.getSheet().getWorkbook().addPicture(data, getImageType(data)));
            }
        }*/
    }
    /**
     * 獲取畫布
     */
    public static Drawing<?> getDrawingPatriarch(Sheet sheet)
    {
        if (sheet.getDrawingPatriarch() == null)
        {
            sheet.createDrawingPatriarch();
        }
        return sheet.getDrawingPatriarch();
    }
    /**
     * 獲取圖片類型,設(shè)置圖片插入類型
     */
    /*public int getImageType(byte[] value)
    {
        String type = FileTypeUtils.getFileExtendName(value);
        if ("JPG".equalsIgnoreCase(type))
        {
            return Workbook.PICTURE_TYPE_JPEG;
        }
        else if ("PNG".equalsIgnoreCase(type))
        {
            return Workbook.PICTURE_TYPE_PNG;
        }
        return Workbook.PICTURE_TYPE_JPEG;
    }*/
    /**
     * 創(chuàng)建表格樣式
     */
    public void setDataValidation(Excel attr, Row row, int column)
    {
        if (attr.name().indexOf("注:") >= 0)
        {
            sheet.setColumnWidth(column, 6000);
        }
        else
        {
            // 設(shè)置列寬
            sheet.setColumnWidth(column, (int) ((attr.width() + 0.72) * 256));
        }
        if (StringUtils.isNotEmpty(attr.prompt()) || attr.combo().length > 0)
        {
            // 提示信息或只能選擇不能輸入的列內(nèi)容.
            setPromptOrValidation(sheet, attr.combo(), attr.prompt(), 1, 100, column, column);
        }
    }
    /**
     * 添加單元格
     */
    public Cell addCell(Excel attr, Row row, T vo, Field field, int column)
    {
        Cell cell = null;
        try
        {
            // 設(shè)置行高
            row.setHeight(maxHeight);
            // 根據(jù)Excel中設(shè)置情況決定是否導(dǎo)出,有些情況需要保持為空,希望用戶填寫這一列.
            if (attr.isExport())
            {
                // 創(chuàng)建cell
                cell = row.createCell(column);
                cell.setCellStyle(styles.get(StringUtils.format("data_{}_{}_{}", attr.align(), attr.color(), attr.backgroundColor())));
                // 用于讀取對(duì)象中的屬性
                Object value = getTargetValue(vo, field, attr);
                String dateFormat = attr.dateFormat();
                String readConverterExp = attr.readConverterExp();
                String separator = attr.separator();
                String dictType = attr.dictType();
                if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value))
                {
                    cell.setCellValue(parseDateToStr(dateFormat, value));
                }
                else if (StringUtils.isNotEmpty(readConverterExp) && StringUtils.isNotNull(value))
                {
                    cell.setCellValue(convertByExp(Convert.toStr(value), readConverterExp, separator));
                }
                /*else if (StringUtils.isNotEmpty(dictType) && StringUtils.isNotNull(value))
                {
                    cell.setCellValue(convertDictByExp(Convert.toStr(value), dictType, separator));
                }*/
                else if (value instanceof BigDecimal && -1 != attr.scale())
                {
                    cell.setCellValue((((BigDecimal) value).setScale(attr.scale(), attr.roundingMode())).toString());
                }
                else if (!attr.handler().equals(ExcelHandlerAdapter.class))
                {
                    cell.setCellValue(dataFormatHandlerAdapter(value, attr));
                }
                else
                {
                    // 設(shè)置列類型
                    setCellVo(value, attr, cell);
                }
                addStatisticsData(column, Convert.toStr(value), attr);
            }
        }
        catch (Exception e)
        {
            log.error("導(dǎo)出Excel失敗{}", e);
        }
        return cell;
    }
    /**
     * 設(shè)置 POI XSSFSheet 單元格提示或選擇框
     * 
     * @param sheet 表單
     * @param textlist 下拉框顯示的內(nèi)容
     * @param promptContent 提示內(nèi)容
     * @param firstRow 開始行
     * @param endRow 結(jié)束行
     * @param firstCol 開始列
     * @param endCol 結(jié)束列
     */
    public void setPromptOrValidation(Sheet sheet, String[] textlist, String promptContent, int firstRow, int endRow,
            int firstCol, int endCol)
    {
        DataValidationHelper helper = sheet.getDataValidationHelper();
        DataValidationConstraint constraint = textlist.length > 0 ? helper.createExplicitListConstraint(textlist) : helper.createCustomConstraint("DD1");
        CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol);
        DataValidation dataValidation = helper.createValidation(constraint, regions);
        if (StringUtils.isNotEmpty(promptContent))
        {
            // 如果設(shè)置了提示信息則鼠標(biāo)放上去提示
            dataValidation.createPromptBox("", promptContent);
            dataValidation.setShowPromptBox(true);
        }
        // 處理Excel兼容性問題
        if (dataValidation instanceof XSSFDataValidation)
        {
            dataValidation.setSuppressDropDownArrow(true);
            dataValidation.setShowErrorBox(true);
        }
        else
        {
            dataValidation.setSuppressDropDownArrow(false);
        }
        sheet.addValidationData(dataValidation);
    }
    /**
     * 解析導(dǎo)出值 0=男,1=女,2=未知
     * 
     * @param propertyValue 參數(shù)值
     * @param converterExp 翻譯注解
     * @param separator 分隔符
     * @return 解析后值
     */
    public static String convertByExp(String propertyValue, String converterExp, String separator)
    {
        StringBuilder propertyString = new StringBuilder();
        String[] convertSource = converterExp.split(",");
        for (String item : convertSource)
        {
            String[] itemArray = item.split("=");
            if (StringUtils.containsAny(separator, propertyValue))
            {
                for (String value : propertyValue.split(separator))
                {
                    if (itemArray[0].equals(value))
                    {
                        propertyString.append(itemArray[1] + separator);
                        break;
                    }
                }
            }
            else
            {
                if (itemArray[0].equals(propertyValue))
                {
                    return itemArray[1];
                }
            }
        }
        return StringUtils.stripEnd(propertyString.toString(), separator);
    }
    /**
     * 反向解析值 男=0,女=1,未知=2
     * 
     * @param propertyValue 參數(shù)值
     * @param converterExp 翻譯注解
     * @param separator 分隔符
     * @return 解析后值
     */
    public static String reverseByExp(String propertyValue, String converterExp, String separator)
    {
        StringBuilder propertyString = new StringBuilder();
        String[] convertSource = converterExp.split(",");
        for (String item : convertSource)
        {
            String[] itemArray = item.split("=");
            if (StringUtils.containsAny(separator, propertyValue))
            {
                for (String value : propertyValue.split(separator))
                {
                    if (itemArray[1].equals(value))
                    {
                        propertyString.append(itemArray[0] + separator);
                        break;
                    }
                }
            }
            else
            {
                if (itemArray[1].equals(propertyValue))
                {
                    return itemArray[0];
                }
            }
        }
        return StringUtils.stripEnd(propertyString.toString(), separator);
    }
    /**
     * 解析字典值
     * 
     * @param dictValue 字典值
     * @param dictType 字典類型
     * @param separator 分隔符
     * @return 字典標(biāo)簽
     */
    /*public static String convertDictByExp(String dictValue, String dictType, String separator)
    {
        return DictUtils.getDictLabel(dictType, dictValue, separator);
    }*/
    /**
     * 反向解析值字典值
     * 
     * @param dictLabel 字典標(biāo)簽
     * @param dictType 字典類型
     * @param separator 分隔符
     * @return 字典值
     */
    /*public static String reverseDictByExp(String dictLabel, String dictType, String separator)
    {
        return DictUtils.getDictValue(dictType, dictLabel, separator);
    }*/
    /**
     * 數(shù)據(jù)處理器
     * 
     * @param value 數(shù)據(jù)值
     * @param excel 數(shù)據(jù)注解
     * @return
     */
    public String dataFormatHandlerAdapter(Object value, Excel excel)
    {
        try
        {
            Object instance = excel.handler().newInstance();
            Method formatMethod = excel.handler().getMethod("format", new Class[] { Object.class, String[].class });
            value = formatMethod.invoke(instance, value, excel.args());
        }
        catch (Exception e)
        {
            log.error("不能格式化數(shù)據(jù) " + excel.handler(), e.getMessage());
        }
        return Convert.toStr(value);
    }
    /**
     * 合計(jì)統(tǒng)計(jì)信息
     */
    private void addStatisticsData(Integer index, String text, Excel entity)
    {
        if (entity != null && entity.isStatistics())
        {
            Double temp = 0D;
            if (!statistics.containsKey(index))
            {
                statistics.put(index, temp);
            }
            try
            {
                temp = Double.valueOf(text);
            }
            catch (NumberFormatException e)
            {
            }
            statistics.put(index, statistics.get(index) + temp);
        }
    }
    /**
     * 創(chuàng)建統(tǒng)計(jì)行
     */
    public void addStatisticsRow()
    {
        if (statistics.size() > 0)
        {
            Row row = sheet.createRow(sheet.getLastRowNum() + 1);
            Set<Integer> keys = statistics.keySet();
            Cell cell = row.createCell(0);
            cell.setCellStyle(styles.get("total"));
            cell.setCellValue("合計(jì)");
            for (Integer key : keys)
            {
                cell = row.createCell(key);
                cell.setCellStyle(styles.get("total"));
                cell.setCellValue(DOUBLE_FORMAT.format(statistics.get(key)));
            }
            statistics.clear();
        }
    }
    /**
     * 編碼文件名
     */
    public String encodingFilename(String filename)
    {
        filename = UUID.randomUUID().toString() + "_" + filename + ".xlsx";
        return filename;
    }
    /**
     * 獲取下載路徑
     * 
     * @param filename 文件名稱
     */
    public String getAbsoluteFile(String filename)
    {
        String downloadPath ="";
        File desc = new File(downloadPath);
        if (!desc.getParentFile().exists())
        {
            desc.getParentFile().mkdirs();
        }
        return downloadPath;
    }
    /**
     * 獲取bean中的屬性值
     * 
     * @param vo 實(shí)體對(duì)象
     * @param field 字段
     * @param excel 注解
     * @return 最終的屬性值
     * @throws Exception
     */
    private Object getTargetValue(T vo, Field field, Excel excel) throws Exception
    {
        Object o = field.get(vo);
        if (StringUtils.isNotEmpty(excel.targetAttr()))
        {
            String target = excel.targetAttr();
            if (target.contains("."))
            {
                String[] targets = target.split("[.]");
                for (String name : targets)
                {
                    o = getValue(o, name);
                }
            }
            else
            {
                o = getValue(o, target);
            }
        }
        return o;
    }
    /**
     * 以類的屬性的get方法方法形式獲取值
     * 
     * @param o
     * @param name
     * @return value
     * @throws Exception
     */
    private Object getValue(Object o, String name) throws Exception
    {
        if (StringUtils.isNotNull(o) && StringUtils.isNotEmpty(name))
        {
            Class<?> clazz = o.getClass();
            Field field = clazz.getDeclaredField(name);
            field.setAccessible(true);
            o = field.get(o);
        }
        return o;
    }
    /**
     * 得到所有定義字段
     */
    private void createExcelField()
    {
        this.fields = getFields();
        this.fields = this.fields.stream().sorted(Comparator.comparing(objects -> ((Excel) objects[1]).sort())).collect(Collectors.toList());
        this.maxHeight = getRowHeight();
    }
    /**
     * 獲取字段注解信息
     */
    public List<Object[]> getFields()
    {
        List<Object[]> fields = new ArrayList<Object[]>();
        List<Field> tempFields = new ArrayList<>();
        tempFields.addAll(Arrays.asList(clazz.getSuperclass().getDeclaredFields()));
        tempFields.addAll(Arrays.asList(clazz.getDeclaredFields()));
        for (Field field : tempFields)
        {
            if (!ArrayUtils.contains(this.excludeFields, field.getName()))
            {
                // 單注解
                if (field.isAnnotationPresent(Excel.class))
                {
                    Excel attr = field.getAnnotation(Excel.class);
                    if (attr != null && (attr.type() == Type.ALL || attr.type() == type))
                    {
                        field.setAccessible(true);
                        fields.add(new Object[] { field, attr });
                    }
                }
                // 多注解
                if (field.isAnnotationPresent(Excels.class))
                {
                    Excels attrs = field.getAnnotation(Excels.class);
                    Excel[] excels = attrs.value();
                    for (Excel attr : excels)
                    {
                        if (attr != null && (attr.type() == Type.ALL || attr.type() == type))
                        {
                            field.setAccessible(true);
                            fields.add(new Object[] { field, attr });
                        }
                    }
                }
            }
        }
        return fields;
    }
    /**
     * 根據(jù)注解獲取最大行高
     */
    public short getRowHeight()
    {
        double maxHeight = 0;
        for (Object[] os : this.fields)
        {
            Excel excel = (Excel) os[1];
            maxHeight = Math.max(maxHeight, excel.height());
        }
        return (short) (maxHeight * 20);
    }
    /**
     * 創(chuàng)建一個(gè)工作簿
     */
    public void createWorkbook()
    {
        this.wb = new SXSSFWorkbook(500);
        this.sheet = wb.createSheet();
        wb.setSheetName(0, sheetName);
        this.styles = createStyles(wb);
    }
    /**
     * 創(chuàng)建工作表
     * 
     * @param sheetNo sheet數(shù)量
     * @param index 序號(hào)
     */
    public void createSheet(int sheetNo, int index)
    {
        // 設(shè)置工作表的名稱.
        if (sheetNo > 1 && index > 0)
        {
            this.sheet = wb.createSheet();
            this.createTitle();
            wb.setSheetName(index, sheetName + index);
        }
    }
    /**
     * 獲取單元格值
     * 
     * @param row 獲取的行
     * @param column 獲取單元格列號(hào)
     * @return 單元格值
     */
    public Object getCellValue(Row row, int column)
    {
        if (row == null)
        {
            return row;
        }
        Object val = "";
        try
        {
            Cell cell = row.getCell(column);
            if (StringUtils.isNotNull(cell))
            {
                if (cell.getCellType() == CellType.NUMERIC || cell.getCellType() == CellType.FORMULA)
                {
                    val = cell.getNumericCellValue();
                    if (DateUtil.isCellDateFormatted(cell))
                    {
                        val = DateUtil.getJavaDate((Double) val); // POI Excel 日期格式轉(zhuǎn)換
                    }
                    else
                    {
                        if ((Double) val % 1 != 0)
                        {
                            val = new BigDecimal(val.toString());
                        }
                        else
                        {
                            val = new DecimalFormat("0").format(val);
                        }
                    }
                }
                else if (cell.getCellType() == CellType.STRING)
                {
                    val = cell.getStringCellValue();
                }
                else if (cell.getCellType() == CellType.BOOLEAN)
                {
                    val = cell.getBooleanCellValue();
                }
                else if (cell.getCellType() == CellType.ERROR)
                {
                    val = cell.getErrorCellValue();
                }
            }
        }
        catch (Exception e)
        {
            return val;
        }
        return val;
    }
    /**
     * 判斷是否是空行
     * 
     * @param row 判斷的行
     * @return
     */
    private boolean isRowEmpty(Row row)
    {
        if (row == null)
        {
            return true;
        }
        for (int i = row.getFirstCellNum(); i < row.getLastCellNum(); i++)
        {
            Cell cell = row.getCell(i);
            if (cell != null && cell.getCellType() != CellType.BLANK)
            {
                return false;
            }
        }
        return true;
    }
    /**
     * 獲取Excel2003圖片
     *
     * @param sheet 當(dāng)前sheet對(duì)象
     * @param workbook 工作簿對(duì)象
     * @return Map key:圖片單元格索引(1_1)String,value:圖片流PictureData
     */
    public static Map<String, PictureData> getSheetPictures03(HSSFSheet sheet, HSSFWorkbook workbook)
    {
        Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>();
        List<HSSFPictureData> pictures = workbook.getAllPictures();
        if (!pictures.isEmpty())
        {
            for (HSSFShape shape : sheet.getDrawingPatriarch().getChildren())
            {
                HSSFClientAnchor anchor = (HSSFClientAnchor) shape.getAnchor();
                if (shape instanceof HSSFPicture)
                {
                    HSSFPicture pic = (HSSFPicture) shape;
                    int pictureIndex = pic.getPictureIndex() - 1;
                    HSSFPictureData picData = pictures.get(pictureIndex);
                    String picIndex = String.valueOf(anchor.getRow1()) + "_" + String.valueOf(anchor.getCol1());
                    sheetIndexPicMap.put(picIndex, picData);
                }
            }
            return sheetIndexPicMap;
        }
        else
        {
            return sheetIndexPicMap;
        }
    }
    /**
     * 獲取Excel2007圖片
     *
     * @param sheet 當(dāng)前sheet對(duì)象
     * @param workbook 工作簿對(duì)象
     * @return Map key:圖片單元格索引(1_1)String,value:圖片流PictureData
     */
    public static Map<String, PictureData> getSheetPictures07(XSSFSheet sheet, XSSFWorkbook workbook)
    {
        Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>();
        for (POIXMLDocumentPart dr : sheet.getRelations())
        {
            if (dr instanceof XSSFDrawing)
            {
                XSSFDrawing drawing = (XSSFDrawing) dr;
                List<XSSFShape> shapes = drawing.getShapes();
                for (XSSFShape shape : shapes)
                {
                    if (shape instanceof XSSFPicture)
                    {
                        XSSFPicture pic = (XSSFPicture) shape;
                        XSSFClientAnchor anchor = pic.getPreferredSize();
                        CTMarker ctMarker = anchor.getFrom();
                        String picIndex = ctMarker.getRow() + "_" + ctMarker.getCol();
                        sheetIndexPicMap.put(picIndex, pic.getPictureData());
                    }
                }
            }
        }
        return sheetIndexPicMap;
    }
    /**
     * 格式化不同類型的日期對(duì)象
     * 
     * @param dateFormat 日期格式
     * @param val 被格式化的日期對(duì)象
     * @return 格式化后的日期字符
     */
    public String parseDateToStr(String dateFormat, Object val)
    {
        if (val == null)
        {
            return "";
        }
        String str;
        if (val instanceof Date)
        {
            str = DateUtils.parseDateToStr(dateFormat, (Date) val);
        }
        else if (val instanceof LocalDateTime)
        {
            str = DateUtils.parseDateToStr(dateFormat, DateUtils.toDate((LocalDateTime) val));
        }
        else if (val instanceof LocalDate)
        {
            str = DateUtils.parseDateToStr(dateFormat, DateUtils.toDate((LocalDate) val));
        }
        else
        {
            str = val.toString();
        }
        return str;
    }
}

本來想多上傳幾個(gè)工具類和枚舉類,但是csdn這個(gè)編輯文字一多就卡住了,只能先寫這里,剩下的枚舉后面有機(jī)會(huì)繼續(xù)上傳,大家有需要可以私信博主

到此這篇關(guān)于Springboot獲取文件內(nèi)容,將MultipartFile轉(zhuǎn)File方法的文章就介紹到這了,更多相關(guān)Springboot MultipartFile轉(zhuǎn)File內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 詳解Spring+Hiernate整合

    詳解Spring+Hiernate整合

    這篇文章主要介紹了詳解Spring+Hiernate整合,spring整合hibernate主要介紹以xml方式實(shí)現(xiàn),有興趣的可以了解一下。
    2017-04-04
  • Spring MVC Mybatis多數(shù)據(jù)源的使用實(shí)例解析

    Spring MVC Mybatis多數(shù)據(jù)源的使用實(shí)例解析

    項(xiàng)目需要從其他網(wǎng)站獲取數(shù)據(jù),因?yàn)槭桥R時(shí)加的需求,這篇文章主要介紹了Spring MVC Mybatis多數(shù)據(jù)源的使用實(shí)例解析,需要的朋友可以參考下
    2016-12-12
  • SpringBoot使用Redis實(shí)現(xiàn)消息隊(duì)列的方法小結(jié)

    SpringBoot使用Redis實(shí)現(xiàn)消息隊(duì)列的方法小結(jié)

    在應(yīng)用中把Redis當(dāng)成消息隊(duì)列來使用已經(jīng)屢見不鮮了,我想主要原因是當(dāng)代應(yīng)用十有八九都會(huì)用到 Redis,因此不用再引入其他消息隊(duì)列系統(tǒng),而且Redis提供了好幾種實(shí)現(xiàn)消息隊(duì)列的方法,用起來也簡(jiǎn)單,本文給大家介紹了SpringBoot使用Redis實(shí)現(xiàn)消息隊(duì)列的方法小結(jié)
    2024-04-04
  • JAVA DOM解析XML文件過程詳解

    JAVA DOM解析XML文件過程詳解

    這篇文章主要介紹了JAVA DOM解析XML文件過程詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-01-01
  • SpringBoot整合JPA 基礎(chǔ)使用示例教程

    SpringBoot整合JPA 基礎(chǔ)使用示例教程

    JPA(Java Persistence API)是Java提供的一套數(shù)據(jù)持久化標(biāo)準(zhǔn),通過對(duì)象-關(guān)系映射(ORM)技術(shù)實(shí)現(xiàn)Java對(duì)象與數(shù)據(jù)庫表之間的映射,它提供了一系列注解和接口,簡(jiǎn)化了數(shù)據(jù)庫操作,使得開發(fā)者可以通過操作對(duì)象來進(jìn)行數(shù)據(jù)庫交互,而無需編寫復(fù)雜的SQL語句
    2024-10-10
  • MyBatis流式查詢的項(xiàng)目實(shí)踐

    MyBatis流式查詢的項(xiàng)目實(shí)踐

    本文主要介紹了MyBatis流式查詢的項(xiàng)目實(shí)踐,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-08-08
  • Mybatis in條件傳參的三種實(shí)現(xiàn)方式(直接$,List,[])

    Mybatis in條件傳參的三種實(shí)現(xiàn)方式(直接$,List,[])

    這篇文章主要介紹了Mybatis in條件傳參的三種實(shí)現(xiàn)方式(直接$,List,[]),具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-12-12
  • Java并發(fā)工具之Exchanger線程間交換數(shù)據(jù)詳解

    Java并發(fā)工具之Exchanger線程間交換數(shù)據(jù)詳解

    這篇文章主要介紹了Java并發(fā)工具之Exchanger線程間交換數(shù)據(jù)詳解,Exchanger是一個(gè)用于線程間協(xié)作的工具類,Exchanger用于進(jìn)行線程間的數(shù)據(jù)交 換,它提供一個(gè)同步點(diǎn),在這個(gè)同步點(diǎn),兩個(gè)線程可以交換彼此的數(shù)據(jù),需要的朋友可以參考下
    2023-12-12
  • Java反射機(jī)制的講解

    Java反射機(jī)制的講解

    今天小編就為大家分享一篇關(guān)于Java反射機(jī)制的講解,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2019-04-04
  • java打印國際象棋棋盤的方法

    java打印國際象棋棋盤的方法

    這篇文章主要為大家詳細(xì)介紹了java打印出國際象棋棋盤的相關(guān)代碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-05-05

最新評(píng)論