springBoot学习笔记-07-SpringBoot_Web开发


Web开发.

springboot

  • 自动装配
    • 自动将环境配置好(执行导入相应的starter)
    • 只需专注于业务代码

SpringBoot 配置了什么?能修改吗?可以修改什么?能不能扩展?

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

WebMvcAutoConfiguration

WebMvcProperties

ResourceProperties

添加静态资源.

1、什么是webjars.

https://www.webjars.org/

WebJars是将客户端(浏览器)资源(JavaScript,Css等)打成jar包文件,以对资源进行统一依赖管理。WebJars的jar包部署在Maven中央仓库上。

2、如何使用 webjars.

  • 后端添加依赖(静态资源会加载到 classpath:/META-INF/resources/webjars/ 下 )映射到

    • /webjars/**
  • classpath:/META-INF/resource/**,classpath:/resources/,classpath:/static/,classpath:/public/会被映射到

    • /**

    优先级:resoures > static > public

localhost:port/** 静态资源都会到 后端以上目录中找

总结:.

在springboot中,我们可以使用以下方式处理静态资源

  • webjars localhost:port/webjars
  • public,static,/**,resources localhost:8080/

添加首页和图标定制.

index.html 可放置在

  • classpath:/resources/
  • classpath:/static/
  • classpath:/public/
  • classpath:/templates/

templates 目录下的所有页面,只能通过controller跳转

图标定制:https://blog.csdn.net/yemuyouhan/article/details/105784153?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522160006064919724836700746%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=160006064919724836700746&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v3~pc_rank_v2-1-105784153.first_rank_ecpm_v3_pc_rank_v2&utm_term=springboot+2.3+%E8%87%AA%E5%AE%9A%E4%B9%89%E5%9B%BE%E6%A0%87&spm=1018.2118.3001.4187

注意:所有的页面静态资源(本地url)都需要都需要thymeleaf托管 @{}


文章作者: liuminkai
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 liuminkai !
评论
 上一篇
springBoot学习笔记-08-Thymeleaf模板引擎 springBoot学习笔记-08-Thymeleaf模板引擎
Thymeleaf模板引擎. 本文转载自:https://fanlychie.github.io/post/thymeleaf.html 添加启动器.<dependency> <groupId>org.springfr
2020-09-14
下一篇 
springBoot学习笔记-06-JSR303校验 springBoot学习笔记-06-JSR303校验
JSR303校验. JSR-303是一个数据验证的规范,但是spring并没有对其进行实现,Hibernate Validator是实现了这一规范的,通过此这个实现来讲SpringMVC对JSR-303的支持。 注解: @Validate
2020-09-13
  目录