今天在IDEA写拦截器的时候遇到点困惑,继承了HandlerInterceptor没有报错,我一直认为他会提醒,要重写方法。如下图

通过查资料,嗯,终于找到原因来,先来上HandlerInterceptor接口的源码

public interface HandlerInterceptor {

	default boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
return true;
} default void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
@Nullable ModelAndView modelAndView) throws Exception {
} default void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
@Nullable Exception ex) throws Exception {
}
}

敲一敲黑板,重点来了

以上是HandlerInterceptor 接口的源码,可以看到高版本的spring-webmvc jar包中,HandlerInterceptor 接口定义的是默认方法,这是jdk1.8的新特性,也就是说接口中的方法你重写也可以,不重写也不会报错。

所以所这里并不会提醒你重写,你要自己去手动写。

没有重写接口方法,IDEA没有报错。的更多相关文章

  1. java调用本地方法的时候报错 could not find the main class:xx.program will exit

    如图所示,当在java调用本地方法的时候报错 我的解决办法是把dll文件放到System.out.println(System.getProperty("java.library.path& ...

  2. IntelliJ IDEA中Mapper接口通过@Autowired注入报错的正确解决方式

    转载请注明来源:四个空格 » IntelliJ IDEA中Mapper接口通过@Autowired注入报错的正确解决方式: 环境 ideaIU-2018.3.4.win: 错误提示: Could no ...

  3. 关于微信JS-SDK 分享接口的两个报错记录

    一.前提: 微信测试号,用微信开发者工具测试 二.简单复述文档: 1.引入JS文件 在需要调用JS接口的页面引入如下JS文件,(支持https):http://res.wx.qq.com/open/j ...

  4. fetch get方法的时候报错

    fetch 报错 Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body. 翻译过来就 ...

  5. 接口调用 读取图片报错 Access to the path '' is denied.解决方案

    调用接口 读取服务器上 图片 报错: Server was unable to process request. ---> Access to the path '图片路径' is denied ...

  6. 【原】iOS 同时重写setter和getter时候报错:Use of undeclared identifier '_name';did you mean 'name'

    写了那么多的代码了,平时也没有怎么注意会报这个错误,因为平时都很少同时重写setter和getter方法,一般的话,我们大概都是使用懒加载方法,然后重写getter方法,做一个非空判断.然后有时候根据 ...

  7. 执行发送邮件Send方法时,报错:邮箱不可用。 服务器响应为: 5.7.1 Unable to relay for xxx@xxx.com

    .net代码在执行发送邮件Send方法时,往往出现这个的报错: 邮箱不可用. 服务器响应为: 5.7.1 Unable to relay for xxx@xxx.com 这个问题应该是smtp的设置问 ...

  8. 使用jieba导入引用方法时,报错AttributeError: module 'jieba' has no attribute 'cut'

    一.问题描述 import jieba导入后,使用jieba.cut()方法时报错AttributeError: module 'jieba' has no attribute 'cut' 二.问题分 ...

  9. 解决分批次调用 jsonp 接口的 callback 会报错问题

    当我们分批次调用同一个jsonp接口时,会有一定机率同时调用,而jsonp的callback不支持同时调用, 会报错,所以当我们在分批次调用同一jsonp接口时,最好在callback后加个变量值,总 ...

随机推荐

  1. CF991C Candies

    CF991C Candies 洛谷评测传送门 题目描述 After passing a test, Vasya got himself a box of nn candies. He decided ...

  2. ionic4 新建 - 报错

    npm install -g cordova ionic 安装依赖 ionic start myApp tabs 新建项目 ionic g page name name为页面名称 新建组件 创建公共模 ...

  3. Java进阶的道路,怎么成为大牛?

    已然励志在java路上走的更远,那就有必要了解java的途径.先看图 image.png 愈加细化的细节如下​ 一: 编程基础 不管是C仍是C++,不管是Java仍是PHP,想成为一名合格的程序员,根 ...

  4. hdu 6495 dp

    http://acm.hdu.edu.cn/showproblem.php?pid=6495 题意 有n个挑战(1e3),假如接受,在挑战之前体力x会变成min(x,\(b[i]\)),然后会减去a[ ...

  5. hw笔试题-02

    #include<stdio.h> #include<string.h> typedef struct { char *mem; char len; }m_table_t; i ...

  6. Azure CosmosDB (14) 使用Postman访问CosmosDB REST API

    <Windows Azure Platform 系列文章目录> 今天研究了一下如何使用Postman访问Azure CosmosDB. CosmosDB API接口,可以参考:https: ...

  7. golang基础之工程结构

    Golang 工作空间 编译工具对源码目录有严格要求,每个工作空间 (workspace) 必须由 bin.pkg.src 三个目录组成. workspace | +--- bin // go ins ...

  8. centos 启动一个tcp服务程序

    需要先yum安装: yum install nc 启动服务: nc -l 80

  9. 《一起学mysql》1

    自从达内毕业后就没用过mysql,一直用的hive,hdfs 存储数据,最近突然又接触到了关系型数据库.本想随便从网上 找个教程看看,但是都不是很满意,pdf看着又难受,还是自己个儿写个笔记吧.   ...

  10. POJ-1129 DFS染色+四色原理的应用

    OJ-ID:     POJ-1129 author:    Caution_X date of submission:    20190927 tags:    DFS+四色原理的应用 descri ...