使用SpringBoot进行web开发: 1、创建SpringBoot应用,选中我们需要的模块; 2、SpringBoot已默认将选择的场景配置好了,只需要在配置文件中指定少量配置就可以运行起来 3、编写业务代码 自动配置原理一些注解简单说明: 1、xxxAutoConfiguration:帮助我们给容器中自动配置组件; 2、xxxProperties:配置类来封装配置文件的内容 |
SpringBoot 对静态资源的映射规则: ctrl + shift + t,搜索 WebMvcAutoConfiguration : 1、所有 /webjars/** ,都去 "classpath:/META-INF/resources/webjars/" 下找资源 webjars地址:http://www.webjars.org/ webjars:以jar包的方式引入静态资源,比如jquery、bootstrap等以 maven 依赖的方式 代码如下: jquery访问地址:http://localhost:8080/webjars/jquery/3.3.1-1/jquery.js 在访问jquery的时候,只需要写webjars下面资源的名称即可 |
1、模板引擎: 模板引擎:JSP、Velocity、Freemarker、Thymeleaf(SpringBoot推荐) 等 1、引入Thymeleaf: 2、Thymeleaf使用&语法: @ConfigurationProperties(prefix = "spring.thymeleaf") public class ThymeleafProperties { private static final Charset DEFAULT_ENCODING = StandardCharsets.UTF_8; public static final String DEFAULT_PREFIX = "classpath:/templates/"; public static final String DEFAULT_SUFFIX = ".html"; 注:只要把HTML页面放在 classpath:/templates/ , thymeleaf 就自动渲染 使用: 1、把 xmlns:th="http://www.thymeleaf.org" 放入在HTML标签中,导入thymeleaf 的名称空间,有代码提示 2、语法案例: thymeleaf使用手册:https://download.csdn.net/download/yufang131/10420053 属性的优先级(下图所示): |
感谢--尚硅谷 |