SpringBoot不使用模板引擎直接返回Html怎么配置?

SpringBoot不使用模板引擎直接返回Html怎么配置?

阅读 12.8k
3 个回答
@Configuration
public class MvcConfigurer extends WebMvcConfigurerAdapter {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/home").setViewName("home.html");
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
    }

    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        super.configurePathMatch(configurer);
        configurer.setUseSuffixPatternMatch(false);//当此参数设置为true的时候,那么/user.html,/user.aa,/user.*都能是正常访问的。
    }
}

在resource目录下面建立public文件夹,里面方静态页面

访问路径为/xx.html

在Controller里面直接return "xx.html"

你找到解决的办法了吗?我也遇到这个问题

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题