阅读完需:约 1 分钟
在springboot中有些页面是没有数据的所以不需要渲染,只要路径跳转就可以了,介绍两种跳转方法:
总目录:

第一种:
我们先写一个HelloController
文件
@Controller
public class HelloController {
@GetMapping("/hello")
public String hello(){
return "hello";
}
}
再创建hello.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>hello spring boot!</h1>
</body>
</html>
跳转结果:

第二种:
我们可以不需要 HelloController
,直接写一个WebMvcConfig
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/cn").setViewName("hello");
}
}
结果:

关于WebMvcConfigurer 接口的更多方法: