Spring Boot 报错:This application has no explicit mapping for /error

Write a configuration class that extends 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");
    }
}

Since there is no understanding of what this means, resulting in an error.

registry.addViewController("/ckh").setViewName("success");

In fact, this component is in Riga to a view controller, when you visit localhost: 8080 / ckh time, will jump to success.html this page,
I did not write a page called success, so the displayed web page can not be found.

Well, actually this is usually extended configuration class role is to write a class configured for Jump homepage:

registry.addViewController("/").setViewName("index");
Released six original articles · won praise 3 · Views 534

Guess you like

Origin blog.csdn.net/bulubulua/article/details/104760945