首页 > 其他分享 >230122_50_SpringBoot入门

230122_50_SpringBoot入门

时间:2023-01-22 22:44:58浏览次数:46  
标签:webjars SpringBoot classpath 50 registry 230122 org public resources

  • SpringBoot Web开发

jar:webapp!

自动装配

1.创建应用,选择模块

springboot到底帮我们配置了什么?我们能不能进行修改?能修改哪些东西?能不能扩展?

  • xxxAutoConfiguration..向容器中自动配置组件
  • xxxProperties:自动配置类,装配配置文件中自定义的一些内容!

要解决的问题:

  • 导入静态资源....

  • 首页

  • jsp,模块引擎Thymeleaf

  • 增删改查

  • 拦截器

  • 国际化!

  • 静态资源

  • 新建一个controller

package com.bill.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Auther: wangchunwen
 * @Date: 2023/1/22 - 01 - 22 - 20:57
 * @Description: com.bill.controller
 * @version: 1.0
 */

@RestController
public class ControllerHello {

    @RequestMapping("/hello")
    public String hello(){
        return "hello,springboot";
    }
}
public void addResourceHandlers(ResourceHandlerRegistry registry) {
   if (!this.resourceProperties.isAddMappings()) {
      logger.debug("Default resource handling disabled");
      return;
   }
   addResourceHandler(registry, "/webjars/**", "classpath:/META-INF/resources/webjars/");
   addResourceHandler(registry, this.mvcProperties.getStaticPathPattern(), (registration) -> {
      registration.addResourceLocations(this.resourceProperties.getStaticLocations());
      if (this.servletContext != null) {
         ServletContextResource resource = new ServletContextResource(this.servletContext, SERVLET_LOCATION);
         registration.addResourceLocations(resource);
      }
   });
}
  • 什么是webjars:WebJars是将客户端(浏览器)网络资源库(例如jQuery或者Bootstrap)打包成j的JAR文件
  • 以jquery为例,导入依赖
<dependency>
   <groupId>org.webjars</groupId>
   <artifactId>jquery</artifactId>
   <version>3.6.3</version>
</dependency>

目录结构相同:

  • 加载webjars下所有静态资源:
addResourceHandler(registry, "/webjars/**", "classpath:/META-INF/resources/webjars/");

测试结果:可以正常访问到该路径下的资源jquery.js

  • 其他可以加载静态资源的路径
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = { "classpath:/META-INF/resources/",
      "classpath:/resources/", "classpath:/static/", "classpath:/public/" };
  • 新建资源目录

  • 测试结果:

  • 优先级:resources > static > public

标签:webjars,SpringBoot,classpath,50,registry,230122,org,public,resources
From: https://www.cnblogs.com/wcwblog/p/17064761.html

相关文章

  • springboot的原理
    SpringBoot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程,该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板......
  • SpringBoot配置文件详解
    简介SpringBoot全局配置文件默认为src/main/resources下的application.properties,后缀可以改为yml,如果application.yml和application.properties两个配置文件都存在,那么,p......
  • Docker 部署 SpringBoot 项目
    Dockerfilehouse.jar为jar包名称/data为存放路径FROMlpicanco/java11-alpineMAINTAINERchenglong<[email protected]>VOLUME/tmpRUNmkdir/dataEXPOS......
  • leetcode-501-easy
    FindModeinBinarySearchTreeGiventherootofabinarysearchtree(BST)withduplicates,returnallthemode(s)(i.e.,themostfrequentlyoccurredelemen......
  • P5030 题解
    前言题目传送门!更好的阅读体验?一道没啥意思的题目,但是好像很多题解都过不了现在的数据?思路只不过是把正常题目的马(\(1,2\))换成了另一种东西(\(1,3\))。很套路地,黑白......
  • 【转】SpringBoot的44种启动器
    springBoot应用启动器基本的一共有44种,具体如下:1)spring-boot-starter这是SpringBoot的核心启动器,包含了自动配置、日志和YAML。2)spring-boot-starter-actuator帮助监控......
  • SpringBoot静态资源映射
    Springboot添加静态资源映射配置将静态资源解析到指定的路径上@Slf4j@ConfigurationpublicclassWebMvcConfigextendsWebMvcConfigurationSupport{@Override......
  • springboot集成kafka
    步骤:1、引入依赖<dependency><groupId>org.springframework.kafka</groupId><artifactId>spring-kafka</artifactId></dependency>2、编写配置文件spring:......
  • 230120_50_SpringBoot入门
    springboot自动配置原理总结(参考狂神说)以HttpEncodingAutoConfiguration(Http编码自动配置)为例解释自动配置原理;//表示这是一个配置类,和以前编写的配置文件一样,也可以给......
  • 华硕 B450主板 如何开启TPM2.0
      001、问题  002、重新开机快速按delete键,进入如下界面    003、按F7进入高级模式   004、利用方向键移动至高级,然后找到AMDfTPMconfigur......