spring boot — InputStream
@Component
public class TextFileDownloadView extends AbstractFileDownloadView {
@Override
protected InputStream getInputStream(Map<String, Object> model,
HttpServletRequest request) throws IOException {
Resource resource = new ClassPathResource("abc.txt");
return resource.getInputStream();
}
@Override
protected void addResponseHeader(Map<String, Object> model,
HttpServletRequest request, HttpServletResponse response) {
response.setHeader("Content-Disposition", "attachment; filename=abc.txt");
response.setContentType("text/plain");
}
}
@RequestMapping(value = "/downloadTxt", method = RequestMethod.GET)
public String downloadTxt1() {
return "textFileDownloadView";
}
Originate from http://rensanning.iteye.com/blog/2356942
package inputstream; import java.io.IOException;
import java.io.InputStream; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import inputstream.domain.Customer; @RestController
public class InputStreamController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @RequestMapping(value = "" , method = RequestMethod.GET , produces = MediaType.APPLICATION_JSON_VALUE )
public InputStream testClassPath() throws IOException {
Resource resource = new ClassPathResource("test.txt");
String fileName = resource.getFilename();
logger.info(fileName);
// resource.getFile(); //获取资源对应的文件
// resource.getURL(); //获取资源对应的URL
//每次都会打开一个新的流
InputStream is = resource.getInputStream();
//this.printContent(is);
logger.info(is.toString());
return is;
} @RequestMapping(value = "/cs" , method = RequestMethod.GET , produces = MediaType.APPLICATION_JSON_VALUE )
public Customer testCustomer() {
Customer c = new Customer(5,"Tom");
return c; } }
http://www.cnblogs.com/wangtj-19/p/5889056.html
spring boot — InputStream的更多相关文章
- Spring Boot整合Activiti,查看流程图出现中文乱码问题
最近研究SpringBoot 整合Activiti时,实现流程图高亮追踪是出现中文乱码问题,找了很多方法,现在把我最后的解决方法提供给大家. Spring Boot是微服务快速开发框架,强调的是零配置 ...
- Spring Boot 启动原理分析
https://yq.aliyun.com/articles/6056 转 在spring boot里,很吸引人的一个特性是可以直接把应用打包成为一个jar/war,然后这个jar/war是可以直接启 ...
- Spring Boot的properties配置文件读取
我在自己写点东西玩的时候需要读配置文件,又不想引包,于是打算扣点Spring Boot读取配置文件的代码出来,当然只是读配置文件没必要这么麻烦,不过反正闲着也是闲着,扣着玩了.具体启动过程以前的博客写 ...
- Spring Boot 2.x 编写 RESTful API (五) 单元测试
用Spring Boot编写RESTful API 学习笔记 概念 驱动模块 被测模块 桩模块 替代尚未开发完毕的子模块 替代对环境依赖较大的子模块 (例如数据访问层) 示例 测试 Service @ ...
- 从.Net到Java学习第十篇——Spring Boot文件上传和下载
从.Net到Java学习系列目录 图片上传 Spring Boot中的文件上传就是Spring MVC中的文件上传,将其集成进来了. 在模板目录创建一个新的页面 profile/uploadPage. ...
- Spring Boot整合邮件发送
概述 Spring Boot下面整合了邮件服务器,使用Spring Boot能够轻松实现邮件发送:整理下最近使用Spring Boot发送邮件和注意事项: Maven包依赖 <dependenc ...
- 【Spring Boot】关于上传文件例子的剖析
目录 Spring Boot 上传文件 功能实现 增加ControllerFileUploadController 增加ServiceStorageService 增加一个Thymeleaf页面 修改 ...
- Spring boot 配置https 实现java通过https接口访问
近来公司需要搭建一个https的服务器来调试接口(服务器用的spring boot框架),刚开始接触就是一顿百度,最后发现互联网认可的https安全链接的证书需要去CA认证机构申请,由于是调试阶段就采 ...
- spring boot生成的war包运行时出现java.lang.NullPointerException: null
最近写了一个数据库同步的程序,见之前的博客,没有用到spring框架来集成,用的时纯Java代码.然后,项目经理要我把程序合到spring boot框架中,因为涉及到多数据源,时间又比较紧,同意我直接 ...
随机推荐
- RVDS4.0 + JLINK 调试 cortex-A9
1.RVDS4.0的安装与破解 参看http://blog.csdn.net/cp1300/article/details/7772645这位大神的帖子吧,写的很详细. 2.JLINK驱动的安装 这里 ...
- jsp页面报错(一)
jsp页面报错 1.错误位置 <form action="../page/areaType.action" method="POST"> <j ...
- 使用ffserver实现转发实时流媒体(摄像头捕获)
本系统为ubuntu 10.04LTS 说明1:本实验在本机成功测试通过: 说明2:本实验仅仅测试了视频流,未测试音频流. 1.配置ffserver.conf -------------------- ...
- Windows控制台下绘制简单图形
最近接触到一个很有意思的问题,如何在Windows控制台下画图,翻遍了C的头文件也没找到画图的函数,好吧,那就用Windows提供的API函数吧,看来想移植是没戏了.先画一个简单的图,类似心电图那种吧 ...
- freemarker基本数据类型
freemarker基本数据类型 1.基本数据类型 (1)字符串 (2)数字 (3)布尔值 (4)日期 2.展示示例 <html> <head> <meta http-e ...
- org.hibernate.exception.ConstraintViolationException
1.错误描述 Caused by:org.hibernate.exception.ConstraintViolationException:Could not execute JDBC batch u ...
- python做基本的图像处理
PIL是python中的图像处理类库,为python提供了基本的图像处理和基本操作.而PIL中最重要的就是Image模块,下面给出具体的例子来理解此模块. 读取一幅图像 我们用Image模块中的ope ...
- linux shell 基本规范
开头指定脚本解释器 #!/bin/bash 或 #!/bin/sh 开头加版权信息 #Date: 2017-8-01 22:50 #Author: yang qiang wei #Mail: xxx@ ...
- springboot--springboot+mybatis多数据源最简解决方案
说起多数据源,一般都来解决那些问题呢,主从模式或者业务比较复杂需要连接不同的分库来支持业务.我们项目是后者的模式,网上找了很多,大都是根据jpa来做多数据源解决方案,要不就是老的spring多数据源解 ...
- 【CF932G】Palindrome Partition(回文树,动态规划)
[CF932G]Palindrome Partition(回文树,动态规划) 题面 CF 翻译: 给定一个串,把串分为偶数段 假设分为了\(s1,s2,s3....sk\) 求,满足\(s_1=s_k ...