可以在 ViewControllerRegistry 中注册简单路径和模板文件的映射,就不需要单独在 Controller 里写了,如下:

@Configuration
public class WebConfig {
    @Bean
    public WebMvcConfigurer webMvcConfigurer() {
        return new WebMvcConfigurer() {
            @Override
            public void addViewControllers(ViewControllerRegistry registry) {
                registry.addViewController("/hello").setViewName("hello.html"); // hello 和 hello.html 都可以
            }
        };
    }
}

Configure simple automated controllers pre-configured with the response status code and/or a view to render the response body. This is useful in cases where there is no need for custom controller logic -- e.g. render a home page, perform simple site URL redirects, return a 404 status with HTML content, a 204 with no content, and more.

results matching ""

    No results matching ""