SpringBoot02

2020-06-01  本文已影响0人  建国同学

复习

@Component
启动时,会加载贴了该注解的类
instanceof:判断是否是该对象的实例

一、集成freemarker

二、 异常处理

静态文件方式

访问异常处理-静态页面方式
1,SpringBoot默认情况下,把所有错误都重新定位到/error这个处理路径上,由BasicErrorController类完成处理;
2,SpringBoot提供了默认的替换错误页面的路径:
1,静态错误页面默认结构:

src/
    resources/
    static/
        error/
            404.html
            401.html
            5xx.html

2,也可以使用模板页面:

src/
    resources/
    templates/
        error/
            5xx.ftl

该路径方式是通过ErrorMvcAutoConfiguration中的DefaultErrorViewResolver完成的;

统一异常处理方式

统一异常处理使用增强控制器啦实现,级别比静态方式更高

三、集成druid

<!-- druid -->
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid-spring-boot-starter</artifactId>
    <version>1.1.21</version>
</dependency>
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql:///crmdemo?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=admin

四、集成mybaties

五、事务

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
        </dependency>

六、 拦截器

  1. 实现WebMvcConfigurer接口
  2. 重写addInterceptors方法
  3. // 如果是拦截的动态请求,handler参数就是HandlerMethod类实例
    // 如果是拦截是静态资源,handler参数就是不是HandLerMethod类实例

七、

八、

九、

十、

上一篇下一篇

猜你喜欢

热点阅读