SpringBoot Web开发

jar :webapp!
自动装配
springboot到底帮我们配置了什么?我们能不能进行修改?能修改那些东西?能不能扩展?

  • xxxxAutoConfiguration…向容器中自动配置组件
  • xxxxProperties:自动配置类,装配配置文件中自定义的一些内容!

要解决的问题:

  • 导入静态资源

  • 首页

  • jsp,模板引擎Thymeleaf

  • 装配扩展SpringMVC

  • 增删改查

  • 拦截器

  • 国际化!
    静态资源
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
    //如果resourceProperties已经被自定义了,
    if (!this.resourceProperties.isAddMappings()) {
    logger.debug(“Default resource handling disabled”);
    } else {
    //从"classpath:/META-INF/resources/webjars/“获取”/webjars/"下的所有资源
    this.addResourceHandler(registry, "/webjars/
    ", “classpath:/META-INF/resources/webjars/”);
    this.addResourceHandler(registry, this.mvcProperties.getStaticPathPattern(), (registration) -> {
    registration.addResourceLocations(this.resourceProperties.getStaticLocations());
    if (this.servletContext != null) {
    //获得静态资源的路径
    ServletContextResource resource = new ServletContextResource(this.servletContext, “/”);
    registration.addResourceLocations(new Resource[]{resource});
    }

              });
          }
      }
    

总结:
1、在springboot,我们可以使用一下方式处理静态资源:

  • webjars 访问方式:localhost:8080/webjars/
  • public、static、/**、resources 访问方式:localhost:8080/
    2.优先级:resources>static(默认的)>public

扩展springMVC
如果我们要扩展springmvc,官方建议我们这样去做!
在这里插入图片描述

SpringBoot2使用的Spring5,因此将WebMvcConfigurerAdapter改为WebMvcConfigurer

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值