14 springboot项目——首页跳转实现
阿里云国内75折 回扣 微信号:monov8 |
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6 |
templates里的静态资源无法访问需要写mvc的配置类或者改application.xml配置文件实现首页访问。这两个方式用其中一种即可否则会冲突。
14.1 首页跳转方式一
创建配置类在config包中创建一个mvc的配置类
package jiang.com.springbootstudy.config;
import org.springframework.context.annotation.Configuration;
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.html");
}
}
14.2 首页跳转方式二
修改application.yaml配置文件server: servlert: context-path: /xxx注意这个方式最好不要用不然无法使用mvc配置类进行跳转
server:
port: 8080
servlet:
context-path: /kuang
student:
name: zhangsan
age: 18
arr: ["zhangsan","李四"]
spring:
thymeleaf:
cache: false