写了一个配置类,扩展Spring MVC:
package com.ckh.springboot04.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
//继承WebMvcConfigurerAdapter扩展mvc
@Configuration
public class MyMvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
//浏览器发送 “/index” 请求,来到 success
registry.addViewController("/ckh").setViewName("success");
}
}
由于没有理解这句话的意思,导致出错。
registry.addViewController("/ckh").setViewName("success");
实际上,这是在往组件里加一个视图控制器,当你访问localhost:8080/ckh时,会跳转到success.html这个页面,
我没有写名为success的页面,所以显示网页找不到。
那么,实际这个扩展配置类通常的作用是,写一个配置类用于首页的跳转:
registry.addViewController("/").setViewName("index");