zoukankan      html  css  js  c++  java
  • SpringBoot 与 Web开发

    1. SpringBoot 静态资源映射规则

    • webjars:以JAR包的方式引入静态资源;
    • 所有/webjars/**,都去classpath:/META-INF/resources/webjars/目录下加载资源;
    • /**访问当前项目的任何资源(即静态资源文件夹)
      • classpath:/META-INF/resources/
      • classpath:/resources/,
      • classpath:/static/,
      • classpath:/public/,
      • /:当前项目的根路径
    // WebMvcAutoConfiguration.java
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        if (!this.resourceProperties.isAddMappings()) {
            logger.debug("Default resource handling disabled");
            return;
        }
        Integer cachePeriod = this.resourceProperties.getCachePeriod();
        if (!registry.hasMappingForPattern("/webjars/**")) {
            customizeResourceHandlerRegistration(registry
                    .addResourceHandler("/webjars/**")
                    .addResourceLocations("classpath:/META-INF/resources/webjars/")
                    .setCachePeriod(cachePeriod));
        }
        String staticPathPattern = this.mvcProperties.getStaticPathPattern();
        if (!registry.hasMappingForPattern(staticPathPattern)) {
            customizeResourceHandlerRegistration(
                    registry.addResourceHandler(staticPathPattern)
                            .addResourceLocations(
                                    this.resourceProperties.getStaticLocations())
                            .setCachePeriod(cachePeriod));
        }
    }
    

    2. Thymeleaf 模板引擎

    • SpringBoot 引入 Thymeleaf 模板引擎
    // pom.xml
    
    <properties>
        <!-- 切换 thymeleaf 版本 --
        <thymeleaf.version>3.0.9.RELEASE</thymeleaf.version>
        <thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout-dialect.version>
    </properties>
    
    <dependency>
    	<groupId>org.springframework.boot</groupId>
    	<artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    
    
    // classpath:/templates/, 存放HTML页面
    success.html
    
    // 编写Controller
    @RequestMapping("/success")
    public String success(){
        return "success";
    }
    

    参考资料:

  • 相关阅读:
    C++利用SOAP开发WebService
    C++中使用soap toolkit访问webService详解
    第一次课堂作业之Circle
    第四次作业(计算器第二步)
    第三次作业之Calculator项目随笔
    C++视频课程小结(3)
    C++视频课程小结(2)
    C++视频课程小结(1)
    第二次作业之视频课程题
    第二次作业之编程题
  • 原文地址:https://www.cnblogs.com/linkworld/p/9142306.html
Copyright © 2011-2022 走看看