zoukankan      html  css  js  c++  java
  • SpringBoot设置首页(默认页)跳转功能的实现方案

    最近springboot开发需要设置个默认页面,要直接跳转到登录页面。

    方案1:controller里添加一个"/"的映射路径

    @RequestMapping("/")
    public String index(Model model, HttpServletResponse response) {
      model.addAttribute("name", "simonsfan");
      return "/index";
    }
    

    方案二:设置默认的View跳转页面

    @Configuration
    public class DefaultView extends WebMvcConfigurerAdapter {
      @Override
      public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
        super.addViewControllers(registry);
      }
    }
    

      

    @Configuration
    public class DefaultView extends WebMvcConfigurerAdapter{
      @Override
      public void addViewControllers(ViewControllerRegistry registry) {
        super.addViewControllers(registry);
        //主页
        registry.addViewController("/").setViewName("forward:/index");
      } 
    }
    

      

  • 相关阅读:
    Linux--VSFTP服务搭建
    Linux--Smba服务搭建
    Linux--DHCP搭建
    编程语言的分类
    用户,组及权限
    linux常用基本命令整理小结
    数据结构之顺序表实现
    进程管理之system
    进程管理之wait和waitpid
    进程管理之fork函数
  • 原文地址:https://www.cnblogs.com/yachao1120/p/12520787.html
Copyright © 2011-2022 走看看