springboot资源文件
1.静态资源放在 static public resources 等文件夹
2.欢迎页 index.html 以上三个路径随便放。
3.网页前的图标,自定义图标,命名为 favicon.ico 以上三个路径随便放
1.配置文件
#1.配置文件:随机数$(random.value)
#2.配置文件:占位符$(dog.name)获取之前配置的值,如果没有:默认值$(dog.name:dog)
#3.配置文件:加载顺序1.根file:/config/ 2.根/ 3.classpath:/config/ 4.classpath:/ 高优先级会覆盖低优先级的配置。
2.日志处理
#日志框架:springboot底层使用的是SLF4j(日志门面)和logback(日志实现)
#springboot把其他的日志都替换成了slf4j,引入其他框架需要把日志依赖排除掉。
#1.设置日志输出级别
logging.level.com.glut.springboot=trace
#2.控制台输出日志格式
#logging.pattern.console=
#3.文件中日志输出格式
#logging.pattern.file=
#4.指定日志名字+路径方式
logging.file.name=D:/idea工作区/ssm/spring-boot-01-helloworld/springboot.log
#5.只指定路径
#在当前磁盘根路径下创建spring文件夹和里面的log文件夹;使用spring.log作为默认名字
#logging.file.path=/spring/log
3.模板引擎thymeleaf
模板引擎放在templates文件夹,例如jsp。。因为springboot只能用html。
springboot推荐使用Thymeleaf。
使用模板引擎不能直接访问模板引擎下的页面,需要在自己的配置类下设置请求转发
@Configuration
public class MyNewConfig implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
//普通的访问不能找到templates文件夹下的页面需要设置请求转发
//普通存在的页面不需要设置,多余设置了会出错
registry.addViewController("/login.html").setViewName("login");
registry.addViewController("/success.html").setViewName("success");
}
}
#关闭thymeleaf的缓存
spring.thymeleaf.cache=false
1.jar包
<!--thymeleaf依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
更改版本
<properties>
<thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
<thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout-dialect.version>
</properties>
2.html命名空间
<html lang="en" xmlns:th="http://www.thymeleaf.org">
3.thymeleaf引用jQuery和Bootstrap
先导jar包
<!--jQuery-->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.4.1</version>
</dependency>
<!--bootstrap-->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>4.0.0</version>
</dependency>
从maven依赖找路径在页面引用
登录拦截器需要排除这个路径
<link rel="stylesheet" th:href="@{/webjars/bootstrap/4.0.0/css/bootstrap.css}">
<script th:src="@{/webjars/jquery/3.4.1/jquery.js}">
<script th:src="@{/webjars/bootstrap/4.0.0/js/bootstrap.js}"></script>
4.java测试
@RequestMapping("/thymeleaf")
public String testThymeleaf(Map<String,Object> map) {
logger.info("测试thymeleaf执行了...");
map.put("hello", "你好");
return "success";
}
5.html引用测试
<a href="thymeleaf">测试thymeleaf</a>
<div th:text="${hello}"></div>