日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網(wǎng)為廣大站長(zhǎng)提供免費(fèi)收錄網(wǎng)站服務(wù),提交前請(qǐng)做好本站友鏈:【 網(wǎng)站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(wù)(50元/站),

點(diǎn)擊這里在線咨詢客服
新站提交
  • 網(wǎng)站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會(huì)員:747

本文介紹了每條url路徑和子路徑的Spring Single頁(yè)面/a/**=>/a/index.html/a/靜態(tài)/**&qot;除外的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我正在構(gòu)建Spring網(wǎng)站,該網(wǎng)站在子路徑下有反應(yīng)單頁(yè)應(yīng)用程序,我當(dāng)前的URL結(jié)構(gòu)應(yīng)該如下所示

localhost/admin/** => react app
localhost/**       => spring thymeleaf/rest/websocket app for everything else

react app mapping:
localhost/admin/static/**  => static react files
localhost/admin/**         => react index.html for everything else

Example of project resources structure:  
resources/
    admin/         <= my admin react files is here
        index.html
        static/    <= react css, js,  statics
    templates/     <= thymeleaf templates
    static/        <= theamleaf static
    ...

因此,我需要為每個(gè)URL路由及其子路由轉(zhuǎn)發(fā)REACTIONindex.html文件。除靜態(tài)文件外,基本上只有一個(gè)頁(yè)面的應(yīng)用程序

看起來(lái)像是一項(xiàng)常見(jiàn)的任務(wù),下面是我已經(jīng)嘗試過(guò)的一些方法:


項(xiàng)目的完整工作演示Spring+Reaction+Gradle如何構(gòu)建項(xiàng)目以及為什么我不能將Reaction文件放在不同的目錄(例如/Resources/Static):https://github.com/varren/spring-react-example


無(wú)法使用forward:/admin/index.htmlfor/admin/**,因?yàn)檫@將創(chuàng)建遞歸,因?yàn)?code>admin/index.html也在admin/**下,必須以某種方式截取admin/static/**


無(wú)法在WebMvcConfigurerAdapter

中使用addResourceHandlers

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/admin/**")
            .addResourceLocations("classpath:/admin/");
}

index.html僅映射到/admin/index.htmlurl,此選項(xiàng)幾乎有效,但僅當(dāng)您從localhost/admin/index.html訪問(wèn)Reaction應(yīng)用程序時(shí)


看到this和this和this和許多其他鏈接,我也有一些解決方案,但可能有一些通用選項(xiàng)我就是看不到

推薦答案

現(xiàn)在我正在使用自定義ResourceResolver來(lái)解決此問(wèn)題

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

@Configuration
public 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);
            }
        }
    }
}

這篇關(guān)于每條url路徑和子路徑的Spring Single頁(yè)面/a/**=&gt;/a/index.html/a/靜態(tài)/**&qot;除外的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,

分享到:
標(biāo)簽:html qot Spring 每條 路徑 靜態(tài) 頁(yè)面
用戶無(wú)頭像

網(wǎng)友整理

注冊(cè)時(shí)間:

網(wǎng)站:5 個(gè)   小程序:0 個(gè)  文章:12 篇

  • 51998

    網(wǎng)站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會(huì)員

趕快注冊(cè)賬號(hào),推廣您的網(wǎng)站吧!
最新入駐小程序

數(shù)獨(dú)大挑戰(zhàn)2018-06-03

數(shù)獨(dú)一種數(shù)學(xué)游戲,玩家需要根據(jù)9

答題星2018-06-03

您可以通過(guò)答題星輕松地創(chuàng)建試卷

全階人生考試2018-06-03

各種考試題,題庫(kù),初中,高中,大學(xué)四六

運(yùn)動(dòng)步數(shù)有氧達(dá)人2018-06-03

記錄運(yùn)動(dòng)步數(shù),積累氧氣值。還可偷

每日養(yǎng)生app2018-06-03

每日養(yǎng)生,天天健康

體育訓(xùn)練成績(jī)?cè)u(píng)定2018-06-03

通用課目體育訓(xùn)練成績(jī)?cè)u(píng)定