@RequestMapping("/index")
    public  String hello(){

        return "index";
    }

 

此处无任何的业务处理,只是简单的页面跳转,写了至少三行有效的代码,在实际的开发中会涉及大量这样的页面转向,若都这样写会特别的麻烦,我们通过在配置类MyMvcConfig里通过重写addViewControllers来简化配置:

 

public class MyMvcConfig extends WebMvcConfigurerAdapter {

......... @Override
public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController("/index").setViewName("/index");
    registry.addViewController("/toUpload").setViewName("/upload");
    registry.addViewController("/converter").setViewName("/converter");
} }

 

相关文章:

  • 2021-09-12
  • 2021-12-04
  • 2021-11-16
  • 2022-01-16
  • 2021-12-21
猜你喜欢
  • 2021-09-04
  • 2022-12-23
  • 2022-01-17
  • 2021-11-22
  • 2021-10-22
  • 2021-07-26
相关资源
相似解决方案