@Configuration
@Controller
public class IndexConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("forward:/index.htm");
registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
super.addViewControllers(registry);
}
@RequestMapping(value = "/index.htm", method = RequestMethod.GET)
public ModelAndView index(HttpServletRequest request, HttpServletResponse response) throws IOException {
ModelAndView view = new ModelAndView();
view.setViewName("index");
return view;
}
}
可以根据需求拆分成两个类。