中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

怎樣做服務(wù)型網(wǎng)站萬能軟文范例800字

怎樣做服務(wù)型網(wǎng)站,萬能軟文范例800字,WordPress推送服務(wù),網(wǎng)頁設(shè)計論文html一、項目場景 項目中要實現(xiàn)交易報表,處理大規(guī)模數(shù)據(jù)導(dǎo)出時,出現(xiàn)單個Excel文件過大導(dǎo)致性能下降的問題,需求是導(dǎo)出大概四千萬條數(shù)據(jù)到Excel文件,不影響正式環(huán)境的其他查詢。 二、方案 1.使用讀寫分離,查詢操作由從庫…
一、項目場景

項目中要實現(xiàn)交易報表,處理大規(guī)模數(shù)據(jù)導(dǎo)出時,出現(xiàn)單個Excel文件過大導(dǎo)致性能下降的問題,需求是導(dǎo)出大概四千萬條數(shù)據(jù)到Excel文件,不影響正式環(huán)境的其他查詢。

二、方案
1.使用讀寫分離,查詢操作由從庫處理
2.數(shù)據(jù)分批查詢
3.異步導(dǎo)出數(shù)據(jù)
4.生成和拆分多個Excel文件
三、實現(xiàn)

1.pom.xml中添加以下依賴:


<dependencies><!-- Spring Boot Starter Data JPA --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-jpa</artifactId></dependency><!-- Spring Boot Starter Async --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- Apache POI for Excel --><dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId></dependency>
</dependencies>

包括SpringBoot、Spring Data JPA、異步處理相關(guān)的依賴,以及用于生成Excel文件的Apache POI庫。

2.application.properties中加入數(shù)據(jù)庫配置,以及異步任務(wù)執(zhí)行器的配置:

# Database configuration
spring.datasource.url=jdbc:mysql://localhost:3306/yourdatabase
spring.datasource.username=yourusername
spring.datasource.password=yourpassword
# Async configuration
spring.task.execution.pool.core-size=10
spring.task.execution.pool.max-size=20
spring.task.execution.pool.queue-capacity=500
spring.task.execution.thread-name-prefix=Async-thread

3.使用從庫進行查詢
減輕主庫的查詢壓力,建議在架構(gòu)上使用讀寫分離,查詢操作由從庫處理。這樣可以確保主庫的操作性能和其他接口查詢不受影響。

@Service
public class DataService {@Autowiredprivate DataRepository dataRepository;public List<Data> fetchData(int offset, int limit) {return dataRepository.findAll(PageRequest.of(offset, limit)).getContent();}
}

4.數(shù)據(jù)分批查詢策略
防止一次性查詢大量數(shù)據(jù)導(dǎo)致內(nèi)存溢出,采用分頁查詢的方式,每次查詢部分?jǐn)?shù)據(jù)進行處理。

@Service
public class DataExportService {@Autowiredprivate DataService dataService;@Asyncpublic void exportData() {int pageSize = 10000;int pageNumber = 0;List<Data> dataBatch;do {dataBatch = dataService.fetchData(pageNumber, pageSize);if (!dataBatch.isEmpty()) {// 導(dǎo)出數(shù)據(jù)到ExcelexportToExcel(dataBatch, pageNumber);}pageNumber++;} while (!dataBatch.isEmpty());}
}

5.異步任務(wù)配置
通過@EnableAsync注解啟用異步任務(wù),并配置一個任務(wù)執(zhí)行線程來單獨執(zhí)行導(dǎo)出任務(wù)。

@Configuration
@EnableAsync
public class AsyncConfig implements AsyncConfigurer {@Overridepublic Executor getAsyncExecutor() {ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();executor.setCorePoolSize(10);executor.setMaxPoolSize(20);executor.setQueueCapacity(500);executor.setThreadNamePrefix("Async-");executor.initialize();return executor;}
}

6.導(dǎo)出任務(wù)接口實現(xiàn)
使用@Async注解將導(dǎo)出任務(wù)的方法標(biāo)記為異步執(zhí)行。

@Service
public class DataExportService {@Autowiredprivate DataService dataService;@Asyncpublic void exportData() {// 數(shù)據(jù)查詢和導(dǎo)出的邏輯}
}

7.生成和拆分Excel文件
使用Apache POI處理Excel,查詢到的數(shù)據(jù)批次,將數(shù)據(jù)分成多個Excel文件,避免單個文件過大。

public void exportToExcel(List<Data> dataBatch, int batchNumber) {Workbook workbook = new XSSFWorkbook();Sheet sheet = workbook.createSheet("Data");int rowNum = 0;for (Data data : dataBatch) {Row row = sheet.createRow(rowNum++);row.createCell(0).setCellValue(data.getId());row.createCell(1).setCellValue(data.getName());// 其他數(shù)據(jù)列}try (FileOutputStream fos = new FileOutputStream("data_batch_" + batchNumber + ".xlsx")) {workbook.write(fos);} catch (IOException e) {e.printStackTrace();}
}
http://www.risenshineclean.com/news/6870.html

相關(guān)文章:

  • 東莞網(wǎng)站建設(shè)電鍍掛具怎么讓百度快速收錄網(wǎng)站
  • 廣州海珠建網(wǎng)站怎么做好網(wǎng)絡(luò)推廣銷售
  • 做網(wǎng)站在哪個地方買空間網(wǎng)絡(luò)營銷是網(wǎng)上銷售嗎
  • 建筑三級資質(zhì)可承接工程范圍win7優(yōu)化
  • wordpress如何修改評論網(wǎng)頁搜索優(yōu)化seo
  • 絕對域名做網(wǎng)站軟文營銷的概念
  • 沒有網(wǎng)站備案可以做誠信認(rèn)證嘛市場調(diào)研分析報告范文
  • asp.net 企業(yè)網(wǎng)站系統(tǒng)百度站長收錄提交入口
  • 江門網(wǎng)站設(shè)計網(wǎng)站推廣多少錢一年
  • 山東青島疫情最新情況信息流廣告優(yōu)化師
  • 做低價的跨境電商網(wǎng)站百度競價推廣開戶多少錢
  • 如何取消wordpress限制搜索引擎優(yōu)化大致包含哪些內(nèi)容或環(huán)節(jié)
  • 中國建設(shè)銀行網(wǎng)站評價西安關(guān)鍵詞優(yōu)化服務(wù)
  • 免費空間網(wǎng)站推薦百度地圖網(wǎng)頁版進入
  • 寧波有哪家公司做網(wǎng)站的2023年火爆的新聞
  • html購物網(wǎng)站重慶關(guān)鍵詞優(yōu)化服務(wù)
  • 珠海企業(yè)網(wǎng)站推廣服務(wù)找關(guān)鍵詞的方法與技巧
  • 網(wǎng)站開發(fā)跟軟件開發(fā)如何在百度搜索到自己的網(wǎng)站
  • 專業(yè)網(wǎng)站設(shè)計開發(fā)網(wǎng)站互聯(lián)網(wǎng)廣告投放代理公司
  • 做h5的網(wǎng)站有哪些php開源建站系統(tǒng)
  • 東莞住房和建設(shè)局網(wǎng)站外貿(mào)業(yè)務(wù)推廣
  • 設(shè)計網(wǎng)站公司為什么都在上海淘寶運營培訓(xùn)多少錢
  • wordpress單本小說站seo主要優(yōu)化哪些
  • 南皮網(wǎng)站建設(shè)南寧網(wǎng)站建設(shè)及推廣
  • 公司設(shè)計網(wǎng)站需要注意哪些sem優(yōu)化是什么意思
  • 無錫做網(wǎng)站價格方象科技的企業(yè)愿景
  • 漢口網(wǎng)站制作怎么開發(fā)一個網(wǎng)站
  • 百度站點提交工具app開發(fā)工具
  • 網(wǎng)站建設(shè)的單可以刷嗎磁力多多
  • 資訊類網(wǎng)站建設(shè)網(wǎng)站生成器