简要说明
如何实现网上文章基本是随便一搜就可以很快找到, 这里不再赘述.
Spring-web 和 Spring-webmvc
通过 idea 查看到两个注解位于 spring-Web-5.2.2.RELEASE.jar 包内,.
而这里 maven 依赖有 spring Web 和 spring webmvc 两个包;
查询到 spring Web 主要提供了 HTTP 的功能集成,
而 spring-webmvc 基于 spring-Web, 从而提供 servlet 功能. (参考: Maven dependency spring-Web vs spring-webmvc)
2.2.5 Web
The Web layer consists of the spring-Web, spring-webmvc, spring-websocket, and spring-webmvc-portlet modules.
- The spring-Web module provides basic Web-oriented integration features such as multipart file upload functionality and the initialization of the IoC container using Servlet listeners and a Web-oriented application context. It also
- contains an HTTP client and the Web-related parts of Spring's remoting support.
- The spring-webmvc module (also known as the Web-Servlet module) contains Spring's model-view-controller (MVC) and REST Web Services implementation for web applications. Spring's MVC framework provides a clean> separation between domain model code and Web forms and integrates with all of the other features of the Spring Framework.
- The spring-webmvc-portlet module (also known as the Web-Portlet module) provides the MVC implementation to be used in a Portlet environment and mirrors the functionality of the Servlet-based spring-webmvc module.
文档地址 (这里有很多值得阅读地方):
两个注解
- @ControllerAdvice
- @Target({ElementType.TYPE})
- @Retention(RetentionPolicy.RUNTIME)
- @Documented
- @Component
- public @interface ControllerAdvice {
- @AliasFor("basePackages")
- String[] value() default {};
- @AliasFor("value")
- String[] basePackages() default {};
- Class<?>[] basePackageClasses() default {};
- Class<?>[] assignableTypes() default {};
- Class<? extends Annotation>[] annotations() default {};
- }
- @ExceptionHandler
- @Target({ElementType.METHOD})
- @Retention(RetentionPolicy.RUNTIME)
- @Documented
- public @interface ExceptionHandler {
- Class<? extends Throwable>[] value() default {};
- }
来源: http://www.bubuko.com/infodetail-3351881.html