统一路径映射

导入thymeleaf依赖

hello.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    hello
</body>
</html>

HelloController

@Controller
public class HelloController {

    @GetMapping("/hello")
    public String hello(){
        return "hello";
    }
}

统一注册 即可以不需要上面的controller

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/qwl").setViewName("hello");
    }
}

然后可以直接访问http://localhost:8080/qwl

posted @ 2020-08-05 20:56  柒丶月  阅读(68)  评论(0编辑  收藏  举报