120_员工管理系统:首页实现


addViewControllers实现无业务逻辑跳转

package com.qing.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 保留Spring Boot MVC功能,并且扩展其他MVC配置
 */
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {

    /**
     * addViewControllers实现无业务逻辑跳转
     * 将请求映射为视图,又因为thymeleaf默认提供的视图解析器,映射到template目录下
     * / 映射为 index 再映射为 /templates/index.html
     * /index.html 映射为 index 映射为 /templates/index.html
     * @param registry
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/index.html").setViewName("index");
    }
}

image.png
image.png
image.png

静态资源引入

定义thymeleaf命名空间
引入静态资源:.css,.svg

image.png

/代表classpath根目录,/css 映射为 /static/css
th:为thymeleaf标签


/** 映射到 classpath:/META-INF/resources/ ; classpath:/resources/ ; classpath:/static/ ; classpath:/public/
如:http://localhost:8080/1.js 映射到 resources/public/1.js


image.png

注意点:所有页面的静态资源都需要使用thymeleaf接管,即@{}

如:th:href="@{/css/bootstrap.min.css}"
好处:如果设置项目路径后,静态资源路径会自动添加项目路径

# 关闭模板引擎的缓存
spring.thymeleaf.cache=false
# 设置项目路径
server.servlet.context-path=/kuang

image.png

image.png

posted @   清风(学习-踏实)  阅读(43)  评论(0)    收藏  举报
点击右上角即可分享
微信分享提示