首页 文章

Thymeleaf和静态内容

提问于
浏览
0

我正在开发一个Spring Boot项目,其中Thymeleaf被用作模板引擎 . 我正在为这个项目设置Swagger,所以我希望能够在我的Thymeleaf内容中提供静态内容 .

“example.com/help”应该返回一个模板 .

“example.com/docs”应返回静态内容 .

目前这个:

@RequestMapping("/docs")
    public String index() {
        return "index.html";
    }

返回:

org.thymeleaf.exceptions.TemplateInputException:解析模板“index.html”时出错,模板可能不存在或任何已配置的模板解析器可能无法访问

我不希望Thymeleaf解决这条道路 .

1 回答

  • 1

    简单回答:如果您不希望Thymeleaf / Spring MVC处理您的请求,那么请不要问它:)

    更长的答案:当您在控制器中使用 @RequestMapping 时,通常会填写一些模型并告诉Spring MVC使用视图来渲染该模型(这就是Thymeleaf的用武之地) .

    如果要使用服务静态资源,则必须以不同方式对其进行配置 . 这是一个例子:

    @Component
    class WebConfigurer extends WebMvcConfigurerAdapter {
        @Override
        public void addResourceHandlers(ResourceHandlerRegistry registry) {
             registry.addResourceHandler("/docs/**").addResourceLocations("file://path/to/yourDocs/");
        }
    
    }
    

相关问题