springboot自定义视图映射

2022年12月4日08:55:39

在项目开发过程中,经常会涉及页面跳转问题,而且这个页面跳转没有任何业务逻辑过程,只是单纯的路由过程 ( 例如:点击一个按钮跳转到一个页面 )

正常的写法是这样的:

@RequestMapping("/testmvc")
 public String view(){
    return "abc";
 }

现在只需要这样统一写,此类必须在启动类所在包或者子包中

@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter{
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/testmvc").setViewName("/abc");
    }
}

页面:abc.flt 或者 abc.html

<html>
<body>
    hello
</body>
</html>

  • 作者:沐宇熙
  • 原文链接:https://blog.csdn.net/qq_31463999/article/details/81628825
    更新时间:2022年12月4日08:55:39 ,共 432 字。