当前位置:网站首页>Chapter 3 business function development (choose to export market activities, Apache POI)
Chapter 3 business function development (choose to export market activities, Apache POI)
2022-07-27 22:21:00 【Make a light】
customer demand :
Users are on the main page of marketing activities , Select campaign to export , Click on " Choose export " Button , Generate one from all the selected data excel file , The dialog box of file download pops up ;
The user selects the directory to save , Complete the function of selecting and exporting marketing activities .
* Choose to export at least one record at a time
* After exporting successfully , The page does not refresh
Function development :
1. Draw according to customer needs UML Sequence diagram

2. Function development ,mapper layer
ActivityMapper Interface

ActivityMapper.xml

3.service layer
ActivityService Interface

ActivityServiceImpl

4.Controller layer
ActivityController
@RequestMapping(value = "/workbench/activity/queryCheckedActivity.do")
public void exportCheckedActivitys(HttpServletResponse response,HttpServletRequest request) throws IOException {
// To obtain parameters
String checkedIds = request.getParameter("checkedIds");
System.out.println(" Parameters obtained :" + checkedIds);
String[] ids = checkedIds.split(",");
// call service Layer method , according to id Inquire about market activities
List<Activity> activityList = activityService.queryCheckedActivity(ids);
// establish excel file , And the activityList write in excel file
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet(" List of campaigns ");
HSSFRow row = sheet.createRow(0);
HSSFCell cell;
// Header
String[] titles = {"ID", " owner ", " name ", " Start date ", " End date ", " cost ", " describe ", " Creation time ", " The creator ", " Modification time ", " Reviser "};
for (int i = 0; i < titles.length; i++) {
cell = row.createCell(i);
cell.setCellValue(titles[i]);
}
// Traverse the campaign items
if (activityList.size() > 0 && activityList != null) {
// Traverse activityList, establish HSSFRow object , Generate all data rows
Activity activity = null;
for (int i = 0; i < activityList.size(); i++) {
activity = activityList.get(i);
// Every time you traverse one activity, Generate a line
row = sheet.createRow(i + 1);
// Create each row 11 Column , The data in each column is from activity In order to get
cell = row.createCell(0);
cell.setCellValue(activity.getId());
cell = row.createCell(1);
cell.setCellValue(activity.getOwner());
cell = row.createCell(2);
cell.setCellValue(activity.getName());
cell = row.createCell(3);
cell.setCellValue(activity.getCreateTime());
cell = row.createCell(4);
cell.setCellValue(activity.getEndDate());
cell = row.createCell(5);
cell.setCellValue(activity.getCost());
cell = row.createCell(6);
cell.setCellValue(activity.getDescription());
cell = row.createCell(7);
cell.setCellValue(activity.getCreateTime());
cell = row.createCell(8);
cell.setCellValue(activity.getCreateBy());
cell = row.createCell(9);
cell.setCellValue(activity.getEditTime());
cell = row.createCell(10);
cell.setCellValue(activity.getEditBy());
}
}
// Generative excel Download the file to the client
response.setContentType("application/octet-stream;charset=UTF-8");
response.addHeader("Content-Disposition","attachment;filename=activityList.xls");
OutputStream out=response.getOutputStream();
wb.write(out);
// close resource
wb.close();
out.flush();
}5.activity Of index.jsp page
// Add a click event to the batch export button
$("#exportActivityAllBtn").click(function () {
window.location.href="workbench/activity/exportAllActivitys.do";
});
// Add a click event to the select export button
$("#exportActivityXzBtn").click(function () {
// Collection parameters
var checkIds=$("#tBody input[type='checkbox']:checked");
// validate form
if (checkIds.size()==0){
alert(" Select at least one piece of data to export ");
return;
}
// String concatenation
var checkedIds=[];
$.each(checkIds,function (i) {
checkedIds[i]=$(this).val();
});
window.location.href="workbench/activity/queryCheckedActivity.do?checkedIds="+checkedIds;
});A functional test :
Enter the campaign list page , Click to download the list data ( Choose export ), Will be automatically customized serverDir Generate excel file , Then download to the client , The excel The files in are completely from the database .
Click the select download button , When there is no choice , Pop up and select at least one campaign

Select two campaigns to download 
View the downloaded data

边栏推荐
- Leetcode-55-jump game
- Interview question: what are the functions of fail safe mechanism and fail fast mechanism
- 项目分析(从技术到项目、产品)
- 关系型数据库的设计思想,20张图给你看的明明白白
- 直播软件app开发,uniapp scroll-view隐藏滚动条
- 项目管理工具禅道
- Pytoch distributed training
- More than 100 lines should be split into functions
- A lock faster than read-write lock. Don't get to know it quickly
- 8000字讲透OBSA原理与应用实践
猜你喜欢

Interview question: talk about your understanding of AQS

What is the employment prospect of software testing?

2022 2nd cyber edge cup cyber security competition Web

SQL注入 Less29(参数污染绕过WAF)

It's too voluminous. A company has completely opened its core system (smart system) that has been operating for many years

Monitor the running of server jar and restart script

SQL注入 Less26a(布尔盲注)

Inventory Poka ecological potential project | cross chain characteristics to promote the prosperity of multi track

Learn the use principle and core idea of thread pool from the source code

Log4j vulnerability is still widespread and continues to cause impact
随机推荐
【无标题】
Reed relay
Seven lines of code crashed station B for three hours
Station B collapsed. What did the developer responsible for the repair do that night?
刚培训完的中级测试工程师如何快速度过试用期
An2021 software installation and basic operation (new file / export)
8000字讲透OBSA原理与应用实践
What is modcount in the source code? What's the effect
EC code introduction
光藕继电器
Leetcode 301. delete invalid parentheses
Open source data quality solution -- Apache Griffin primer
The source code of live broadcast app system, and the rotation diagram of upper and lower layers
MySQL series - database tables, queries, sorting, and data processing functions
8000字讲透OBSA原理与应用实践
Behind every piece of information you collect, you can't live without TA
High frequency relay
高频继电器
[Marine Science] climate indices data set
Starfish Os X MetaBell战略合作,元宇宙商业生态更进一步