スプリングブーツのThymeleafテンプレート注入

参照:

ここに写真の説明を挿入

ここに写真の説明を挿入

シーンは、ビューの名前がユーザーが制御できる場合です。

実際のテストでは、デフォルトのThymeleafバージョンに関連するSpringbootのバージョンに関連していることがわかりました。

spring boot:1.5.1.RELEASE spring-boot-starter-thymeleaf:2.1.5
spring boot:2.0.0.RELEASE spring-boot-starter-thymeleaf:3.0.9
spring boot:2.2.0.RELEASE spring-boot-スターター-thymeleaf:3.0.11

thymeleafの3.xバージョンのみが影響を受けます。


renderFragment3.xバージョンのthymeleaf-spring5は次のようになります。

            if (!viewTemplateName.contains("::")) {
    
    
                templateName = viewTemplateName;
                markupSelectors = null;
            } else {
    
    
                IStandardExpressionParser parser = StandardExpressions.getExpressionParser(configuration);

                FragmentExpression fragmentExpression;
                try {
    
    
                    fragmentExpression = (FragmentExpression)parser.parseExpression(context, "~{" + viewTemplateName + "}");
                } catch (TemplateProcessingException var25) {
    
    
                    throw new IllegalArgumentException("Invalid template name specification: '" + viewTemplateName + "'");
                }

そして2.xthymeleaf-spring4はこんな感じです

                Configuration configuration = viewTemplateEngine.getConfiguration();
                ProcessingContext processingContext = new ProcessingContext(context);
                templateCharacterEncoding = getStandardDialectPrefix(configuration);
                StandardFragment fragment = StandardFragmentProcessor.computeStandardFragmentSpec(configuration, processingContext, viewTemplateName, templateCharacterEncoding, "fragment");
                if (fragment == null) {
    
    
                    throw new IllegalArgumentException("Invalid template name specification: '" + viewTemplateName + "'");
                }

おすすめ

転載: blog.csdn.net/caiqiiqi/article/details/108446723