Springboot & Mybatis 构建restful 服务四
Springboot & Mybatis 构建restful 服务四
1 前置条件
成功执行完Springboot & Mybatis 构建restful 服务三
2 restful service 添加 Apache POI生成 Excel 文件
1)修改 POM.xml文件
添加 Apache POI 的依赖
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.5-FINAL</version>
</dependency>
2)在SY里添加创建 excel 文件的方法
src/main/java/com/serena/controller/SY.java
@ApiOperation(value="查询所有账户余额等信息,并导出在 excel 表格中")
@RequestMapping(value="/accountsfile",method = RequestMethod.GET)
public boolean wSelectAll(HttpServletResponse response){
logg.info("write a file that select accounts ");
List<SettleAccount> list = null;
boolean flag = false;
// 获取所有账户信息
list = iSY.selectAccounts();
// 判断是否存在账户
if(list == null)
logg.warn("not found accounts");
else{
// 创建表对象
HSSFWorkbook workBook = new HSSFWorkbook();
ServletOutputStream fileOut = null;
try {
// 获取输出流对象
fileOut = response.getOutputStream();
// 创建 sheet
HSSFSheet sheet = workBook.createSheet();
// 设置表格第一行的字段名
HSSFRow row = sheet.createRow(0);
int i =1;
row.createCell(0).setCellValue("账户编号");
row.createCell(1).setCellValue("账户名");
row.createCell(2).setCellValue("客户编号");
row.createCell(3).setCellValue("短信余额");
for (SettleAccount acc : list) {
HSSFRow rowi = sheet.createRow(i++);
rowi.createCell(0).setCellValue(acc.getAccountcode());
rowi.createCell(1).setCellValue(acc.getAccountname());
rowi.createCell(2).setCellValue(acc.getCustomercode());
rowi.createCell(3).setCellValue(acc.getSmsnum().doubleValue());
}
workBook.write(fileOut);
return true;
} catch (FileNotFoundException e) {
logg.error("create table error ---- " + e.getMessage());
e.printStackTrace();
return false;
} catch (IOException e) {
logg.error("create table error ---- " + e.getMessage());
e.printStackTrace();
return false;
} finally {
try {
fileOut.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return flag;
}
5)在终端输入如下测试指令:
#cd 项目所在目录
cd /Users/psj/Documents/pro/xm/AccountBalance
mvn clean package
cd target
mkdir /Users/psj/Desktop/t/
#将 tar 包复制到自己指定目录(/Users/psj/Desktop/t/)
cp AccountBalance-0.0.1-SNAPSHOT.tar /Users/psj/Desktop/t/
#cd 到上个操作指定的目录
cd /Users/psj/Desktop/t
#解压 tar 包
tar -xvf AccountBalance-0.0.1-SNAPSHOT.tar
#此时可查看目录结构如要求所示
ll
#运行 可执行jar,测试结果
java -jar AccountBalance-0.0.1-SNAPSHOT.jar
#
#打开浏览器
http://localhost:8999/accountsfile
#在下载对话框中指定文件名和保存路径
#
#返回上个 iterm 窗口,control+c 结束服务
Springboot & Mybatis 构建restful 服务四的更多相关文章
- Springboot & Mybatis 构建restful 服务五
Springboot & Mybatis 构建restful 服务五 1 前置条件 成功执行完Springboot & Mybatis 构建restful 服务四 2 restful ...
- Springboot & Mybatis 构建restful 服务三
Springboot & Mybatis 构建restful 服务三 1 前置条件 成功执行完Springboot & Mybatis 构建restful 服务二 2 restful ...
- Springboot & Mybatis 构建restful 服务二
Springboot & Mybatis 构建restful 服务二 1 前置条件 成功执行完Springboot & Mybatis 构建restful 服务一 2 restful ...
- Springboot & Mybatis 构建restful 服务
Springboot & Mybatis 构建restful 服务一 1 前置条件 jdk测试:java -version maven测试:命令行之行mvn -v eclipse及maven插 ...
- 基于SpringBoot开发一个Restful服务,实现增删改查功能
前言 在去年的时候,在各种渠道中略微的了解了SpringBoot,在开发web项目的时候是如何的方便.快捷.但是当时并没有认真的去学习下,毕竟感觉自己在Struts和SpringMVC都用得不太熟练. ...
- jersey+maven构建restful服务
一.新建一个Maven Web项目 a) 新建一个简单的Maven项目 b) 将简单的Maven项目转成Web项目 (若没出现further configuration available--或里面的 ...
- 用Jersey构建RESTful服务7--Jersey+SQLServer+Hibernate4.3+Spring3.2
一.整体说明 本例执行演示了用 Jersey 构建 RESTful 服务中.怎样集成 Spring3 二.环境 1.上文的项目RestDemo 2.Spring及其它相关的jar ,导入项目 三.配置 ...
- JAX-RS(基于Jersey) + Spring 4.x + MyBatis构建REST服务架构
0. 大背景 众所周知,REST架构已经成为现代服务端的趋势. 很多公司,已经采用REST作为App, H5以及其它客户端的服务端架构. 1. 什么是JAX-RS? JAX-RS是JAVA EE6 引 ...
- 使用spring mvc或者resteasy构建restful服务
看到最近一个项目里用resteasy来构建restful接口,有点不明白,不少Spring mvc4.0以后也可以很方面的实现restful服务吗,为啥还要在Spring MVC的项目里还引入rest ...
随机推荐
- cdh启动datanode报错
问题: 为cdh新增节点时,在分配datanode后,启动报错 Can't open /iot/opt/cloudera-manager/cm-5.11.2/run/cloudera-scm-agen ...
- v-charts 第一次亲密接触
v-charts是什么鬼 v-charts是饿了么团队开源的一个图表库,vue+echarts开发.用element-ui直接集成echarts有些费劲,而v-charts已经封装成vue组件,可以直 ...
- thinkphp5.1 退出登陆操作
使用Session:: 静态方法即可
- Xilinx Zynq ZC-702 开发(02)—— 通过 Xilinx SDK 调试 Linux 应用
远程调试环境由 PC 上运行的 System Debugger(集成在 Xilinx SDK 中) 和 Zynq 板上运行的 Linux TCF Agent 共同构成, 两者通过 TCP 连接,架构图 ...
- Traceback (most recent call last): File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\Packages\ptvsd\_vendored\pydevd\_pydevd_bundle\pyd
某次编码,debug的时候突然突然突然给我报这个错: Traceback (most recent call last): File "c:\program files (x86)\mi ...
- Hadoop学习笔记记录
NameNode的介绍: NameNode是HDFS的核心,也称为master,它仅存储元数据(文件系统中所有文件的目录树) NameNode不存储实际的数据或数据集,数据本身存储在DateNodes ...
- 一条分页的SQL语句
1.概述 在网页中如果显示的数据太多就会占据过多的页面,而且显示速度也会很慢.为了控制每次在页面上显示数据的数量,就可以利用分页来显示数据. 2.技术要点 在SQL Server中要实现SQL分页,需 ...
- Codeforces Round #436 B. Polycarp and Letters
题意:给你一串长度为n的字符,由大小写字母组成,求连续的小写子串中不同字母个数的最大值. Input 11aaaaBaabAbA Output 2 Input 12zACaAbbaazzC Outpu ...
- linux下ping不通问题的说明与解决(DNS配置丢失)
一.出现问题的原因 最近由于linux需要使用外网,发现ping不通地址,经过一番查找分析后发现是DNS服务配置丢失,在这里有两种方法可以解决该问题. 1:你可以手动修改/etc/sysconfig/ ...
- yum与rpm常用命令
1 yum常用命令 2 rpm常用命令 1 yum常用命令 (1)列出所有可更新的软件清单命令:yum check-update (2)更新所有软件命令:yum update (4)仅安装指定的 ...