springBoot优雅返回图片/网页到浏览器
一、普通spring mvc返回图片或网页到浏览器
- @Controller
- @RequestMapping(value = "/image")
- public class ImageController {
- @RequestMapping(value = "/get")
- @ResponseBody
- public void getImage(HttpServletResponse response) throws IOException {
- File file = new File("D:/test.jpg");
- FileInputStream inputStream = new FileInputStream(file);
- byte[] bytes = new byte[inputStream.available()];
- response.setContentType("image/jpeg");
- OutputStream out = response.getOutputStream();
- out.write(result);
- out.flush();
- //关闭响应输出流
- out.close();
- }
- }
二、spring boot
- import org.springframework.http.MediaType;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.ResponseBody;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.IOException;
- @Controller
- @RequestMapping(value = "/image")
- public class ImageController {
- @RequestMapping(value = "/get",produces = MediaType.IMAGE_JPEG_VALUE)
- @ResponseBody
- public byte[] getImage() throws IOException {
- File file = new File("D:/test.jpg");
- FileInputStream inputStream = new FileInputStream(file);
- byte[] bytes = new byte[inputStream.available()];
- inputStream.read(bytes, 0, inputStream.available());
- return bytes;
- }
- }
如果是网页的话,
- produces = MediaType.TEXT_HTML
springBoot优雅返回图片/网页到浏览器的更多相关文章
- SpringMVC中controller返回图片(转)
本文转自:http://blog.csdn.net/u011637069/article/details/51112187 SpringMVC中controller通过返回ModelAndView然后 ...
- SpringBoot优雅的全局异常处理
前言 本篇文章主要介绍的是SpringBoot项目进行全局异常的处理. SpringBoot全局异常准备 说明:如果想直接获取工程那么可以直接跳到底部,通过链接下载工程代码. 开发准备 环境要求 JD ...
- SpringBoot基于websocket的网页聊天
一.入门简介正常聊天程序需要使用消息组件ActiveMQ或者Kafka等,这里是一个Websocket入门程序. 有人有疑问这个技术有什么作用,为什么要有它?其实我们虽然有http协议,但是它有一个缺 ...
- springboot集成websocket实现向前端浏览器发送一个对象,发送消息操作手动触发
工作中有这样一个需示,我们把项目中用到代码缓存到前端浏览器IndexedDB里面,当系统管理员在后台对代码进行变动操作时我们要更新前端缓存中的代码怎么做开始用想用版本方式来处理,但这样的话每次使用代码 ...
- 在屏幕上搜索图片并返回图片所在位置的坐标的AutoHotkey脚本源代码(类似大漠插件)
;~ 在屏幕上搜索图片并返回图片所在位置的坐标的AutoHotkey脚本源代码(类似大漠插件) ; https://www.autohotkey.com/boards/viewtopic.php?t ...
- 图片在ie8浏览器打不开,其他浏览器都可以打开的问题
问题描述: 1.图片在IE8浏览器打不开,但是IE8以上及其他浏览器均可以打开: 2.同一网站,其他图片可以在IE8浏览器打开 解决办法: 1.图片的颜色模式是CMYK模式,应改为RGB模式 2.修改 ...
- 检测访问网页的浏览器呈现引擎、平台、Windows操作系统、移动设备和游戏系统
/** * Author: laixiangran. * Created by laixiangran on 2015/12/02. * 检测访问网页的浏览器呈现引擎.平台.Windows操作系统.移 ...
- ExtJS-Viewport背景图片铺满浏览器视图并自动伸缩
var viewport = Ext.create('Ext.container.Viewport', { style : 'background-image:url(login_bj.jpg);ba ...
- MVC返回图片
这几天忙着一些小事,也没有写什么了,今天,我们来玩一个比较简单的东东.就是在MVC下如何返回图片,相信,在传统WebForm下,大家都晓得怎么弄,方也不限于一种,但是,在架构较为严格的MVC里面,刚开 ...
随机推荐
- tonight i need your body
wdnmd wdnmd 再lable中我们有几个不同的type参数: text 写的是文本类型的参数 password 不管输入的是什么显示的都是星星 date 输入的是一个日历本 ...
- BUUCTF RE部分题目wp
RE 1,easyre拖进ida,得到flag 2,helloworld 将文件拖入apk改之理,得到flag 3,xor拖进ida,就是简单异或,写脚本 glo=[0x66,0x0a,0x6b,0x ...
- android 批量加载数据
public class MainActivity extends Activity { private ListView listView; private List<String> d ...
- miaosha
1:跨域请求配置 后端Controller 添加注解 @CrossOrigin(origins = {"*"},allowCredentials = "true" ...
- 浅谈HTTP与其工作流程
一.什么是HTTP协议 HTTP协议(Hyper Text Transfer Protocol)翻译过来是超文本传输协议,也是一种restful风格的协议,在web开发和APP接口开发都很常用. HT ...
- 【CSS】text-align:justify 的使用
工作需要写一个全是文本的网页,规范格式的时候发现很多css属性不是很熟悉,比如text-align:justify. 这个是两端对齐,css3中新增了text-justify属性 语法:text-ju ...
- input | button | textarea 元素的checked, disabled,hidden属性控制
这三种元素涉及到的checked, disabled,hidden属性的控制方法如下 一.attribute方法: //以下3行,都会影响HTML的( checked | disabled | hid ...
- linux中的read_link
readlink是linux系统中一个常用工具,主要用来找出符号链接所指向的位置. readlink 获取当前进程对应proc/self/exe]:shell中 readlink /proc/sel ...
- concurrent=false/true的定时任务job策略介绍
前言: 四种测试情况,cronExpression = 0/30 * * * * ? : 1,一个trigger,job设置的是每30s执行一次,实际需要75s:concurrent=false: 2 ...
- magento 多域名多店
在magento1.4中请参考官网 :http://www.magentocommerce.com/knowledge-base/entry/tutorial-multi-site-multi-dom ...