如何使用Java 实现excel模板导出---多sheet导出?

实现多个sheet的excel导出功能

效果展示:
在这里插入图片描述

maven依赖

<dependency>
			<groupId>org.apache.poi</groupId>
			<artifactId>poi</artifactId>
			<version>3.17</version>
		</dependency>
		<dependency>
			<groupId>org.apache.poi</groupId>
			<artifactId>poi-ooxml</artifactId>
			<version>3.17</version>
		</dependency>

相关工具类
**此处省略异常处理类

ExcelReportUtil 类


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;

import java.math.BigDecimal;
import java.util.*;

/**
 * 
* @ClassName: ExcelReportUtil 
* @Description: excel导出工具类 
* @version v1.0
 */
public class ExcelReportUtil {
	
	private static Log logger = LogFactory.getLog(ExcelReportUtil.class);
	
	/**
	 * clone the height, cells and cellRangeAddress to destRow from srcRow
	 * @param sheet
	 * @param srcRow
	 * @param destRow
	 */
	public static void cloneRow(Sheet sheet, Row srcRow, Row destRow) {
		if (sheet == null || srcRow == null || destRow == null)
			return;
		Set mergedRegions = new HashSet();
		destRow.setHeight(srcRow.getHeight());
		if (srcRow.getFirstCellNum() >= 0 && srcRow.getLastCellNum() >= 0) {
            for (int i = srcRow.getFirstCellNum(), j = srcRow.getLastCellNum(); i <= j; i++) {
				Cell srcCell = srcRow.getCell(i);
				Cell destCell = destRow.getCell(i);
                if (srcCell != null) {
                	logger.debug("cell is found at col[" + i + 
                			"], will be cloned to the destRow");
                    if (destCell == null) {
                        destCell = destRow.createCell(i);
                    }
                    cloneCell(srcCell, destCell);
                    CellRangeAddress mergedRegion = getMergedRegion(sheet, srcRow.getRowNum(),
                    		srcCell.getColumnIndex());
                    if (mergedRegion != null) {
                    	CellRangeAddress newMergedRegion = new CellRangeAddress(
                    			destRow.getRowNum(), 
                    			destRow.getRowNum() + mergedRegion.getLastRow() - mergedRegion.getFirstRow(), 
                    			mergedRegion.getFirstColumn(), 
                    			mergedRegion.getLastColumn());
                        if (isNewMergedRegion(newMergedRegion, mergedRegions)) {
                        	logger.debug("CellRangeAddress is found at col[" + i + 
                        			"], will be cloned to the destRow");
                            mergedRegions.add(newMergedRegion);
                            sheet.addMergedRegion(newMergedRegion);
                        }
                    }
                }
            }
		}
	}
	
	/**
	 * get the CellRangeAddress of sheet at [rowNum, colNum] if exists
	 * @param sheet
	 * @param rowNum
	 * @param colNum
	 * @return null if not exists
	 */
	public static CellRangeAddress getMergedRegion(Sheet sheet, int rowNum, int colNum) {
        for (int i = 0, c = sheet.getNumMergedRegions(); i < c; i++) {
            CellRangeAddress merged = sheet.getMergedRegion(i);
            if (isRangeContainsCell(merged, rowNum, colNum)) {
                return merged;
            }
        }
        return null;
    }
	
	/**
	 * to judge whether the CellRangeAddress includes the cell at [row, col]
	 * @param range
	 * @param row
	 * @param col
	 * @return 
	 * 	true if the CellRangeAddress includes the cell at [row, col]
	 */
    public static boolean isRangeContainsCell(CellRangeAddress range, int row, int col) {
        if ((range.getFirstRow() <= row) && (range.getLastRow() >= row)
                && (range.getFirstColumn() <= col)
                && (range.getLastColumn() >= col)) {
            return true;
        }
        return false;
    }
    
    /**
     * to judge if the CellRangeAddress is not included in mergedRegions,
     * using {@link #areRegionsEqual(CellRangeAddress, CellRangeAddress)} to compare
     * @param region
     * @param mergedRegions
     * @return 
     * 	true if the CellRangeAddress is not included in mergedRegions
     */
    private static boolean isNewMergedRegion(CellRangeAddress region,
            Collection mergedRegions) {
        for (Iterator iterator = mergedRegions.iterator(); iterator.hasNext();) {
            CellRangeAddress cellRangeAddress = (CellRangeAddress) iterator.next();
            if (areRegionsEqual(cellRangeAddress, region)) {
                return false;
            }
        }
        return true;
    }
    
    /**
     * compares region1 with region2
     * @param region1
     * @param region2
     * @return 
     * 	true if both of them are null or 
     * 	their firstColumn, lastColumn, firstRow and lastRow are all the same
     */
    public static boolean areRegionsEqual(CellRangeAddress region1,
            CellRangeAddress region2) {
        if ((region1 == null && region2 != null)
                || (region1 != null && region2 == null)) {
            return false;
        }
        if (region1 == null) {
            return true;
        }
        return (region1.getFirstColumn() == region2.getFirstColumn()
                && region1.getLastColumn() == region2.getLastColumn()
                && region1.getFirstRow() == region2.getFirstRow() 
                && region2.getLastRow() == region2.getLastRow());
    }
    
    /**
     * clone the style and value to destCell from srcCell
     * @param srcCell
     * @param destCell
     */
    public static void cloneCell(Cell srcCell, Cell destCell) {
		if (srcCell == null || destCell == null)
			return;
		destCell.setCellStyle(srcCell.getCellStyle());
		switch (srcCell.getCellTypeEnum()) {
			case NUMERIC :
				destCell.setCellValue(srcCell.getNumericCellValue());
				break;
			case STRING :
				destCell.setCellValue(srcCell.getRichStringCellValue());
				break;
			case FORMULA :
				destCell.setCellFormula(srcCell.getCellFormula());
				break;
			case ERROR:
				destCell.setCellErrorValue(srcCell.getErrorCellValue());
				break;
			case BOOLEAN:
				destCell.setCellValue(srcCell.getBooleanCellValue());
				break;
			default :
				destCell.setCellType(CellType.BLANK);
				break;
		}
	}
    
    /**
     * Set a value for the cell.
     * Value whose type is {@link Calendar}, {@link Date}, {@link Number}, {@link String}
     * is supported directly, otherwise will be processed as string.
     * @param cell
     * @param value
     */
    public static void setCellValue(Cell cell, Object value) {
    	if (cell == null)
    		return;
    	if (value == null) {
    		cell.setCellType(CellType.BLANK);
    	} else if (value instanceof Calendar) {
    		cell.setCellValue((Calendar) value);
    	//Date格式化日期输出
		} else if (value instanceof Date) {
			//cell.setCellValue((Date) value);
			//cell.setCellValue(BaseUtils.Date2String((Date)value, CommonConstants.FORMAT_Date));
			cell.setCellValue(BaseUtils.Date2String((Date)value, "yyyy-MM-dd HH:mm:ss"));
		} else if (value instanceof Number) {
			setCellValue(cell, (Number) value);
		} else if (value instanceof String) {
			cell.setCellValue((String) value);
		} else {
			logger.warn("value type [" + value.getClass().getName() + 
					"] is not directly supported, will be processed as String");
			cell.setCellValue((String) value.toString());
		}
    }
	
    /**
     * set a number value for the cell
     * @param cell
     * @param value
     * @throws XLSReportException
     * 	if the Number can not be unwrapped
     */
	private static void setCellValue(Cell cell, Number value) {
		double doubleContent = 0.0;
		if (value instanceof Byte) {
			doubleContent = (Byte) value;
		} else if (value instanceof Double) {
			doubleContent = (Double) value;
		} else if (value instanceof Float) {
			doubleContent = (Float) value;
		//BigDecimal转换为Double
		}else if (value instanceof BigDecimal) {
			doubleContent = TypeCaseHelper.convert2Double(value);
		} else if (value instanceof Integer) {
			float tmp = (Integer) value;
			doubleContent = tmp;
		} else if (value instanceof Long) {
			float tmp = (Long) value;
			doubleContent = tmp;
		} else if (value instanceof Short) {
			short tmp = (Short) value;
			doubleContent = tmp;
		} else {
			throw new XLSReportException("value type [" + value.getClass().getName() + 
					"] can not be processed as double");
		}
		cell.setCellValue(doubleContent);
	}
	
	/**
	 * get the string value of a cell
	 * @param cell
	 * @return "" if type of the cell is not in 
	 * 	{CELL_TYPE_NUMERIC, CELL_TYPE_STRING and CELL_TYPE_BOOLEAN}
	 * @see Cell#CELL_TYPE_BLANK
     * @see Cell#CELL_TYPE_NUMERIC
     * @see Cell#CELL_TYPE_STRING
     * @see Cell#CELL_TYPE_FORMULA
     * @see Cell#CELL_TYPE_BOOLEAN
     * @see Cell#CELL_TYPE_ERROR
	 */
	public static String getCellStringValue(Cell cell) {
		String cellStringValue = null;
		switch (cell.getCellTypeEnum()) {
			case NUMERIC:
				cellStringValue = cell.getNumericCellValue() + "";
				break;
			case STRING:
				cellStringValue = cell.getStringCellValue();
				break;
			case BOOLEAN:
				cellStringValue = cell.getBooleanCellValue() + "";
				break;
			default :
				logger.warn("can not get the string value of a cell whose type is " + cell.getCellTypeEnum());
				cellStringValue = "";
				break;
		}
		return cellStringValue;
	}
	
	/**
	 * remove a comment from sheet
	 * @param sheet
	 * @param comment
	 */
	public static void removeComment(Sheet sheet, Comment comment) {
		if (sheet != null && comment != null) {
			sheet.getRow(comment.getRow())
				.getCell(comment.getColumn())
				.removeCellComment();
		}
	}
	
}

excel 接口


import org.apache.poi.ss.usermodel.Sheet;
import java.util.Map;

/**
 * 
* @ClassName: ExcelProcessor 
* @Description: 自定义的excel接口
* @author huali
* @version v1.0
 */
public interface ExcelProcessor{
	
	/**
	 * initialize the CommentProcessor
	 */
	void init();
	

	boolean isInited();
	
	/**
	 * 
	* @Title: process 
	* @Description: fill the XLS sheet by data 
	* @param @param sheet
	* @param @param dataSource
	* @return void
	 */
	void process(Sheet sheet, Map dataSource);
}

实现类

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ibatis.ognl.Ognl;
import org.apache.ibatis.ognl.OgnlException;
import org.apache.poi.ss.usermodel.*;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * Implementation of {@link ExcelProcessor},
 * it fills a list in the XLS horizontally.
 * Besides 'type', 'expression', 'firstIndex' and 'dataMapping' are added to finish that,
 * 1) expression, mandatory, a OGNL expression, is used to get the list from XLS data
 * 2) firstIndex, mandatory, the beginning row index of filling list
 * 3) dataMapping, mandatory, a Map<Integer, String> value,
 * 		whose key is the cell column index and value is a OGNL expression to
 * 		get the cell value from list element.
 * In filling, the list element is transfered by {@link ExcelDataSource},
 * and the index of element is put in the transfered data as key 'index'.
 * A typical configuration is like this,
 * { type : 'I', expression : 'students', dataMapping : { 1 : 'index', 2 : 'name'...} }
 *
 */
public class ExcelIteratorNoLastRowProcessor implements ExcelProcessor {
//填充类型
	public static String TYPE_ID = "I";

	private static Log logger = LogFactory.getLog(ExcelIteratorNoLastRowProcessor.class);

	private boolean inited;
//批注
	private final Comment comment;
//填充数据的名称
	private String expression;
//从第几行开始填充
	private int firstIndex;
//填充的数据
	private Map<Integer, String> dataMapping;

	public ExcelIteratorNoLastRowProcessor(Comment comment) {
		this.comment = comment;
	}

	public String getExpression() {
		return expression;
	}

	public void setExpression(String expression) {
		this.expression = expression;
	}

	public int getFirstIndex() {
		return firstIndex;
	}

	public void setFirstIndex(int firstIndex) {
		this.firstIndex = firstIndex;
	}

	public Map<Integer, String> getDataMapping() {
		return dataMapping;
	}

	public void setDataMapping(Map<Integer, String> dataMapping) {
		this.dataMapping = dataMapping;
	}

	@Override
	public void init() {
		try {
			Map<String, Object> classMap = new HashMap<String, Object>();
			classMap.put("dataMapping", Map.class);
			Map<String, Object> cfg = JSON.parseObject(this.comment.getString().toString(),Map.class);
			Object expresionCfg = cfg.get("expression");
			Object firstIndexCfg = cfg.get("firstIndex");
			Object dataMappingCfg = cfg.get("dataMapping");
			if (expresionCfg == null || !(expresionCfg instanceof String)) {
				throw new XLSReportCfgException("expresion must be configured and its type must be String");
			}
			this.expression = (String) expresionCfg;
			if (firstIndexCfg == null || !(firstIndexCfg instanceof Integer)) {
				throw new XLSReportCfgException("firstIndex must be configured and its type must be Integer");
			}
			this.firstIndex = (Integer) firstIndexCfg;
			if (dataMappingCfg == null || !(dataMappingCfg instanceof Map)) {
				throw new XLSReportCfgException("dataMapping must be configured and its type must be Map");
			}
			this.dataMapping = (Map<Integer, String>) dataMappingCfg;
			this.inited = true;
		} catch (JSONException e) {
			throw new XLSReportCfgException("the comment configuration at [" +
					comment.getRow() + "," + comment.getColumn() + "] " + comment.getString().toString() +
					" is error", e);
		}
	}

	@Override
	public boolean isInited() {
		return this.inited;
	}

	@Override
	public void process(Sheet sheet, Map dataSource) {
		try {
			if (!isInited())
				throw new XLSReportException("the CommentProcessor has not inited yet");
				//从dataSource中找到填充目标名称
			Object content = Ognl.getValue(this.expression, dataSource);
			if (content == null) {
				content = Collections.EMPTY_LIST;
			}
			if (!(content instanceof Iterable)) {
				content = Arrays.asList(content);
			}
			int index = 0;
			boolean isAddRow = false;
			for (Object element : (Iterable) content) {
				//clone row
				logger.debug("clone the row at index[" + (this.firstIndex + index + 1) + "] to the new row at index[" + (this.firstIndex + index) + "]");
				ExcelReportUtil.cloneRow(sheet, sheet.getRow(this.firstIndex + index + 1), sheet.createRow(this.firstIndex + index));
				//获取填充行
				Row aimedRow = sheet.getRow(this.firstIndex + index);
				//fill data
				for (Integer key : this.dataMapping.keySet()) {
					int cellIndex = key;
					//获取第一行的数据
					Map rowDS = new ExcelDataSource(element).getData();
					rowDS.put("index", index);
					Cell aimedCell = aimedRow.getCell(cellIndex);
					if (aimedCell == null)
						aimedCell = aimedRow.createCell(cellIndex);
						//找到列对应的数据
					Object value = Ognl.getValue(this.dataMapping.get(key), rowDS);
					//样式
					if(Boolean.parseBoolean(rowDS.get("isBolded") == null ? "":rowDS.get("isBolded").toString())){
						Workbook workbook = sheet.getWorkbook();
						CellStyle cellStyle = workbook.createCellStyle();
						Font font = workbook.createFont();
						//font.setBoldweight(Font.BOLDWEIGHT_BOLD);
						font.setBold(true);
						cellStyle.setFont(font);
						aimedCell.setCellStyle(cellStyle);
					}
					logger.debug("set the value of cell[" + (this.firstIndex + index) + ", " + cellIndex + "] to " + value);
					//给列填值
					ExcelReportUtil.setCellValue(aimedCell, value);
				}
				index++;
			}
			//remove comment
			ExcelReportUtil.removeComment(sheet, this.comment);
		} catch (OgnlException e) {
			throw new XLSReportException("extracting data error while using OGNL expression[" +
					this.expression + "] with root object : " + dataSource);
		}
	}
}

excel填充数据处理类


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * Implementation of XLSReportDataSource, which is constructed by a original bean.
 * The original bean will be processed as following,
 * 1. Collections.emptyMap() if it is null
 * 2. used directly if its type is Map
 * 3. otherwise it will be transformed to Map, {@link #transformPropertiesToMap(Object)}
 */
public class ExcelDataSource  {
	
	private static Log logger = LogFactory.getLog(ExcelDataSource.class);
	
	/**
	 * the original bean 
	 */
	private Object dataSource;
	
	public ExcelDataSource(Object dataSource) {
		this.dataSource = dataSource;
	}
	
	public Map getData() {
		Map ds = null;
		if (this.dataSource == null) {
			ds = Collections.emptyMap();
		} else if (this.dataSource instanceof Map) {
			ds = (Map) this.dataSource;
		} else {
			logger.debug("the type of dataSource is [" + dataSource.getClass() + 
					"], will be transformed to Map");
			ds = transformPropertiesToMap(this.dataSource);
		}
		return ds;
	}
	
	/**
	 * Used locally to transform a bean to Map.
	 * The property names are transformed to the keys,
	 * theirs values are transformed to the value of the corresponding key.
	 * Besides, the property named 'class' is excluded.
	 * @param bean
	 * @return
	 */
	private Map transformPropertiesToMap(Object bean) {
		Map properties = new HashMap();
		BeanInfo beanInfo;
		try {
			beanInfo = Introspector.getBeanInfo(bean.getClass());
			PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
			for (PropertyDescriptor pd : pds) {
				if (!"class".equals(pd.getName())) {
					properties.put(pd.getName(), pd.getReadMethod().invoke(bean));
				}
			}
		} catch (Exception e) {
			throw new XLSReportException(e);
		}
		return properties;
	}

}

excel填充处理类

import com.alibaba.fastjson.JSON;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.poi.ss.usermodel.*;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 
* @ClassName: ExcelReportFiller 
* @Description: 读取模板数据处理
* @version v1.0
 */
public class ExcelReportFiller {
	
	private static final Log logger = LogFactory.getLog(ExcelReportFiller.class);
	
	public void fill(Workbook template, Map dataSource) {
		int sheetCount = template.getNumberOfSheets();
		for (int i = 0; i < sheetCount; i++) {
			logger.debug("scan the sheet at index[" + i + "]");
			fillSheet(template.getSheetAt(i), dataSource);
		}
	}
	
	public void fillSheetName(String sheetName, Workbook template,
			Map dataSource) {
		logger.debug("scan the sheet at [" + sheetName + "]");
		fillSheet(template.getSheet(sheetName), dataSource);
	}
	
	/**
	 * fill the XLS sheet by data
	 * @param sheet 模板template
	 * @param dataSource
	 */
	private void fillSheet(Sheet sheet, Map dataSource) {
		int rowCount = sheet.getLastRowNum();
		for (int i = 0; i <= rowCount; i++) {
			Row row = sheet.getRow(i);
			if (row != null) {
				int cellCount = row.getLastCellNum();
				for (int j = 0; j <= cellCount; j++) {
					Cell cell = row.getCell(j);
					if (cell != null ) {
						Comment comment = cell.getCellComment();
						if (comment != null) {
							logger.debug("comment is found at [" + i + ", " + j + "]");
							ExcelProcessor processor = ExcelProcessorFactory.getCommentProcessor(comment);
							processor.process(sheet, dataSource);
							//refresh rowCount
							rowCount = sheet.getLastRowNum();
						}
					}
				}
			}
		}
	}
}

excel模板处理


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;

import javax.servlet.http.HttpServletRequest;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

/**
 * 
* @ClassName: ExcelReportTemplate 
* @Description: 通过模板创建流
* @version v1.0
 */
public class ExcelReportTemplate  {
	
	private static final Log logger = LogFactory.getLog(ExcelReportTemplate.class);
	
	private final String path;

	private ClassLoader classLoader;
	
	/**
	 * 
	 * @param path
	 */
	public ExcelReportTemplate(String path) {
		this(path, (ClassLoader) null);
	}
	
	/**
	 * 
	 * @param path
	 * @param classLoader
	 */
	public ExcelReportTemplate(String path, ClassLoader classLoader) {
		if (path == null) {
			throw new IllegalArgumentException("Path must not be null");
		}
		this.path = path;
		if (classLoader == null) {
			try {
				classLoader = Thread.currentThread().getContextClassLoader();
			} catch (Throwable ex) {
				logger.debug("Cannot access thread context ClassLoader - falling back to system class loader", ex);
				classLoader = ExcelReportTemplate.class.getClassLoader();
			}
		}
		this.classLoader = classLoader;
	}
	
	
	public Workbook getTemplate() throws IOException, InvalidFormatException {
		InputStream is =new FileInputStream(this.path);
		if (is == null) {
			throw new FileNotFoundException(
					"class path resource [" + this.path + "] cannot be opened because it does not exist");
		}
		//return new HSSFWorkbook(is);
		Workbook workbook = WorkbookFactory.create(is);
		if(is != null){
			is.close();
		}
		return workbook;
	}
	

	public Workbook getTemplate(HttpServletRequest resquest) throws IOException, InvalidFormatException {
		InputStream is = this.classLoader.getResourceAsStream(this.path);
		if (is == null) {
			throw new FileNotFoundException(
					"class path resource [" + this.path + "] cannot be opened because it does not exist");
		}
		Workbook workbook = WorkbookFactory.create(is);
		if(is != null){
			is.close();
		}
		return workbook;
	}

}

实现关键代码展示
通过模板实现导出功能

 try {
            os = new FileOutputStream(excelPth);
            ExcelReportCreator.createXLS(new ExcelReportTemplate(excelTempletPath),
                    new ExcelDataSource(jsonMap),
                    new ExcelReportFiller(),
                    os);
            excelFilePathName = ftpPath + fileModel.getRealFileName();
        } catch (Exception e) {
            log.error("导出excel文件出错" + " excel文件路径=" + excelPth + " 模板路径=" + excelTempletPath, e);
            log.error("excel内容 " + jsonMap);
            throw e;
        } finally {
            if (os != null) {
                os.close();
            }
        }

ExcelReportCreator 中的代码

	
	/**
	 * 
	 * @param dataSource
	 * @param filler
	 * @param os
	 * @throws IOException
	 * @throws InvalidFormatException
	 */
	public static void createXLS(ExcelReportTemplate template,
			ExcelDataSource dataSource, ExcelReportFiller filler,
			OutputStream os) throws IOException, InvalidFormatException {
		Workbook workbook = template.getTemplate();
		filler.fill(workbook, dataSource.getData());
		workbook.write(os);
	}
	

导入数据案例展示
在这里插入图片描述
excel模板批注案例
每个sheet页都需要写批注,通过批注中的expression对应的值来判断是哪个sheet页的数据,从而进行填充。dataMapping中的key值指的是列序号,value值指的是填充的字段名称,通过名称找对应的数据。
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/44770.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

为啥面试官总喜欢问computed是咋实现的?

这里给大家分享我在网上总结出来的一些知识&#xff0c;希望对大家有所帮助 从computed的特性出发 computed最耀眼的几个特性是啥&#xff1f; 1. 依赖追踪 1 2 3 4 5 6 7 8 9 10 import { reactive, computed } from vue const state reactive({ a: 1, b: 2, c: 3,…

PHP8知识详解:PHP8开发工具VS Code的安装

作为PHP8的开发工具有很多&#xff0c;具有IDE功能的有phpstorm、Visual Studio Code、Sublime Text、NetBeans、Eclipse、Codelobster、PHP Designer等&#xff0c;当然还有很多轻量的工具&#xff0c;比如Notepad、Editplus等。本文给你介绍的是万能编辑器Visual Studio Code…

gitee上创建新仓库如何clone到本地,并初始化项目

目录 一、克隆 方法一 方法二 二、初始化项目 构建基本框架 自动生成代码 一、克隆 方法一 由于github速度较慢&#xff0c;这里我们使用gitee。我们在gitee上面创建一个仓库&#xff0c;然后我们可以通过ideal直接克隆下来&#xff0c;仓库设置如下 接着使用ideal将项…

芯洲科技-降压DCDC开关电源参考选型目录

芯洲科技&#xff0c;是国内领先的中高压DC-DC&#xff08;直流转直流&#xff09;功率转换芯片供应商。北京冠宇铭通 一级代理。 国产化替代&#xff0c;对标TI&#xff0c;有很多料号可直接PIN TO PIN&#xff0c;比如TPS562200(SOT23-6)\TPS563200(SOT23-6)/TPS54540/LMR140…

【nginx】nginx之location规则详解:

文章目录 一、语法规则&#xff1a;二、优先级&#xff1a;三、验证&#xff1a;1、精确匹配&#xff1a;2、通过^~方式实现匹配&#xff1a;3、通过”~”方式实现匹配&#xff1a;4、通过"~*"方式实现匹配:5、”!~*” 和”!~” 不常用&#xff0c;再次不做介绍6、通…

cocosCreator 之 Button

版本&#xff1a; 3.4.0 参考&#xff1a;Button组件 简介 Button组件主要用于响应用户的点击操作&#xff0c;属性检查器中的示意图&#xff1a; Button组件的主要属性有&#xff1a; Interactable 表示按钮是否可交互&#xff0c;如果未勾选表示禁用Transition表示按钮状态…

JDK9 接口特性(heima)

JDK9 接口特性&#xff08;heima&#xff09; 将log方法私有化

three.js-解决外部模型太暗的问题

先看效果 优化前 优化后的效果 在网上找了好久&#xff0c;好多方法都过时了&#xff0c;还有调整自发光都不行&#xff0c;后来又调金属度的&#xff0c;试了下很ok, child.material.metalness 0.58;&#xff0c;完整例子看下边。 解决方案 调整模型的金属度 loader.lo…

web前端tips:js继承——原型链继承

原型链继承 原型链继承是 JavaScript 中实现继承的一种方式&#xff0c;它通过使用原型来实现对象之间的继承关系。 在 JavaScript 中&#xff0c;每个对象都有一个原型&#xff08;prototype&#xff09;&#xff0c;它是一个指向另一个对象的引用。当我们访问一个对象的属性…

java项目之社区生活超市管理系统(ssm+mysql+jsp)

风定落花生&#xff0c;歌声逐流水&#xff0c;大家好我是风歌&#xff0c;混迹在java圈的辛苦码农。今天要和大家聊的是一款基于ssm的社区生活超市管理系统。技术交流和部署相关看文章末尾&#xff01; 开发环境&#xff1a; 后端&#xff1a; 开发语言&#xff1a;Java 框…

Redis高级篇(二)

Redis高级篇之多级缓存 什么是多级缓存 JVM进程缓存 Lua语法入门 实现多级缓存 缓存同步 一、什么是多级缓存 传统的缓存策略一般是请求到达Tomcat后&#xff0c;先查询Redis&#xff0c;如果未命中则查询数据库&#xff0c;如图&#xff1a; 存在下面的问题&#xff1a;…

TCP/UDP的首部

TCP/UDP首部信息 TCP首部第一个4字节第二个4字节与第三个4字节第四个4字节第五个4字节选项最大报文段长度&#xff08;MSS&#xff09;选项窗口扩大选项时间戳选项 什么时候发送RST包UDP首部 TCP首部 TCP 首部长度为20字节&#xff0c;加上选项部分最大可达60字节。 第一个4…

云原生|kubernetes|kubernetes集群部署神器kubekey安装部署高可用k8s集群(半离线形式)

前言&#xff1a; 云原生|kubernetes|kubernetes集群部署神器kubekey的初步使用&#xff08;centos7下的kubekey使用&#xff09;_晚风_END的博客-CSDN博客 前面利用kubekey部署了一个简单的非高可用&#xff0c;etcd单实例的kubernetes集群&#xff0c;经过研究&#xff0c;…

STM32MP157驱动开发——LED 驱动( GPIO 子系统)

文章目录 编写思路GPIO子系统的LED驱动程序(stm32mp157)如何找到引脚功能和配置信息在设备树中添加 Pinctrl 信息leddrv.cledtest.cMakefile编译测试 编写思路 阅读&#xff1a;STM32MP157驱动开发——GPIO 和 和 Pinctrl 子系统的概念可知利用GPIO子系统去编写LED驱动&#x…

【每日一题】—— B. Ternary String (Educational Codeforces Round 87 (Rated for Div. 2))

&#x1f30f;博客主页&#xff1a;PH_modest的博客主页 &#x1f6a9;当前专栏&#xff1a;每日一题 &#x1f48c;其他专栏&#xff1a; &#x1f534; 每日反刍 &#x1f7e1; C跬步积累 &#x1f7e2; C语言跬步积累 &#x1f308;座右铭&#xff1a;广积粮&#xff0c;缓称…

华为数通HCIP-OSPF基础

路由协议 作用&#xff1a;用于路由设备学习非直连路由&#xff1b; 动态路由协议&#xff1a;使路由设备自动学习到非直连路由&#xff1b; 分类&#xff1a; 按照算法分类&#xff1a; 1、距离矢量路由协议&#xff1b;&#xff08;RIP、BGP&#xff09; 只交互路由信息…

了解 3DS MAX 3D摄像机跟踪设置:第 4 部分

推荐&#xff1a; NSDT场景编辑器助你快速搭建可二次开发的3D应用场景 1. 项目设置 步骤 1 打开“后效”。 打开后效果 步骤 2 转到合成>新合成以创建新合成。 将“宽度”和“高度”值分别设置为 1280 和 720。将帧速率设置为 25&#xff0c;将持续时间设置为 12 秒。单…

前端开发中的常见优化

目录 外观 兼容 不同尺寸&#xff08;包裹&#xff0c;height:100%&#xff09; 不同 浏览器 隐藏滚动条 的 不同属性名 重排->重绘 不显示 display:none->禁用disable 性能 导航重复&#xff08;修改原型push、replace方法&#xff09; 搜索防抖 import { debo…

LLM - Chinese-Llama-2-7b 初体验

目录 一.引言 二.模型下载 三.快速测试 四.训练数据 五.总结 一.引言 自打 LLama-2 发布后就一直在等大佬们发布 LLama-2 的适配中文版&#xff0c;也是这几天蹲到了一版由 LinkSoul 发布的 Chinese-Llama-2-7b&#xff0c;其共发布了一个常规版本和一个 4-bit 的量化版本…

Animator Animator Controller Avatar relationship

Animator 组件用于将动画分配给场景中的游戏对象。Animator 需要对Animator Controller 的引用&#xff0c;该控制器定义要使用的动画剪辑&#xff0c;并控制何时以及如何在它们之间混合和过渡。 如果 GameObject 是具有 Avatar 定义的人形角色&#xff0c;则 Avatar 也应在此组…