一、编写controller,有一个get请求
/**
* 返回登录模板
* @param model
* @return
*/
@GetMapping(value = "/login")
public String login(Model model) {
return "login";
}
二、编写配置类,将访问指向要设置的首页
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
public class MVCConfiguration extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("forward:/login");
registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
super.addViewControllers(registry);
}
}
三、启动访问测试

还没有评论,来说两句吧...