步骤一:
首先,在templates文件夹西创建一个文件“index.html”(名字任意取)
步骤二:创建一个名为“MyMvcConfig.java”的class文件。
其内容如下:
package com.example.demo.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry)
{
registry.addViewController("/").setViewName("index");
registry.addViewController("/index.html").setViewName("index");
}
}
这样就能直接通过本地ip访问,不用加路径了