springboot几种开发模式_SpringBoot笔记

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

2、src/main/webapp目录下

e5b497943d6f6803750ec9842450bb56.png

8. Spring Boot文件上传

(1) 在Spring Boot中如何设置单个上传文件大小?

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

(3) 解决Thymeleaf中标签匹配的异常有几种方式?

两种:

1、按照严禁的语法编写HTML

2、Thymeleaf.jar更新为3.0以上的版本

thymeleaf-layout-dialect.jar更新为2.0以上的版本。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值