一、編寫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);
}
}
三、啓動訪問測試