1、创建SpringBoot,选择Web模块,并快速编写Controller完成测试
2、引入静态资源,动态资源改造页面
static放静态资源:css/img/js
templates放页面,交由模板引擎操作
读博客:静态资源映射规则
3、引用模板引擎
引入Thymeleaf依赖
4、项目测试,由模板引擎访问到页面
启动主程序类,访问http://localhost:8080/login
说明模板引擎生效
正常开发,像这些不带数据的页面(带数据都是Controller来实现),都是由SpringMVC来控制页面跳转,下面实现此功能
扩展SpringMVC功能,创建MyMvcConfig类实现接口WebMvcConfigurer,实现方法addViewControllers
如下
package com.xue.springbootweb.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* @Description
* 扩展SpringMVC功能
* @Author xuexue
* @Date 2019/10/14 9:16
*/
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/login").setViewName("login");
}
}
同样启动测试,一样访问,结果一样。
5、更多流程,待完善..