springboot自定义视图映射

10次阅读
没有评论

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

正常的写法是这样的:

@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>

正文完
 0