问题:如何在SpringBoot中使用view-controller
- 首先:创建一个配置类,实现WebMvcConfigurer接口
-
package com.boot.config; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; /** * @Author zzz * @Date 2022/2/15 15:57 * @Version 1.0 */ @Configuration public class MyWebMvcConfig implements WebMvcConfigurer {
/**
* 目前只需要实现 addViewControllers() 方法
*/
@Override public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController("/").setViewName("index"); } }
-
浙公网安备 33010602011771号