当前位置: 首页 > news >正文

网站如何防止别人抄袭wordpress 语言插件

网站如何防止别人抄袭,wordpress 语言插件,设计本质,网站建设初期工作方案一、实现方式 在Java中#xff0c;导出数据到Excel有多种方式#xff0c;每种方式都有其优缺点#xff0c;适用于不同的场景。以下是常见的几种方式及其特点#xff1a; 1.1 Apache POI Apache POI 是 Java 中最流行的库#xff0c;支持读写 Excel 文件#xff08;包括…一、实现方式 在Java中导出数据到Excel有多种方式每种方式都有其优缺点适用于不同的场景。以下是常见的几种方式及其特点 1.1 Apache POI Apache POI 是 Java 中最流行的库支持读写 Excel 文件包括 .xls 和 .xlsx 格式。 特点 支持 .xlsHSSFWorkbook和 .xlsxXSSFWorkbook、SXSSFWorkbook。功能强大支持样式、公式、图表等。SXSSFWorkbook 支持流式写入适合大数据量导出。 适用场景 需要导出复杂格式的 Excel 文件。大数据量导出使用 SXSSFWorkbook。 1.2 EasyExcel EasyExcel 是阿里巴巴开源的 Excel 操作库基于 Apache POI 封装专注于大数据量导出和导入。 特点 支持流式读写内存占用低。API 简单易用。支持 .xlsx 格式。 适用场景 大数据量导出百万级数据。需要高性能和低内存占用的场景。 1.3 OpenCSV 虽然不是直接导出 Excel 文件但 CSV 文件可以被 Excel 直接打开适合简单的数据导出。 特点 轻量级速度快。文件格式简单不支持样式、公式等。适合纯数据导出。 适用场景 数据量较大且不需要复杂格式。需要快速导出和导入。 二、使用SXSSFWorkbook 2.1 添加依赖 在pom.xml中添加Apache POI依赖 dependencygroupIdorg.apache.poi/groupIdartifactIdpoi-ooxml/artifactIdversion5.2.3/version /dependency dependencygroupIdorg.apache.poi/groupIdartifactIdpoi-ooxml-schemas/artifactIdversion4.1.2/version /dependency2.2 定义数据模型 创建一个 Java 类表示导出的数据模型。 public class DataModel {private Long id;private String name;private Double value;// 构造方法、Getter 和 Setterpublic DataModel(Long id, String name, Double value) {this.id id;this.name name;this.value value;}public Long getId() {return id;}public void setId(Long id) {this.id id;}public String getName() {return name;}public void setName(String name) {this.name name;}public Double getValue() {return value;}public void setValue(Double value) {this.value value;} }2.3 分页查询数据 使用Spring Data JPA或MyBatis进行分页查询。 import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service;Service public class DataService {Autowiredprivate DataRepository dataRepository;public PageDataEntity getDataByPage(int page, int size) {Pageable pageable PageRequest.of(page, size);return dataRepository.findAll(pageable);} }2.4 多线程导出数据 使用线程池并行处理分页查询和数据写入。 import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;import java.io.FileOutputStream; import java.io.IOException; import java.util.List; import java.util.concurrent.*;Service public class ExcelExportService {Autowiredprivate DataService dataService;// 线程池配置private final ExecutorService executorService Executors.newFixedThreadPool(10);public void exportLargeDataToExcel(String filePath, int pageSize) throws IOException, InterruptedException, ExecutionException {// 创建 SXSSFWorkbook设置内存中保留的行数默认100try (SXSSFWorkbook workbook new SXSSFWorkbook(100)) {Sheet sheet workbook.createSheet(Sheet1);// 创建表头Row headerRow sheet.createRow(0);headerRow.createCell(0).setCellValue(ID);headerRow.createCell(1).setCellValue(Name);headerRow.createCell(2).setCellValue(Value);// 计算总页数long totalCount dataService.getTotalCount();int totalPages (int) Math.ceil((double) totalCount / pageSize);// 使用 CountDownLatch 等待所有线程完成CountDownLatch latch new CountDownLatch(totalPages);// 提交任务到线程池for (int page 0; page totalPages; page) {final int currentPage page;executorService.submit(() - {try {// 分页查询数据PageDataModel dataPage dataService.getDataByPage(currentPage, pageSize);ListDataModel dataList dataPage.getContent();// 写入当前页数据synchronized (sheet) {int startRow currentPage * pageSize 1; // 数据从第2行开始for (int i 0; i dataList.size(); i) {DataModel data dataList.get(i);Row row sheet.createRow(startRow i);row.createCell(0).setCellValue(data.getId());row.createCell(1).setCellValue(data.getName());row.createCell(2).setCellValue(data.getValue());}}} finally {latch.countDown(); // 任务完成}});}// 等待所有线程完成latch.await();// 写入文件try (FileOutputStream outputStream new FileOutputStream(filePath)) {workbook.write(outputStream);}// 清理临时文件workbook.dispose();}// 关闭线程池executorService.shutdown();} }2.5 调用导出方法 在Controller或Service中调用导出方法。 import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;import java.io.IOException; import java.util.concurrent.ExecutionException;RestController RequestMapping(/export) public class ExportController {Autowiredprivate ExcelExportService excelExportService;GetMapping(/excel)public String exportToExcel() throws IOException, InterruptedException, ExecutionException {String filePath large_data_export.xlsx;excelExportService.exportLargeDataToExcel(filePath, 10000); // 每页查询10000条数据return Export successful! File saved at: filePath;} }三、使用EasyExcel 3.1 添加依赖 在 pom.xml 中添加 EasyExcel 依赖 dependencygroupIdcom.alibaba/groupIdartifactIdeasyexcel/artifactIdversion3.3.2/version /dependency3.2 定义数据模型 创建一个 Java 类表示导出的数据模型。 import com.alibaba.excel.annotation.ExcelProperty;public class DataModel {ExcelProperty(ID)private Long id;ExcelProperty(Name)private String name;ExcelProperty(Value)private Double value;// 构造方法、Getter 和 Setterpublic DataModel(Long id, String name, Double value) {this.id id;this.name name;this.value value;}public Long getId() {return id;}public void setId(Long id) {this.id id;}public String getName() {return name;}public void setName(String name) {this.name name;}public Double getValue() {return value;}public void setValue(Double value) {this.value value;} }3.3 分页查询数据 使用 Spring Data JPA 或 MyBatis 进行分页查询。 import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service;Service public class DataService {Autowiredprivate DataRepository dataRepository;public PageDataModel getDataByPage(int page, int size) {Pageable pageable PageRequest.of(page, size);return dataRepository.findAll(pageable);} }3.4 多线程导出数据 使用线程池并行处理分页查询和数据写入。 import com.alibaba.excel.EasyExcel; import com.alibaba.excel.write.metadata.WriteSheet; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.List; import java.util.concurrent.*;Service public class ExcelExportService {Autowiredprivate DataService dataService;// 线程池配置private final ExecutorService executorService Executors.newFixedThreadPool(10);public void exportLargeDataToExcel(HttpServletResponse response, int pageSize) throws IOException, InterruptedException, ExecutionException {// 设置响应头response.setContentType(application/vnd.ms-excel);response.setCharacterEncoding(utf-8);String fileName large_data_export.xlsx;response.setHeader(Content-Disposition, attachment;filename fileName);// 创建 Excel 写入器WriteSheet writeSheet EasyExcel.writerSheet(Sheet1).head(DataModel.class).build();// 计算总页数int totalPages (int) Math.ceil((double) dataService.getTotalCount() / pageSize);// 使用 CountDownLatch 等待所有线程完成CountDownLatch latch new CountDownLatch(totalPages);// 提交任务到线程池for (int page 0; page totalPages; page) {final int currentPage page;executorService.submit(() - {try {// 分页查询数据PageDataModel dataPage dataService.getDataByPage(currentPage, pageSize);ListDataModel dataList dataPage.getContent();// 写入当前页数据EasyExcel.write(response.getOutputStream(), DataModel.class).sheet(Sheet1).doWrite(dataList);} catch (IOException e) {e.printStackTrace();} finally {latch.countDown(); // 任务完成}});}// 等待所有线程完成latch.await();// 关闭线程池executorService.shutdown();} }3.5 Controller 调用导出方法 在 Controller 中调用导出方法。 import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.concurrent.ExecutionException;RestController RequestMapping(/export) public class ExportController {Autowiredprivate ExcelExportService excelExportService;GetMapping(/excel)public void exportToExcel(HttpServletResponse response) throws IOException, InterruptedException, ExecutionException {excelExportService.exportLargeDataToExcel(response, 10000); // 每页查询10000条数据} }四、使用OpenCSV 4.1 添加依赖 在 pom.xml 中添加 OpenCSV 依赖 dependencygroupIdcom.opencsv/groupIdartifactIdopencsv/artifactIdversion5.8/version /dependency4.2 定义数据模型 创建一个 Java 类表示导出的数据模型。 public class DataModel {private Long id;private String name;private Double value;// 构造方法、Getter 和 Setterpublic DataModel(Long id, String name, Double value) {this.id id;this.name name;this.value value;}public Long getId() {return id;}public void setId(Long id) {this.id id;}public String getName() {return name;}public void setName(String name) {this.name name;}public Double getValue() {return value;}public void setValue(Double value) {this.value value;} }4.3 分页查询数据 使用 Spring Data JPA 或 MyBatis 进行分页查询。 import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service;Service public class DataService {Autowiredprivate DataRepository dataRepository;public PageDataModel getDataByPage(int page, int size) {Pageable pageable PageRequest.of(page, size);return dataRepository.findAll(pageable);}public long getTotalCount() {return dataRepository.count();} }4.4 多线程导出数据 使用线程池并行处理分页查询和数据写入。 import com.opencsv.CSVWriter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.concurrent.*;Service public class CsvExportService {Autowiredprivate DataService dataService;// 线程池配置private final ExecutorService executorService Executors.newFixedThreadPool(10);public void exportLargeDataToCsv(String filePath, int pageSize) throws IOException, InterruptedException, ExecutionException {// 创建 CSV 写入器try (CSVWriter writer new CSVWriter(new FileWriter(filePath))) {// 写入表头writer.writeNext(new String[]{ID, Name, Value});// 计算总页数long totalCount dataService.getTotalCount();int totalPages (int) Math.ceil((double) totalCount / pageSize);// 使用 Future 保存每个线程的查询结果ListFutureListDataModel futures new ArrayList();// 提交任务到线程池for (int page 0; page totalPages; page) {final int currentPage page;FutureListDataModel future executorService.submit(() - {PageDataModel dataPage dataService.getDataByPage(currentPage, pageSize);return dataPage.getContent();});futures.add(future);}// 合并所有线程的查询结果并写入 CSVfor (FutureListDataModel future : futures) {ListDataModel dataList future.get();for (DataModel data : dataList) {writer.writeNext(new String[]{String.valueOf(data.getId()),data.getName(),String.valueOf(data.getValue())});}}}// 关闭线程池executorService.shutdown();} }4.5 Controller 调用导出方法 在 Controller 中调用导出方法。 import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;import java.io.IOException; import java.util.concurrent.ExecutionException;RestController RequestMapping(/export) public class ExportController {Autowiredprivate CsvExportService csvExportService;GetMapping(/csv)public String exportToCsv() throws IOException, InterruptedException, ExecutionException {String filePath large_data_export.csv;csvExportService.exportLargeDataToCsv(filePath, 10000); // 每页查询10000条数据return Export successful! File saved at: filePath;} }
http://www.ho-use.cn/article/10823917.html

相关文章:

  • 网站的流程图南通旅游网站建设
  • 关于网站建设的pptwordpress商家展示主题
  • 网站建设方案合同考幼师证去哪个网站做试题
  • 网站开发工程师特点广告公司岗位
  • 网站二级目录做优化百度指数是什么
  • 中小型网站建设多少钱糟糕的网站设计
  • PHP做的哪些大型网站广州网络公司
  • 昆明网站建设推广公司哪家好ae在线生成视频
  • 企业站模板大全郑州网络营销公司排名
  • 设计比较好的企业网站网站建设任职资格
  • 网站改版做301是啥意思 换域名孝感注册公司
  • 合肥网站建设讯息同一个ip网站太多 seo
  • 东莞网站如何制作中国企业网银怎么登录
  • 辽宁城乡建设厅网站学做古典家具网站
  • 用仿站工具做网站电话号码查询企业
  • 想在微信公众号上做网站链接上海网址一360导航
  • 什么是网站策划书如何搭建个人博客网站
  • 网站如何绑定域名江西企业网站建设电话
  • 基础网站建设代码如何建立学校网站
  • 企业网站建设维护合同书wordpress fifth
  • 宠物用品网站建设自己做的网站怎么放到外网上
  • 金属东莞网站建设技术支持品牌建设指导性意见
  • 网站设计改版深圳猪八戒网站建设
  • 长春网站建设方案详细wordpress什么主题好
  • 深圳极速网站建设服务上海市住房与城乡建设部网站
  • 南昌专业做网站公司网站建设吧个好
  • 怎么免费开网站建设工程检测网
  • 苏州住房和城乡建设局网站如何在网站上添加备案号
  • 什么网站做一手房比较好秦皇岛最新消息今天
  • 什么网站上做效果图可以赚钱杨小刀网站建设