第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Thymeleaf:將 webjar CSS 文件的內(nèi)容插入樣式標(biāo)簽

Thymeleaf:將 webjar CSS 文件的內(nèi)容插入樣式標(biāo)簽

大話西游666 2021-09-15 15:43:42
在某些情況下,內(nèi)聯(lián) CSS 文件比通過 URL 引用它更受歡迎(例如,在呈現(xiàn)包含所有內(nèi)容的 HTML 頁(yè)面時(shí))。該 CSS 文件可能來自 webjar。我需要什么才能撥打這樣的電話:<style th:insert="/webjars/bootstrap/bootstrap.css"></style>這是在 spring-boot 環(huán)境中運(yùn)行的,沒有任何網(wǎng)絡(luò)服務(wù)器。
查看完整描述

1 回答

?
慕娘9325324

TA貢獻(xiàn)1783條經(jīng)驗(yàn) 獲得超4個(gè)贊

所以我讓它與一個(gè)特殊的 TemplateResolver 一起工作。它的邏輯類似于 Spring 的WebJarsResourceResolver,并且使用WebJarAssetLocator.


public class WebJarTemplateResolver extends ClassLoaderTemplateResolver {


    private final static String WEBJARS_PREFIX = "/webjars/";


    private final static int WEBJARS_PREFIX_LENGTH = WEBJARS_PREFIX.length();


    private final WebJarAssetLocator webJarAssetLocator = new WebJarAssetLocator();


    @Override

    protected ITemplateResource computeTemplateResource(IEngineConfiguration configuration, String ownerTemplate, String template, String resourceName, String characterEncoding, Map<String, Object> templateResolutionAttributes) {


        resourceName = findWebJarResourcePath(template);

        if (resourceName == null) {

            return null;

        }


        return super.computeTemplateResource(configuration, ownerTemplate, template, resourceName, characterEncoding, templateResolutionAttributes);

    }


    @Nullable

    protected String findWebJarResourcePath(String templateName) {

        if (!templateName.startsWith(WEBJARS_PREFIX)) {

            return null;

        }


        int startOffset = WEBJARS_PREFIX_LENGTH;

        int endOffset = templateName.indexOf('/', startOffset);


        if (endOffset == -1) {

            return null;

        }


        String webjar = templateName.substring(startOffset, endOffset);

        String partialPath = templateName.substring(endOffset + 1);

        return this.webJarAssetLocator.getFullPathExact(webjar, partialPath);

    }

}

這通過以下配置集成到應(yīng)用程序中:


@Configuration

public class ThymeleafConfiguration {


    private SpringTemplateEngine templateEngine;


    public ThymeleafConfiguration(SpringTemplateEngine templateEngine) {

        this.templateEngine = templateEngine;

    }


    @PostConstruct

    public void enableWebjarTemplates() {

        templateEngine.addTemplateResolver(new WebJarTemplateResolver());

    }

}


查看完整回答
反對(duì) 回復(fù) 2021-09-15
  • 1 回答
  • 0 關(guān)注
  • 198 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)