栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何使用Spring MVC返回视频,以便可以使用html5 标签进行导航?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用Spring MVC返回视频,以便可以使用html5 标签进行导航?

处理非静态资源的简单解决方案:

@SpringBootApplicationpublic class DemoApplication {    private final static File MP4_FILE = new File("/home/ego/bbb_sunflower_1080p_60fps_normal.mp4");    public static void main(String[] args) {        SpringApplication.run(DemoApplication.class, args);    }    @Controller    final static class MyController {        @Autowired        private MyResourceHttpRequestHandler handler;        // supports byte-range requests        @GetMapping("/")        public void home(     HttpServletRequest request,     HttpServletResponse response        ) throws ServletException, IOException { request.setAttribute(MyResourceHttpRequestHandler.ATTR_FILE, MP4_FILE); handler.handleRequest(request, response);        }        // does not support byte-range requests        @GetMapping(path = "/plain", produces = "video/mp4")        public FileSystemResource plain() { return new FileSystemResource(MP4_FILE);        }    }    @Component    final static class MyResourceHttpRequestHandler extends ResourceHttpRequestHandler {        private final static String ATTR_FILE = MyResourceHttpRequestHandler.class.getName() + ".file";        @Override        protected Resource getResource(HttpServletRequest request) throws IOException { final File file = (File) request.getAttribute(ATTR_FILE); return new FileSystemResource(file);        }    }}

(受Spring Boots LogFileMvcEndpoint的启发,并且或多或少等于我稍后发现的Paul-Warrens(@ paul-warren)StoreByteRangeHttpRequestHandler)。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/398687.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号