1. SpringBoot介绍
(1) 什么是Spring Boot?
SpringBoor是一个框架,一种全新的编程规范,他的 产生简化了框架的使用 ,所谓简化是指简化了Spring众多框架总所需的大量且繁琐的配置文件,所以SpringBoot是一个服务于框架的框架,服务范围是简化配置文件。
(2) Spring Boot有哪些特点?
1、Spring Boot设计的目的是用来简化新Spring应用的初始搭建以及开发过程。
2、嵌入的Tomcat,无需部署war文件
3、Spring Boot并不是对Spring功能上的增强,而是提供了一种快速使用Spring的方式。
2. 构建SpringBoot项目以及启动器讲解
(1) Spring Boot常见的启动器有哪些?
1、spring-boot-starter-web:支持全栈式的web开发,包括了Tomcat和springMVC等jar。
2、spring-boot-starter-jdbc:支持spring以jdbc方式操作数据库的jar包的集合。
3、spring-boot-starter-redis:支持Redis键值存储的数据库操作。
(2) Spring Boot的Web启动器的坐标是什么?
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
3. 编写HelloWorld
(1) 如何编写Spring Boot启动类?
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class , args);
}
}
(2) 编写Spring Boot启动类时需要注意什么?
启动类存放的位置,可以和controller位于同一包下,或位于controller的上一级包中,不能放到controller的平级包以及子包中。
4. Spring Boot整合Servlet
(1) Spring Boot整合Servlet有几种方式?
两种。
(2) 各种方式有什么特点?
第一种:注解的方式:@WebServlet(name = "AnnotationServlet" , urlPatterns = "/first")
第二种:方法的方式:
@Bean
public ServletRegistrationBean getServletRegistrationBean(){
ServletRegistrationBean<MethodServlet> bean = new ServletRegistrationBean<>(new MethodServlet());
bean.addUrlMappings("/second");
return bean;
}
5. Spring Boot整合Filter
(1) Spring Boot整合Filter有几种方式?
2,实现Filter接口
(2) 各种方式有什么特点?
第一种:注解:@WebFilter(filterName = "AnnotationFilter" , urlPatterns = "/first")
第二种:方法:
@Bean
public ServletRegistrationBean getServlet(){
ServletRegistrationBean bean = new ServletRegistrationBean(new MethonServlet());
bean.addUrlMappings("/second");
return bean ;
}
@Bean
public FilterRegistrationBean getFilter(){
FilterRegistrationBean bean = new FilterRegistrationBean(new MethonFilter());
//bean.addUrlPatterns(new String[]{"*.do" , "*.jsp"});
bean.addUrlPatterns("/second");
return bean;
}
6. springBoot整合Listener
(1) Spring Boot整合Listener有几种方式?
2种
(2) 各种方式有什么特点?
实现ServletContextListener接口:
第一种:注解:@WebListener()
第二种:方法:
@Bean
public ServletListenerRegistrationBean getListener(){
ServletListenerRegistrationBean bean = new ServletListenerRegistrationBean(new MethonListener());
return bean;
7. Spring Boot访问静态资源
(1) 在Spring Boot中访问静态资源有几种方式?
两种:
1、从classpath/static目录访问
![ad21d7dbd59ab45ccd8089077690f12e.png](https://img-blog.csdnimg.cn/img_convert/ad21d7dbd59ab45ccd8089077690f12e.png)
2、src/main/webapp目录下
![e5b497943d6f6803750ec9842450bb56.png](https://img-blog.csdnimg.cn/img_convert/e5b497943d6f6803750ec9842450bb56.png)
8. Spring Boot文件上传
(1) 在Spring Boot中如何设置单个上传文件大小?
![62f1f022a994d15da825d436bb9457c9.png](https://img-blog.csdnimg.cn/img_convert/62f1f022a994d15da825d436bb9457c9.png)
(2) 在Spring Boot中如何设置一次请求上传文件大小?
同上
9. Spring Boot整合jsp
(1) 在Spring Boot中整合jsp需要添加哪些坐标?
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.tomcat.embed/tomcat-embed-jasper -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
10. Spring Boot整合Freemarker
(1) 在Spring Boot中整合Freemarker需要添加哪些坐标?
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
</dependencies>
(2) Freemarker视图的扩建名是什么?
ftl
11. Thymeleaf入门-创建项目
(1) 在Spring Boot中整合Thymeleaf需要添加哪些坐标?
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>
(2) Thymeleaf视图的扩建名是什么?
html
(3) Thymeleaf视图要求放到项目的哪个目录下?
src/main/resoutces/templates
12. Thymeleaf入门-Thymeleaf基本使用
(1) Thymeleaf的特点是什么?
通过他特定语法对HTML的标记做渲染。
(2) 在使用Thymeleaf时页面会出现什么异常?
![b9967d33a423225dca2bf0903d85832a.png](https://img-blog.csdnimg.cn/img_convert/b9967d33a423225dca2bf0903d85832a.png)
(3) 解决Thymeleaf中标签匹配的异常有几种方式?
两种:
1、按照严禁的语法编写HTML
2、Thymeleaf.jar更新为3.0以上的版本
thymeleaf-layout-dialect.jar更新为2.0以上的版本。