没有合适的资源?快使用搜索试试~ 我知道了~
首页Spring框架参考文档4.2.7.RELEASE
Spring框架参考文档4.2.7.RELEASE
需积分: 9 1 下载量 17 浏览量
更新于2024-07-20
收藏 5.34MB PDF 举报
"Spring Framework 4.2.7.RELEASE 的参考文档"
《Spring Framework Reference Documentation》是Spring框架的权威指南,涵盖了4.2.7.RELEASE版本的详细内容。该文档由众多专家共同编撰,包括Rod Johnson、Juergen Hoeller等知名开发者。文档的版权归属2004年至2015年期间的作者,允许非商业性的复制与分发,但需保留版权信息。
Spring Framework 是一个开源的应用程序框架,主要以Java语言编写,广泛用于企业级应用开发。它提供了一个全面的编程和配置模型,旨在简化Java开发并促进良好的编程实践。本参考文档详细阐述了Spring的核心特性,主要包括以下几个方面:
1. **概述**:
- **入门**:介绍如何开始使用Spring,包括环境配置和基本项目结构。
- **Spring框架简介**:深入解释Spring的依赖注入(Dependency Injection, DI)和控制反转(Inversion of Control, IOC)概念,这是Spring的核心特性,帮助解耦应用程序组件,提高可测试性和可维护性。
2. **模块**:
- **核心容器**:这是Spring的基础,包括BeanFactory和ApplicationContext,它们负责管理应用中的对象生命周期和依赖关系。
- **面向切面编程(AOP)和 instrumentation**:Spring的AOP模块支持创建可插入的面向切面的解决方案,可以用于日志、事务管理等跨切面关注点。Instrumentation则提供类加载器和类修改的支持,便于在运行时进行一些高级操作。
- **消息**:Spring提供了对消息传递的支持,尤其在实现企业级应用的集成时,如JMS(Java Message Service)。
3. **数据访问/集成**:
- 包括对各种持久化技术的支持,如JDBC、ORM(Object-Relational Mapping)框架如Hibernate和JPA,以及对NoSQL数据库的集成。
4. **Web**:
- 提供了多种Web开发的支持,如MVC(Model-View-Controller)框架,用于构建RESTful服务,还有WebSocket支持。
5. **工具**:
- 提供了一些辅助工具和库,如测试支持、远程访问、EJB集成等。
6. **其他模块**:
- 包括Spring Batch,用于处理批量处理任务,Spring Security,用于应用程序的安全管理,以及Spring Integration,用于实现企业应用之间的松散耦合集成。
通过这些模块,Spring Framework提供了一站式的解决方案,使得开发者可以轻松地构建复杂、可扩展且健壮的企业级应用。文档还包含了详细的API参考和示例代码,帮助开发者快速上手和深入理解Spring的各种功能。
Spring Framework Reference Documentation
4.2.7.RELEASE Spring Framework xvi
Producible Media Types .......................................................................... 483
Request Parameters and Header Values ................................................. 484
Defining @RequestMapping handler methods .................................................. 484
Supported method argument types .......................................................... 485
Supported method return types ............................................................... 487
Binding request parameters to method parameters with @RequestParam ... 488
Mapping the request body with the @RequestBody annotation .................. 488
Mapping the response body with the @ResponseBody annotation ............. 490
Creating REST Controllers with the @RestController annotation ................ 490
Using HttpEntity ...................................................................................... 490
Using @ModelAttribute on a method ....................................................... 491
Using @ModelAttribute on a method argument ......................................... 492
Using @SessionAttributes to store model attributes in the HTTP session
between requests ................................................................................... 493
Working with "application/x-www-form-urlencoded" data ............................ 494
Mapping cookie values with the @CookieValue annotation ........................ 494
Mapping request header attributes with the @RequestHeader annotation ... 495
Method Parameters And Type Conversion ............................................... 495
Customizing WebDataBinder initialization ................................................. 495
Advising controllers with @ControllerAdvice ............................................. 497
Jackson Serialization View Support ......................................................... 497
Jackson JSONP Support ........................................................................ 498
Asynchronous Request Processing .................................................................. 499
Exception Handling for Async Requests ................................................... 500
Intercepting Async Requests ................................................................... 501
HTTP Streaming ..................................................................................... 501
HTTP Streaming With Server-Sent Events ............................................... 501
HTTP Streaming Directly To The OutputStream ....................................... 502
Configuring Asynchronous Request Processing ........................................ 502
Testing Controllers ......................................................................................... 503
21.4. Handler mappings .......................................................................................... 503
Intercepting requests with a HandlerInterceptor ................................................ 504
21.5. Resolving views ............................................................................................. 506
Resolving views with the ViewResolver interface .............................................. 506
Chaining ViewResolvers ................................................................................. 508
Redirecting to Views ....................................................................................... 508
RedirectView .......................................................................................... 509
The redirect: prefix ................................................................................. 510
The forward: prefix ................................................................................. 510
ContentNegotiatingViewResolver ..................................................................... 510
21.6. Using flash attributes ..................................................................................... 512
21.7. Building URIs ................................................................................................. 513
Building URIs to Controllers and methods ........................................................ 514
Building URIs to Controllers and methods from views ....................................... 515
21.8. Using locales ................................................................................................. 516
Obtaining Time Zone Information .................................................................... 516
AcceptHeaderLocaleResolver .......................................................................... 516
CookieLocaleResolver ..................................................................................... 516
SessionLocaleResolver ................................................................................... 517
LocaleChangeInterceptor ................................................................................ 517
Spring Framework Reference Documentation
4.2.7.RELEASE Spring Framework xvii
21.9. Using themes ................................................................................................ 517
Overview of themes ........................................................................................ 517
Defining themes ............................................................................................. 518
Theme resolvers ............................................................................................. 518
21.10. Spring’s multipart (file upload) support ........................................................... 519
Introduction .................................................................................................... 519
Using a MultipartResolver with Commons FileUpload ........................................ 519
Using a MultipartResolver with Servlet 3.0 ....................................................... 519
Handling a file upload in a form ...................................................................... 520
Handling a file upload request from programmatic clients .................................. 521
21.11. Handling exceptions ..................................................................................... 522
HandlerExceptionResolver .............................................................................. 522
@ExceptionHandler ........................................................................................ 522
Handling Standard Spring MVC Exceptions ...................................................... 523
Annotating Business Exceptions With @ResponseStatus .................................. 524
Customizing the Default Servlet Container Error Page ...................................... 524
21.12. Web Security ............................................................................................... 525
21.13. Convention over configuration support ........................................................... 525
The Controller ControllerClassNameHandlerMapping ........................................ 525
The Model ModelMap (ModelAndView) ............................................................ 526
The View - RequestToViewNameTranslator ..................................................... 527
21.14. HTTP caching support .................................................................................. 528
Cache-Control HTTP header ........................................................................... 529
HTTP caching support for static resources ....................................................... 529
Support for the Cache-Control, ETag and Last-Modified response headers in
Controllers ...................................................................................................... 530
Shallow ETag support ..................................................................................... 531
21.15. Code-based Servlet container initialization ..................................................... 531
21.16. Configuring Spring MVC ............................................................................... 533
Enabling the MVC Java Config or the MVC XML Namespace ............................ 533
Customizing the Provided Configuration ........................................................... 535
Conversion and Formatting ............................................................................. 535
Validation ....................................................................................................... 536
Interceptors .................................................................................................... 538
Content Negotiation ........................................................................................ 538
View Controllers ............................................................................................. 539
View Resolvers .............................................................................................. 540
Serving of Resources ..................................................................................... 541
Falling Back On the "Default" Servlet To Serve Resources ................................ 543
Path Matching ................................................................................................ 544
Message Converters ....................................................................................... 545
Advanced Customizations with MVC Java Config ............................................. 546
Advanced Customizations with the MVC Namespace ........................................ 547
22. View technologies ..................................................................................................... 548
22.1. Introduction .................................................................................................... 548
22.2. Thymeleaf ..................................................................................................... 548
22.3. Groovy Markup Templates .............................................................................. 548
Configuration .................................................................................................. 548
Example ......................................................................................................... 549
22.4. Velocity & FreeMarker .................................................................................... 549
Spring Framework Reference Documentation
4.2.7.RELEASE Spring Framework xviii
Dependencies ................................................................................................ 549
Context configuration ...................................................................................... 549
Creating templates ......................................................................................... 550
Advanced configuration ................................................................................... 550
velocity.properties ................................................................................... 550
FreeMarker ............................................................................................. 551
Bind support and form handling ....................................................................... 551
The bind macros .................................................................................... 551
Simple binding ........................................................................................ 551
Form input generation macros ................................................................. 552
HTML escaping and XHTML compliance ................................................. 556
22.5. JSP & JSTL .................................................................................................. 556
View resolvers ................................................................................................ 556
'Plain-old' JSPs versus JSTL ........................................................................... 557
Additional tags facilitating development ............................................................ 557
Using Spring’s form tag library ........................................................................ 557
Configuration .......................................................................................... 558
The form tag .......................................................................................... 558
The input tag .......................................................................................... 559
The checkbox tag ................................................................................... 559
The checkboxes tag ............................................................................... 561
The radiobutton tag ................................................................................ 561
The radiobuttons tag ............................................................................... 561
The password tag ................................................................................... 562
The select tag ........................................................................................ 562
The option tag ........................................................................................ 562
The options tag ...................................................................................... 563
The textarea tag ..................................................................................... 564
The hidden tag ....................................................................................... 564
The errors tag ........................................................................................ 564
HTTP Method Conversion ....................................................................... 566
HTML5 Tags .......................................................................................... 567
22.6. Script templates ............................................................................................. 567
Dependencies ................................................................................................ 567
How to integrate script based templating .......................................................... 568
22.7. XML Marshalling View .................................................................................... 570
22.8. Tiles .............................................................................................................. 570
Dependencies ................................................................................................ 570
How to integrate Tiles ..................................................................................... 570
UrlBasedViewResolver ............................................................................ 571
ResourceBundleViewResolver ................................................................. 571
SimpleSpringPreparerFactory and SpringBeanPreparerFactory ................. 572
22.9. XSLT ............................................................................................................. 572
My First Words ............................................................................................... 573
Bean definitions ...................................................................................... 573
Standard MVC controller code ................................................................. 573
Document transformation ........................................................................ 574
22.10. Document views (PDF/Excel) ........................................................................ 574
Introduction .................................................................................................... 574
Configuration and setup .................................................................................. 575
Spring Framework Reference Documentation
4.2.7.RELEASE Spring Framework xix
Document view definitions ....................................................................... 575
Controller code ....................................................................................... 575
Subclassing for Excel views .................................................................... 575
Subclassing for PDF views ..................................................................... 577
22.11. JasperReports .............................................................................................. 577
Dependencies ................................................................................................ 577
Configuration .................................................................................................. 577
Configuring the ViewResolver .................................................................. 578
Configuring the Views ............................................................................. 578
About Report Files .................................................................................. 578
Using JasperReportsMultiFormatView ...................................................... 578
Populating the ModelAndView ......................................................................... 579
Working with Sub-Reports ............................................................................... 580
Configuring Sub-Report Files .................................................................. 580
Configuring Sub-Report Data Sources ..................................................... 581
Configuring Exporter Parameters ..................................................................... 581
22.12. Feed Views ................................................................................................. 582
22.13. JSON Mapping View .................................................................................... 582
22.14. XML Mapping View ...................................................................................... 583
23. Integrating with other web frameworks ....................................................................... 584
23.1. Introduction .................................................................................................... 584
23.2. Common configuration ................................................................................... 585
23.3. JavaServer Faces 1.2 .................................................................................... 586
SpringBeanFacesELResolver (JSF 1.2+) ......................................................... 586
FacesContextUtils ........................................................................................... 586
23.4. Apache Struts 2.x .......................................................................................... 586
23.5. Tapestry 5.x .................................................................................................. 587
23.6. Further Resources ......................................................................................... 587
24. Portlet MVC Framework ............................................................................................ 588
24.1. Introduction .................................................................................................... 588
Controllers - The C in MVC ............................................................................ 589
Views - The V in MVC .................................................................................... 589
Web-scoped beans ......................................................................................... 589
24.2. The DispatcherPortlet ..................................................................................... 589
24.3. The ViewRendererServlet ............................................................................... 591
24.4. Controllers ..................................................................................................... 592
AbstractController and PortletContentGenerator ............................................... 593
Other simple controllers .................................................................................. 594
Command Controllers ..................................................................................... 594
PortletWrappingController ................................................................................ 595
24.5. Handler mappings .......................................................................................... 595
PortletModeHandlerMapping ............................................................................ 596
ParameterHandlerMapping .............................................................................. 596
PortletModeParameterHandlerMapping ............................................................ 597
Adding HandlerInterceptors ............................................................................. 597
HandlerInterceptorAdapter ............................................................................... 598
ParameterMappingInterceptor .......................................................................... 598
24.6. Views and resolving them .............................................................................. 598
24.7. Multipart (file upload) support ......................................................................... 598
Using the PortletMultipartResolver ................................................................... 599
Spring Framework Reference Documentation
4.2.7.RELEASE Spring Framework xx
Handling a file upload in a form ...................................................................... 599
24.8. Handling exceptions ....................................................................................... 603
24.9. Annotation-based controller configuration ........................................................ 603
Setting up the dispatcher for annotation support ............................................... 603
Defining a controller with @Controller .............................................................. 604
Mapping requests with @RequestMapping ....................................................... 604
Supported handler method arguments ............................................................. 606
Binding request parameters to method parameters with @RequestParam .......... 608
Providing a link to data from the model with @ModelAttribute ............................ 608
Specifying attributes to store in a Session with @SessionAttributes .................... 609
Customizing WebDataBinder initialization ......................................................... 609
Customizing data binding with @InitBinder ............................................... 609
Configuring a custom WebBindingInitializer .............................................. 610
24.10. Portlet application deployment ...................................................................... 610
25. WebSocket Support .................................................................................................. 611
25.1. Introduction .................................................................................................... 611
WebSocket Fallback Options ........................................................................... 611
A Messaging Architecture ............................................................................... 612
Sub-Protocol Support in WebSocket ................................................................ 612
Should I Use WebSocket? .............................................................................. 612
25.2. WebSocket API ............................................................................................. 613
Create and Configure a WebSocketHandler ..................................................... 613
Customizing the WebSocket Handshake .......................................................... 614
WebSocketHandler Decoration ........................................................................ 615
Deployment Considerations ............................................................................. 615
Configuring the WebSocket Engine ................................................................. 616
Configuring allowed origins ............................................................................. 618
25.3. SockJS Fallback Options ................................................................................ 619
Overview of SockJS ....................................................................................... 619
Enable SockJS ............................................................................................... 620
HTTP Streaming in IE 8, 9: Ajax/XHR vs IFrame .............................................. 621
Heartbeat Messages ....................................................................................... 622
Servlet 3 Async Requests ............................................................................... 622
CORS Headers for SockJS ............................................................................. 623
SockJS Client ................................................................................................. 623
25.4. STOMP Over WebSocket Messaging Architecture ........................................... 625
Overview of STOMP ....................................................................................... 625
Enable STOMP over WebSocket ..................................................................... 626
Flow of Messages .......................................................................................... 628
Annotation Message Handling ......................................................................... 630
Sending Messages ......................................................................................... 632
Simple Broker ................................................................................................ 632
Full-Featured Broker ....................................................................................... 632
Connections To Full-Featured Broker .............................................................. 633
Using Dot as Separator in @MessageMapping Destinations .............................. 634
Authentication ................................................................................................. 635
User Destinations ........................................................................................... 636
Listening To ApplicationContext Events and Intercepting Messages ................... 637
STOMP Client ................................................................................................ 639
WebSocket Scope .......................................................................................... 640
剩余892页未读,继续阅读
2019-09-18 上传
2014-11-26 上传
2017-08-26 上传
2011-07-20 上传
2020-02-28 上传
2019-06-13 上传
2020-07-17 上传
2011-04-15 上传
2019-05-30 上传
erdongritian
- 粉丝: 8
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Vue_frontend_for_Laravel_rest_api
- react_calculator:react_calculator
- Smartclient-Top-Cases:基于 JavaFX Java Swing 的应用程序显示按类型分组创建的顶级案例
- Data-Mining
- php-cartography.alterway.fr:网站来源-Source website php
- hackrank2nd 1-11-2017,c语言软件代码大全源码,c语言
- C#-Leetcode编程题解之第19题删除链表的倒数第N个结点.zip
- gboard-large-clipboard:MVP重现Gboard中的大型剪贴板崩溃
- code_hub_acc_academy
- generator-jade:玉器项目的约曼发电机
- agv:用于自动导引车的 ROS Groovy 包
- peer-flight-search:对等机器人飞行搜索
- gtwizard-0-ex.zip
- Supermarket_Managment_System
- 23种设计模式图.zip
- 太阳高度角.m,vs2017c语言源码,c语言
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功