博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
springboot mvc beetl模板 自定义错误的后缀问题
阅读量:6889 次
发布时间:2019-06-27

本文共 1614 字,大约阅读时间需要 5 分钟。

@Componentpublic class BeetlErrorViewResolver implements ErrorViewResolver {	private static final Map
SERIES_VIEWS; @Value("${beetl.templatesPath:templates}") String templatesPath; @Value("${beetl.suffix:btl}") String suffix; private static ArrayList
errorFiles = new ArrayList
(); public void getErrorFiles() { if (errorFiles.isEmpty()) { String path = BeetlErrorViewResolver.class.getClassLoader().getResource("").getFile(); File templates = new File(path + templatesPath + "/error"); File[] files = templates.listFiles(); for (File file : files) { if (file.isFile()) errorFiles.add(file.getName()); } } } static { Map
views = new EnumMap<>(Series.class); views.put(Series.CLIENT_ERROR, "4xx"); views.put(Series.SERVER_ERROR, "5xx"); SERIES_VIEWS = Collections.unmodifiableMap(views); } @Override public ModelAndView resolveErrorView(HttpServletRequest request, HttpStatus status, Map
model) { ModelAndView modelAndView = resolve(String.valueOf(status), model); if (modelAndView == null && SERIES_VIEWS.containsKey(status.series())) { modelAndView = resolve(SERIES_VIEWS.get(status.series()), model); } return modelAndView; } private ModelAndView resolve(String viewName, Map
model) { viewName = viewName + "." + suffix; getErrorFiles(); try { for (String error : errorFiles) { if (error.equals(viewName)) return new ModelAndView("/error/" + viewName, model); } } catch (Exception ex) { } return null; }}

  

转载于:https://www.cnblogs.com/startnow/p/8818931.html

你可能感兴趣的文章
Thread类常用方法
查看>>
/etc/resolv.conf中内容被清空的解决办法
查看>>
Yarn大体框架和工作流程研究
查看>>
vue学习笔记(一)
查看>>
微软专家推荐11个Chrome 插件
查看>>
三天学会HTML5——SVG和Canvas的使用
查看>>
Azure 部署 Asp.NET Core Web App
查看>>
MySql基本操作(二)
查看>>
SaaS、PaaS和云计算 搅动未来软件发展
查看>>
App测试点
查看>>
运行jar包
查看>>
supervisor centos安装
查看>>
深入分析:Flash vs. HTML5 網路影音格式落誰家?
查看>>
带你领略Linux系统发展及版本更迭
查看>>
聊聊ES7与ES8特性
查看>>
尾调用
查看>>
Redis学习笔记
查看>>
Version 1.6.0 of the JVM is not suitable for the this product.Version:1.8 or greater is required
查看>>
《JAVA与模式》之责任链模式
查看>>
厉害了,龙果!开源中国颁发证书:GVP-码云最有价值开源项目(roncoo-pay)
查看>>