1.创建配置类创建相关映射(/dashboard—>/main.html)
@Configuration public class MyConfig implements WebMvcConfigurer { @Override public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController("/").setViewName("index"); registry.addViewController("/index.html").setViewName("index"); registry.addViewController("/main.html").setViewName("dashboard"); } }
2.进入该页面时重定向进入
return "redirect:/main.html";//重定向进入
@Controller public class IndexController { @RequestMapping("/userin") private String UserIn(Model model, @RequestParam("username") String username , @RequestParam("password") String password, HttpSession session){ session.setAttribute("name",username); if(StringUtils.hasLength(username) && password.equals("123")){ return "redirect:/main.html";//重定向进入 }else { model.addAttribute("msg","用户名或密码错误"); return "index"; } } }
启动进入该页面隐藏成功
没有配置之前:
配置之后: