每个网址路由和子路由的春季单页“a** => aindex.html,astatic**除外”

每个网址路由和子路由的春季单页“a** => aindex.html,astatic**除外”,第1张

每个网址路由和子路由的春季单页“ / a / ** => /a/index.html,/a/static/**除外”

现在我正在使用自定义

ResourceResolver
来解决这个问题

演示:https :
//github.com/varren/spring-react-example

@Configurationpublic class baseWebMvcConfigurerAdapter extends WebMvcConfigurerAdapter {    @Override    public void addResourceHandlers(ResourceHandlerRegistry registry) {        ResourceResolver resolver = new AdminResourceResolver();        registry.addResourceHandler("/admin/**")     .resourceChain(false)     .addResolver(resolver);        registry.addResourceHandler("/admin/")     .resourceChain(false)     .addResolver(resolver);    }    private class AdminResourceResolver implements ResourceResolver {        private Resource index = new ClassPathResource("/admin/index.html");        @Override        public Resource resolveResource(HttpServletRequest request, String requestPath, List<? extends Resource> locations, ResourceResolverChain chain) { return resolve(requestPath, locations);        }        @Override        public String resolveUrlPath(String resourcePath, List<? extends Resource> locations, ResourceResolverChain chain) { Resource resolvedResource = resolve(resourcePath, locations); if (resolvedResource == null) {     return null; } try {     return resolvedResource.getURL().toString(); } catch (IOException e) {     return resolvedResource.getFilename(); }        }        private Resource resolve(String requestPath, List<? extends Resource> locations) { if(requestPath == null) return null; if (!requestPath.startsWith("static")) {     return index; }else{     return new ClassPathResource("/admin/" + requestPath); }        }    }}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5153659.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-18
下一篇 2022-11-18

发表评论

登录后才能评论

评论列表(0条)

保存