2020-02-24

庚子鼠年 戊寅月 丁酉日

描述

springboot练习

随笔

thymeleaf学习

MVC配置原理

国际化

Spring 5.0后,WebMvcConfigurerAdapter被废弃,取代的方法有两种:

​ ①implements WebMvcConfigurer(官方推荐)

​ ②extends WebMvcConfigurationSupport

总结博客: https://blog.csdn.net/qq_40674583/article/details/104477435

拦截器

1. 实现拦截器接口 HandlerInterceptor

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class LoginHandlerInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        System.out.println("拦截器!!!");
        String a = request.getParameter("a");
        // return !StringUtils.isEmpty(a) && "123".equals(a);
        return true;
    }
}

2. 配置

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class MyMvcConfig implements WebMvcConfigurer {

    @Autowired
    LoginHandlerInterceptor loginHandlerInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
  registry.addInterceptor(loginHandlerInterceptor).addPathPatterns("/hello");
    }
}

404处理

1. 在static项目新建文件夹error

2. 编写404.html 和 500.html

3. 配置文件过滤

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry
            .addResourceHandler("/**")
            .addResourceLocations("classpath:/static/");
}

自定义异常处理

技术博客https://blog.csdn.net/qq_40674583/article/details/104484838

自定义类型转换器

技术博客https://blog.csdn.net/qq_40674583/article/details/104486783

整合Druid

整合mybatis

spring安全

swagger

异步任务

邮件任务

分布式RPC

微服务

Dubbo和Zookeeper

Dubbo-admin

原文地址:https://www.cnblogs.com/chang1024/p/12359154.html