springboot默认的欢迎页面设置

1.新建MVCConfiguration类,代码如下:

/*** mvc设置** @Auther: chenkai* @Date: 2019/3/13 0013 09:24* @Description:*/
@Configuration
public class MVCConfiguration extends WebMvcConfigurationSupport {@Overridepublic void addViewControllers(ViewControllerRegistry registry) {registry.addViewController("/").setViewName("forward:/index");registry.setOrder(Ordered.HIGHEST_PRECEDENCE);super.addViewControllers(registry);}
}

2.新建hello.html,目录为:resources/templates

 

3. 新建controller控制器,此处配置的thymeleaf模板配置

/*** 首页控制类* @Auther: chenkai* @Date: 2019/3/13 0013 09:15* @Description:*/
@Controller
public class IndexController {@RequestMapping(value = "/index")public String hello(Model model) {model.addAttribute("name", "Tom");return "hello";}
}

4. 访问地址:http://localhost:8080/,如图:

本文链接:https://my.lmcjl.com/post/979.html

展开阅读全文

4 评论

留下您的评论.