当前位置:网站首页>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

边栏推荐
- Live broadcast software app development, uniapp scroll view hidden scroll bar
- SQL注入 Less29(参数污染绕过WAF)
- CMOS传输门原理及应用
- Massive data TOPK problem
- Vs2019 release mode debugging: this expression has side effects and will not be evaluated.
- What is the employment prospect of software testing?
- How to learn object Defineproperty | an article takes you to quickly learn
- 【二叉树】统计二叉树中好节点的数目
- 九天后我们一起,聚焦音视频、探秘技术新发展
- 视频直播源码,uni-app实现广告滚动条
猜你喜欢

Alibaba Senior Software Testing Engineer recommends testers to learn -- Introduction to security testing

Polarization relay

How can anyone ask how MySQL archives data?

The design idea of relational database is obvious to you in 20 pictures

SQL注入 Less26a(布尔盲注)

软件测试的就业前景到底怎么样?

基于简化的评分卡、Smote采样和随机森林的信贷违约预测

How to deal with high concurrency deadlock?

Excel only wants to visualize charts and make data move? Yes, come and watch (with a large number of templates to download)

每条你收藏的资讯背后,都离不开TA
随机推荐
项目分析(从技术到项目、产品)
EC code introduction
Deepfake's face is hard to distinguish between true and false, and musk Fenke has disguised successfully
Drawing three coordinate (axis) diagram with MATLAB
Wireshark filter rule notes, with software
Implementation of arbitrary code execution based on.Net dynamic compilation technology
Encapsulate an array into a class
Wechat applet live broadcast plug-in -- get temporary files (background integrated applet live broadcast)
Credit default prediction based on simplified scorecard, smote sampling and random forest
直播app系统源码,上下叠层样式的轮播图
Leetcode-155-minimum stack
直播软件app开发,uniapp scroll-view隐藏滚动条
Yyds dry goods inventory # solve the real problem of famous enterprises: cycle number comparison
Live video source code, uni app to achieve advertising scroll bar
Cocoapods reload
How can anyone ask how MySQL archives data?
基于简化的评分卡、Smote采样和随机森林的信贷违约预测
温度继电器
Temperature relay
vs2019 release模式调试:此表达式有副作用,将不予计算。