spring-framework-reference 3.1.4(十七章)

17.Web MVC framework

17.1 Spring Web MVC 简介

Spring Web MVC framework围绕一个可以分派请求到相应处理者的DispatcherServlet设计,它支持可配置的处理映射、视图解析、区域和主题解析并且同时支持文件上传。默认的处理者是基于@Controller和@RequestMapping注解,提供十分灵活的处理方法。根据Spring3.0的介绍,@Controller机制也允许你创建RESTful Web站点和应用程序,通过利用@PathVariable注解以及其他功能。使用Spring Web MVC 你可以把任何一个对象用来做命令对象或者表单回填对象;而不用必须实现一个特定的框架接口或者基类。Spring 的数据绑定也是很灵活的:比如,Spring框架把类型不匹配错误作为可以被应用程序解决的验证错误处理,而不是当作系统错误。因此你不必复制业务对象属性为简单的,无类型的字符串到表单对象中去,仅仅是为了验证提交或者适当的转化字符串。取而代之的是直接绑定到业务对象。

Spring 的视图解析也是相当的灵活。通常一个Controller主要负责准备一个包含有数据的模型Map并且选择一个视图名称,但是它也可以直接向响应流中写入内容并完成请求。视图名称解析也是高度可配置的。可以通过文件扩展名或者接收头内容类型协议,实体名称,属性文件,甚至是一个定制的ViewResolver的实现来配置。Model(MVC 中的 M)是一个Map接口,完全与视图技术剥离,也就是说跟使用何种视图技术没有关系。你可以将Model直接与那些基于JSP、Velocity和Freemarker这些呈现技术的模板集成,或者直接生成XML,JSON,以及许多其他类型的内容。模型Map只需要转换为合适的格式,比如JSP请求属性,Velocity模板模型。

Spring Web MVC的特色

Spring的web模块包含有很多独一无二的web支持功能:

  • 分工明确。每一个角色-控制器、验证器、命令对象、表单对象、域模型、DispatcherServlet、处理器映射表、视图解析器、等角色可以分别被一个特定的对象履行。
  • 强大并且直观的配置框架和应用像配置javaBeans一样。配置能力包括在不同的上下文环境中交叉引用,比如从控制器到业务模型和验证器。
  • 可变、无侵入、灵活。定义你需要的控制器方法签名,尽可能的使用参数注解(如:@RequestParam,@RequestHeader,@PathVariable等等)针对给定的应用场景。
  • 可重用的业务代码,无需重复。利用存在的业务对象作为命令对象或者表单对象而不需要反射他们去扩展一个特定的框架基类。
  • 可定制的绑定和验证。类型不匹配作为应用级的验证错误,保存有违规的数据、本地化的日期和数字绑定等等而不是作为一个只包含有字符串属性的表单对象,需要人工解析并转换为业务对象。
  • 可定制的处理器映射和视图解析。Spring提供从最简单的基于URL的配置到复杂的,特定用途的处理器映射和视图解析策略。Spring比起那些强制使用一种特定的技术进行请求映射的框架要更具有灵活性。
  • 灵活的模型传递。模型传递有了一个键值对Map的支持很容易的跟任何类型的视图技术结合。
  • 可定制的语言环境和主题解析,支持JSPs不论有没有Spring标签库,支持JSTL,支持Velocity不需要其他的纽带。
  • 一个简单却有力的JSP标签库,也就是所说的Spring标签库,他提供对数据绑定和主题定制功能的支持。定制标签考虑到尽可能大的灵活性就标记代码来讲。想要知道关于标签库描述的信息,请看题名为: Appendix G.spring.tld的附录。
  • 拥有一个JSP表单标签库,在Spring2.0版本时引入的,使得编写JSP页面的表单变得更容易。关于JSP表单标签库的描述见附录:Appendix H, spring-form.tld。
  • 所有beans的生命周期被局限到当前的HTTP请求或者HTTP Session。这不是Sprign MVC自身特有的功能,而是Spring MVC所使用的WebApplicationContext 容器所具有的。Bean的范围描述在Request, session, andglobalsession scopes部分。

其他类型MVC框架可插入性

在有些项目中Non-Spring MVC的实现是更受人喜欢的。许多团队希望利用他们在技术和工具上的既有的投资。大量的Struts框架的知识和经验。如果你能够忍受Struts设计上的瑕疵,Struts也是web层一个不错的选择;也同样适用于WebWork以及其他的web MVC框架。

如果你不想使用Spring的Web MVC,但是又想要利用Spring提供的其他方面的解决方案,你可以轻松的将你选择的MVC框架跟Spring集成在一起。只需要利用ContextLoaderListener启动一个Spring跟应用上下文,通过来自Struts或者WebWork  action内部的ServletContext属性(或者利用Spring的帮助方法)来访问它。不涉及任何插件,因此没有专用的集成是必须的。站在web层的观点来看,你只是使用把Spring当做一个库来使用,把根应用上下文实体作为一个入口。

尽管没有用Spring 的 Web MVC是注册 的实体和Spring服务也是唾手可得的。在这方面Spring跟Struts或者WebWork不是竞争关系。Spring致力于很多方面然而那些纯粹的web MVC框架做不到这些,从实体配置到数据访问以及事务管理。因此你可以充实你的应用程序利用Spring的中间层和/或数据访问层,甚至你可以只使用抽象于JDBC或者Hibernate的事务。

17.2  TheDispatcherServlet

Spring Web MVC 跟许多其他的Web MVC框架类似,请求驱动,围绕一个中心Servlet设计,这个中央Servlet分配请求到对应的Controller并且提供其他的功能以促进web应用的开发。但是Spring Web MVC 的DispatcherServlet能做的远远不止这些。它完全跟Spring IoC 容器集成在一起正因为如此你可以使用Spring 具有的任何其他功能。

Spring Web MVC 的DispatcherServlet处理请求的工作流在下图中阐述.深谙设计模式的读者会意识到DispatcherServlet是“前端控制器”(一种设计模式 Spring Web MVC与其他主流的web框架所公用的)设计模式的一种表现形式。


Spring Web MVC 处理请求流程图(顶级)

DiapatcherServlet其实就是一个Servlet(它继承自HttpServlet这个基类),因此需要在你的web项目的web.xml中被声明。你需要映射那些你想要DispatcherServlet处理的请求,通过使用URL映射在同一个web.xml文件中。这是一个标准的Java EE Servlet 配置;下面的例子向你展示了一个DispatcherServlet的声明以及映射:

<web-app>
<servlet>
    <servlet-name>example</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>example</servlet-name>
    <url-pattern>/example/*</url-pattern>
</servlet-mapping>
</web-app>


在前面的例子中,所有的以/example 开头的请求将会被命名为example的DispatcherServlet实体处理。在一个Servlet3.0以上的环境中,你也可以选择以编程的方式配置Servlet容器。下面是的代码基本等效于上面的web.xml例子:

public classMyWebApplicationInitializer implements WebApplicationInitializer{
    @Override
    public void onStartup(ServletContext container){
            ServletRegistration.Dynamic registration=container.addServlet("dispatcher",newDispatcherServlet());
            registration.setLoadOnStartup(1);
            registration.addMapping("/example/*");
        }
}

WebApplicationInitializer是一个Spring MVC提供的接口用来确保你的基于代码的配置能够被检测到并自动被用来初始化任何类型的Servlet 3容器。一个实现了该接口的抽象基类AbstractDispatcherServletInitializer使注册DisapatcherServlet变得更加容易,只需要简单的制定的servlet 的映射。在Code-based Servlet containerinitialization了解更多信息。

以上只是设置Spring Web MVC 框架的第一步。接下来你需要配置多种多样的Spring Web MVC框架需要使用的实体(除了DispatcherServlet以外的)。

正如在5.14节详细说明的一样“ApplicationContext的附加功能”,Spring中的Application -Context实体是有范围的。在Web MVC框架中,每一个DispatcherServlet有它自己的Web Appli -cationContext,这个WebApplicationContext继承所有已经在根Web ApplicationContext中定义的实体。这些被继承的实体可以在特定的Servelt范围内被重写,你也可以为一个给定的Ser -vlet实体定义新的特定范围的实体。

在初始化一个DispatcherServlet 的时候,SpringMVC 会在你的web项目的WEB-INF目录下去寻找一个以[servlet-name]-servlet.xml命名规范命名的配置文件并会创建在这个配置文件中声明的实体,也会重写在全局范围内以相同名称被定义的实体。

思考下面的DispatcherServlet配置(在 web.xml中):

<web-app>
<servlet>
    <servlet-name>golfing</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>golfing</servlet-name>
    <url-pattern>/golfing/*</url-pattern>
</servlet-mapping>
</web-app>


如果你的项目中用到了上面这中配置,那么在你项目中需要有这样一个配置文件:WEB-INF/golfi -ng -servlet.xml;这个文件中包含有跟你的Spring MVC框架相关的组件。你可以使用Servelt初始化参数来改变这个这个配置文件的确切位置(将在下文中做详细介绍)。

WebApplicationContext是对原始的ApplicationContext的扩展,增加了一些web应用需要的功能。WebApplicationContext跟一般的ApplicationContext的不同之处在于它具有解析主题的能力并且它知道自己跟哪个Servlet相关联(WebApplicationContext引用了ServletContext)。WebApplicationContext被绑定到ServletContext上,当你需要访问WebApplicationContext的时候你可以使用RequestContextUtils提供的静态方法来获取WebApplicationContext。

WebApplicationContext中的特殊实体

Spring 的DispatcherServlet利用特殊的实体来处理来之页面的请求并且渲染合适的视图。这些实体是Spring MVC的一部分。你可以根据自己的需要在配置这些实体。Spring MVC 维护有一组默认的实体,当你没做任何的配置的时候,那些默认的实体将会被使用,因此你不一定必须配置实体。更多信息将在下一节中讲述。先看看下面的表格,列出了DispatcherServlet所依赖的一些特殊的实体。
表 17.1. WebApplicationContext中的特殊类型的实体

实体类型

说明

HandlerMapping

将请求映射到对应的处理器以及以系列的前置或后置处理(处理者拦截器)根据一些标准,这些标准的细节可以被HandlerMapping 的实现多样化。最受欢迎的实现支持带有注解的控制器但是也有其他类型实现。

HandlerAdapter

帮助DispatcherServlet调用映射到请求的处理器,而不用管实际调用的是那个处理者。比如,调用一个有注解的控制器需要解析多个注解。因此HandlerAdapter 的作用就是对DispatcherServlet隐藏这些细节。

HandlerExceptionResolver

将异常映射到视图或者更复杂的一场处理代码

ViewResolver

解析字符串类型的逻辑视图名称到实际的视图类型

LocaleResolver

解析用户的使用的地域,为了提供国际化视图

ThemeResolver

解析你的web应用可以使用的主题,比如想要提供个性化的布局

MultipartResolver

解析多部请求例如支持来自HTML表单的文件上传

FlashMapHandler

存储、检索输入和输出的FlashMap用来在请求之间传递属性,通常用在重定向的时候。

默认的DispatcherServlet配置

前面提到的每一个特定的实体DispatcherServlet都默认维护有一系列他们的实现。关于这些实体的信息保存在org.springframework.web.servlet包下面的DispatcherServlet.properties文件中。

所有的特定实体都有自己合理的默认值。尽管迟早你会你会定制这些实体的属性。比如,你会经常配置一个InternalResourceViewResolver并设置它的prefix属性为视图文件的父文件夹。

不用关注细节,理解这个地方的重要理论是一旦你配置了一个特殊的实体比如一个InternalReso –urceViewResolver在你的WebApplicationContext中,你实际上重写了默认的,本该被使用的实现列表。例如如果你配置了一个InternalResourcesViewResolver,默认的ViewResolver实现列表将会被忽略。

在17.15部分“配置Spring MVC”你将了解配置Spring MVC的其他可选项,包括 用java文件配置MVC以及MVC XML的命名空间,那些知识仅仅向你提供了一个简单的切入点。假设你已经对Spring MVC如何工作有了一定的了解。不管你是以何种方式配置你的应用程序,在该部分讲解的基本概念都将对你有所帮助。

DispatcherServlet处理顺序

在你设置好一个DispatcherServlet以后,并且这个DispatcherServlet对应的请求到来,接着DispatcherServlet按照下面的步骤处理该请求:

1.   相应WebApplicationContext将会被寻找并且作为一个属性被绑定到请求上为了方便处理过程中用到的处理器和其他元素使用。默认情况下会被绑定到DispatcherServlet.WEB_APPLICATION_CO -NTEXT_ATTRIBUTE键下。

2.   地域解析器也会被绑定到请求上便于处理过程中的其他元素在处理请求(渲染视图、准备数据等)的时候可以确定使用区域。如果你不需要解析地域,那么你将不需要用它。

3.   主题解析器被绑定到请求上为了让视图这类处理元素知道使用哪种主题。如果你不适用主题,你可以忽略。

4.   如果你指定了多部件文件解析器,则会在请求中检查多部分;如果多部分被找到了,那么请求将会被封装为MultipartHttpServletRequest便于处理流程中接下来的元素来处理改请求。请看17.10,“Spring 的多部(文件上传)支持”获取跟多部处理有关的更多信息。

5.   一个合适的处理器被搜索。如果一个处理者被找到了,为了准备model或者渲染,跟该处理者(前置处理器,后置处理器,控制器)关联的执行链将会被执行。

6.   如果一个模型被返回,视图将会被渲染。如果没有模型返回,(可能是以为一个前置处理器或者后置处理器拦截了请求,也有可能因为安全原因),不会有视图被渲染,因为请求到此已经完成了。

声明在WebApplicationContext中的处理异常解析器收集处理请求过程中被抛出的异常。利用这些异常解析器你可以定制异常的处理行为。

Spring的DispatcherServlet也支持返回last-modification-date,像Servlet API规定的一样。决定某一请求的最后修改时间的处理流程是比较直观的:DispatcherServlet寻找一个合适的处理者映射并且检查这些处理者是否实现了LastModified接口。如果实现了,LastModified接口的Long getLastModified(request)方法的返回值将会被返回到客户端。

你可以在web.xml中声明Servlet的时候为DispatcherServlet设置初始化参数来定制个人的DispatcherServlet。下面的表中显示了支持的参数。

表17.2 DispatcherServlet初始化参数

参数

说明

contextClass

一个类实现了WebApplicationContext接口,实例化Servlet使用的上下文。默认情况下XmlWebapplicationContext被使用。

contextConfigLocation

一个被传递给上下文实例(contextClass指定的)的字符串用来指明上下文可以在哪里被找到。这个字符串可以包含多个子串(子串之间用逗号分隔)来初始化多个上下文。同一个实体的位置被定义两次的话靠后的位置将会起作用。

namespace

WebApplicationContext的命名空间。默认的是[servlet-name]-servlet

17.3控制器的实现

控制器可以访问应用程序行为通常你通过一个服务接口定义的。控制器翻译用户输入成为一个模型,对视图来说代表用户。Spring用很抽象的方法实现一个控制器,因此你可以创建多种多样的控制器。

Spring2.5为MVC控制器引入了基于注解的编程模型,可以使用@RequestMapping,@RequestPara -m,@ModelAttribute等。Servlet MVC 和Portlet都可以使用这些注解。以此种方式实现的控制器无需扩展特定的基类或者实现特定的接口。此外他们不会经常直接依赖Servlet或者Portle -t APIs,但是你可以轻松的配置对Servlet或Portlet的访问。

@Controller
public class HelloWorldController {
   @RequestMapping("/helloWorld")
   public String helloWorld(Model model){
      model.addAttribute("message","Hello World!");
      return "helloWorld";
   }
}


正如你看到一样,@Controller和@RequestMapping注解允许灵活的方法名和签名。在这个特定例子中这个方法接收一个Model并且以字符串的形式返回一个视图的逻辑名称,但是其他类型的接收参数和返回参数也是可以被使用的,将在这一章节的后面讲述。@Controller和@RequestMa -ppding以及许多其他的注解构成了Spring MVC实现的基石。该部分记载那些在Servl -et环境中最常使用的注解。

用@Controller定义一个控制器

@Controller注解表明一个特定的类起着控制器的作用。Spring 不要求你扩展任何的控制器基类或者引用Servelet API。如果需要你也可以引用特定的Servlet的功能。

@Controller注解扮演着一个原型对被注解的类来说,声明了类的扮演的角色。分配器扫描带有@Controller注解的类寻找被影射的方法并且找出@RequestMapping注解(请看下节)。

你可以用标准的Spring实体定义方法,明确的定义注解的控制器在分配器上下文中。@Controller原型也支持自动检测,与Spring通常支持在类路径上检测组件类并自动注册为他们定义的实体一致。

为了能够使用自动检测被注解的控制器,你需要在你的配置文件添加组件扫描。利用spring-context模式像下面列出的XML片段一样:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">
    <context:component-scan base-package="org.springframework.samples.petclinic.web"/>
</beans>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Not Using Commons Logging ................................................................... 12 Using SLF4J ............................................................................................ 13 Using Log4J ............................................................................................. 14 II. What’s New in Spring Framework 4.x .................................................................................... 16 3. New Features and Enhancements in Spring Framework 4.0 ............................................ 17 3.1. Improved Getting Started Experience .................................................................. 17 3.2. Removed Deprecated Packages and Methods .................................................... 17 3.3. Java 8 (as well as 6 and 7) ............................................................................... 17 3.4. Java EE 6 and 7 ............................................................................................... 18 3.5. Groovy Bean Definition DSL .............................................................................. 18 3.6. Core Container Improvements ............................................................................ 19 3.7. General Web Improvements ............................................................................... 19 3.8. WebSocket, SockJS, and STOMP Messaging ..................................................... 19 3.9. Testing Improvements ........................................................................................ 20 III. Core Technologies .............................................................................................................. 21 4. The IoC container ........................................................................................................ 22 4.1. Introduction to the Spring IoC container and beans .............................................. 22 4.2. Container overview ............................................................................................ 22 Configuration metadata ..................................................................................... 23 Instantiating a container .................................................................................... 24 Composing XML-based configuration metadata .......................................... 25 Using the container .......................................................................................... 26 4.3. Bean overview ................................................................................................... 27 Naming beans .................................................................................................. 28 Aliasing a bean outside the bean definition ................................................ 28 Instantiating beans ........................................................................................... 29 Instantiation with a constructor .................................................................. 29 Instantiation with a static factory method .................................................... 30 Spring Framework 4.0.0.RELEASE Spring Framework Reference Documentation iii Instantiation using an instance factory method ........................................... 30 4.4. Dependencies ................................................................................................... 32 Dependency injection ....................................................................................... 32 Constructor-based dependency injection .................................................... 32 Setter-based dependency injection ............................................................ 34 Dependency resolution process ................................................................. 35 Examples of dependency injection ............................................................. 36 Dependencies and configuration in detail ........................................................... 38 Straight values (primitives, Strings, and so on) ........................................... 38 References to other beans (collaborators) .................................................. 40 Inner beans .............................................................................................. 41 Collections ............................................................................................... 41 Null and empty string values ..................................................................... 44 XML shortcut with the p-namespace .......................................................... 44 XML shortcut with the c-namespace .......................................................... 46 Compound property names ....................................................................... 46 Using depends-on ............................................................................................ 47 Lazy-initialized beans ....................................................................................... 47 Autowiring collaborators .................................................................................... 48 Limitations and disadvantages of autowiring ............................................... 49 Excluding a bean from autowiring .............................................................. 50 Method injection ............................................................................................... 50 Lookup method injection ........................................................................... 51 Arbitrary method replacement ................................................................... 53 4.5. Bean scopes ..................................................................................................... 54 The singleton scope ......................................................................................... 55 The prototype scope ......................................................................................... 55 Singleton beans with prototype-bean dependencies ............................................ 56 Request, session, and global session scopes .................................................... 56 Initial web configuration ............................................................................ 57 Request scope ......................................................................................... 58 Session scope .......................................................................................... 58 Global session scope ............................................................................... 58 Scoped beans as dependencies ................................................................ 58 Custom scopes ................................................................................................ 60 Creating a custom scope .......................................................................... 60 Using a custom scope .............................................................................. 61 4.6. Customizing the nature of a bean ....................................................................... 62 Lifecycle callbacks ............................................................................................ 62 Initialization callbacks ............................................................................... 63 Destruction callbacks ................................................................................ 64 Default initialization and destroy methods .................................................. 64 Combining lifecycle mechanisms ............................................................... 66 Startup and shutdown callbacks ................................................................ 66 Shutting down the Spring IoC container gracefully in non-web applications ................................................................................................................. 68 ApplicationContextAware and BeanNameAware ................................................. 68 Other Aware interfaces ..................................................................................... 69 4.7. Bean definition inheritance ................................................................................. 71 4.8. Container Extension Points ................................................................................ 72 Spring Framework 4.0.0.RELEASE Spring Framework Reference Documentation iv Customizing beans using a BeanPostProcessor ................................................. 72 Example: Hello World, BeanPostProcessor-style ........................................ 74 Example: The RequiredAnnotationBeanPostProcessor ............................... 75 Customizing configuration metadata with a BeanFactoryPostProcessor ................ 75 Example: the Class name substitution PropertyPlaceholderConfigurer .......... 76 Example: the PropertyOverrideConfigurer .................................................. 77 Customizing instantiation logic with a FactoryBean ............................................. 78 4.9. Annotation-based container configuration ............................................................ 79 @Required ....................................................................................................... 80 @Autowired ..................................................................................................... 80 Fine-tuning annotation-based autowiring with qualifiers ....................................... 83 Using generics as autowiring qualifiers .............................................................. 89 CustomAutowireConfigurer ................................................................................ 90 @Resource ...................................................................................................... 90 @PostConstruct and @PreDestroy .................................................................... 92 4.10. Classpath scanning and managed components ................................................. 92 @Component and further stereotype annotations ............................................... 93 Meta-annotations .............................................................................................. 93 Automatically detecting classes and registering bean definitions .......................... 94 Using filters to customize scanning ................................................................... 95 Defining bean metadata within components ....................................................... 96 Naming autodetected components ..................................................................... 97 Providing a scope for autodetected components ................................................ 98 Providing qualifier metadata with annotations ..................................................... 99 4.11. Using JSR 330 Standard Annotations ............................................................... 99 Dependency Injection with @Inject and @Named ............................................. 100 @Named: a standard equivalent to the @Component annotation ....................... 100 Limitations of the standard approach ............................................................... 101 4.12. Java-based container configuration ................................................................. 102 Basic concepts: @Bean and @Configuration ................................................... 102 Instantiating the Spring container using AnnotationConfigApplicationContext ....... 103 Simple construction ................................................................................ 103 Building the container programmatically using register(Class<?>…) ........... 104 Enabling component scanning with scan(String…) .................................... 104 Support for web applications with AnnotationConfigWebApplicationContext ............................................................................................................... 105 Using the @Bean annotation .......................................................................... 106 Declaring a bean .................................................................................... 107 Receiving lifecycle callbacks ................................................................... 107 Specifying bean scope ............................................................................ 108 Customizing bean naming ....................................................................... 109 Bean aliasing ......................................................................................... 109 Bean description ..................................................................................... 110 Using the @Configuration annotation ............................................................... 110 Injecting inter-bean dependencies ............................................................ 110 Lookup method injection ......................................................................... 111 Further information about how Java-based configuration works internally .... 111 Composing Java-based configurations ............................................................. 112 Using the @Import annotation ................................................................. 112 Conditionally including @Configuration classes or @Beans ....................... 116 Spring Framework 4.0.0.RELEASE Spring Framework Reference Documentation v Combining Java and XML configuration ................................................... 117 4.13. Bean definition profiles and environment abstraction ........................................ 120 4.14. PropertySource Abstraction ............................................................................ 120 4.15. Registering a LoadTimeWeaver ...................................................................... 120 4.16. Additional Capabilities of the ApplicationContext .............................................. 120 Internationalization using MessageSource ........................................................ 121 Standard and Custom Events .......................................................................... 124 Convenient access to low-level resources ........................................................ 127 Convenient ApplicationContext instantiation for web applications ....................... 128 Deploying a Spring ApplicationContext as a J2EE RAR file ............................... 128 4.17. The BeanFactory ........................................................................................... 129 BeanFactory or ApplicationContext? ................................................................ 129 Glue code and the evil singleton ..................................................................... 131 5. Resources .................................................................................................................. 132 5.1. Introduction ..................................................................................................... 132 5.2. The Resource interface .................................................................................... 132 5.3. Built-in Resource implementations .................................................................... 133 UrlResource ................................................................................................... 133 ClassPathResource ........................................................................................ 133 FileSystemResource ....................................................................................... 134 ServletContextResource .................................................................................. 134 InputStreamResource ..................................................................................... 134 ByteArrayResource ......................................................................................... 134 5.4. The ResourceLoader ....................................................................................... 134 5.5. The ResourceLoaderAware interface ................................................................ 135 5.6. Resources as dependencies ............................................................................. 136 5.7. Application contexts and Resource paths .......................................................... 137 Constructing application contexts ..................................................................... 137 Constructing ClassPathXmlApplicationContext instances - shortcuts .......... 137 Wildcards in application context constructor resource paths ............................... 138 Ant-style Patterns ................................................................................... 138 The Classpath*: portability classpath*: prefix ............................................ 139 Other notes relating to wildcards ............................................................. 139 FileSystemResource caveats .......................................................................... 140 6. Validation, Data Binding, and Type Conversion ............................................................ 141 6.1. Introduction ..................................................................................................... 141 6.2. Validation using Spring’s Validator interface ...................................................... 141 6.3. Resolving codes to error messages .................................................................. 143 6.4. Bean manipulation and the BeanWrapper ......................................................... 144 Setting and getting basic and nested properties ............................................... 144 Built-in PropertyEditor implementations ............................................................ 146 Registering additional custom PropertyEditors .......................................... 149 6.5. Spring Type Conversion ................................................................................... 151 Converter SPI ................................................................................................ 151 ConverterFactory ............................................................................................ 152 GenericConverter ........................................................................................... 153 ConditionalGenericConverter ................................................................... 154 ConversionService API ................................................................................... 154 Configuring a ConversionService ..................................................................... 154 Using a ConversionService programmatically ................................................... 155 Spring Framework 4.0.0.RELEASE Spring Framework Reference Documentation vi 6.6. Spring Field Formatting .................................................................................... 155 Formatter SPI ................................................................................................. 156 Annotation-driven Formatting ........................................................................... 157 Format Annotation API ............................................................................ 158 FormatterRegistry SPI ..................................................................................... 159 FormatterRegistrar SPI ................................................................................... 159 Configuring Formatting in Spring MVC ............................................................. 159 6.7. Configuring a global date & time format ............................................................ 161 6.8. Spring Validation ............................................................................................. 163 Overview of the JSR-303 Bean Validation API ................................................. 163 Configuring a Bean Validation Provider ............................................................ 164 Injecting a Validator ................................................................................ 164 Configuring Custom Constraints .............................................................. 164 Additional Configuration Options .............................................................. 165 Configuring a DataBinder ................................................................................ 165 Spring MVC 3 Validation ................................................................................. 166 Triggering @Controller Input Validation .................................................... 166 Configuring a Validator for use by Spring MVC ......................................... 166 Configuring a JSR-303/JSR-349 Validator for use by Spring MVC .............. 167 7. Spring Expression Language (SpEL) ........................................................................... 168 7.1. Introduction ..................................................................................................... 168 7.2. Feature Overview ............................................................................................ 168 7.3. Expression Evaluation using Spring’s Expression Interface ................................. 169 The EvaluationContext interface ...................................................................... 171 Type Conversion .................................................................................... 171 7.4. Expression support for defining bean definitions ................................................ 172 XML based configuration ................................................................................ 172 Annotation-based configuration ........................................................................ 173 7.5. Language Reference ........................................................................................ 174 Literal expressions .......................................................................................... 174 Properties, Arrays, Lists, Maps, Indexers ......................................................... 174 Inline lists ....................................................................................................... 175 Array construction ........................................................................................... 175 Methods ......................................................................................................... 176 Operators ....................................................................................................... 176 Relational operators ................................................................................ 176 Logical operators .................................................................................... 177 Mathematical operators ........................................................................... 177 Assignment .................................................................................................... 178 Types ............................................................................................................. 178 Constructors ................................................................................................... 179 Variables ........................................................................................................ 179 The #this and #root variables .................................................................. 179 Functions ....................................................................................................... 180 Bean references ............................................................................................. 180 Ternary Operator (If-Then-Else) ....................................................................... 180 The Elvis Operator ......................................................................................... 181 Safe Navigation operator ................................................................................ 181 Collection Selection ........................................................................................ 182 Collection Projection ....................................................................................... 182 Spring Framework 4.0.0.RELEASE Spring Framework Reference Documentation vii Expression templating ..................................................................................... 183 7.6. Classes used in the examples .......................................................................... 183 8. Aspect Oriented Programming with Spring ................................................................... 187 8.1. Introduction ..................................................................................................... 187 AOP concepts ................................................................................................ 187 Spring AOP capabilities and goals ................................................................... 189 AOP Proxies .................................................................................................. 190 8.2. @AspectJ support ........................................................................................... 190 Enabling @AspectJ Support ............................................................................ 190 Enabling @AspectJ Support with Java configuration ................................. 190 Enabling @AspectJ Support with XML configuration ................................. 191 Declaring an aspect ........................................................................................ 191 Declaring a pointcut ........................................................................................ 192 Supported Pointcut Designators .............................................................. 192 Combining pointcut expressions .............................................................. 194 Sharing common pointcut definitions ........................................................ 194 Examples ............................................................................................... 196 Writing good pointcuts ............................................................................ 198 Declaring advice ............................................................................................. 199 Before advice ......................................................................................... 199 After returning advice .............................................................................. 200 After throwing advice .............................................................................. 200 After (finally) advice ................................................................................ 201 Around advice ........................................................................................ 202 Advice parameters .................................................................................. 203 Advice ordering ...................................................................................... 206 Introductions ................................................................................................... 206 Aspect instantiation models ............................................................................. 207 Example ......................................................................................................... 208 8.3. Schema-based AOP support ............................................................................ 209 Declaring an aspect ........................................................................................ 210 Declaring a pointcut ........................................................................................ 210 Declaring advice ............................................................................................. 212 Before advice ......................................................................................... 212 After returning advice .............................................................................. 212 After throwing advice .............................................................................. 213 After (finally) advice ................................................................................ 214 Around advice ........................................................................................ 214 Advice parameters .................................................................................. 215 Advice ordering ...................................................................................... 216 Introductions ................................................................................................... 217 Aspect instantiation models ............................................................................. 217 Advisors ......................................................................................................... 217 Example ......................................................................................................... 218 8.4. Choosing which AOP declaration style to use .................................................... 220 Spring AOP or full AspectJ? ........................................................................... 220 @AspectJ or XML for Spring AOP? ................................................................. 221 8.5. Mixing aspect types ......................................................................................... 222 8.6. Proxying mechanisms ...................................................................................... 222 Understanding AOP proxies ............................................................................ 223 Spring Framework 4.0.0.RELEASE Spring Framework Reference Documentation viii 8.7. Programmatic creation of @AspectJ Proxies ..................................................... 225 8.8. Using AspectJ with Spring applications ............................................................. 225 Using AspectJ to dependency inject domain objects with Spring ........................ 226 Unit testing @Configurable objects .......................................................... 228 Working with multiple application contexts ................................................ 228 Other Spring aspects for AspectJ .................................................................... 229 Configuring AspectJ aspects using Spring IoC ................................................. 229 Load-time weaving with AspectJ in the Spring Framework ................................. 230 A first example ....................................................................................... 231 Aspects .................................................................................................. 234 ' META-INF/aop.xml' ............................................................................... 234 Required libraries (JARS) ........................................................................ 234 Spring configuration ................................................................................ 235 Environment-specific configuration ........................................................... 237 8.9. Further Resources ........................................................................................... 239 9. Spring AOP APIs ....................................................................................................... 240 9.1. Introduction ..................................................................................................... 240 9.2. Pointcut API in Spring ...................................................................................... 240 Concepts ........................................................................................................ 240 Operations on pointcuts .................................................................................. 241 AspectJ expression pointcuts .......................................................................... 241 Convenience pointcut implementations ............................................................ 241 Static pointcuts ....................................................................................... 241 Dynamic pointcuts .................................................................................. 242 Pointcut superclasses ..................................................................................... 243 Custom pointcuts ............................................................................................ 243 9.3. Advice API in Spring ........................................................................................ 243 Advice lifecycles ............................................................................................. 243 Advice types in Spring .................................................................................... 244 Interception around advice ...................................................................... 244 Before advice ......................................................................................... 244 Throws advice ........................................................................................ 245 After Returning advice ............................................................................ 246 Introduction advice .................................................................................. 247 9.4. Advisor API in Spring ....................................................................................... 249 9.5. Using the ProxyFactoryBean to create AOP proxies ........................................... 250 Basics ............................................................................................................ 250 JavaBean properties ....................................................................................... 250 JDK- and CGLIB-based proxies ...................................................................... 251 Proxying interfaces ......................................................................................... 252 Proxying classes ............................................................................................ 254 Using global advisors ...................................................................................... 255 9.6. Concise proxy definitions ................................................................................. 255 9.7. Creating AOP proxies programmatically with the ProxyFactory ............................ 256 9.8. Manipulating advised objects ............................................................................ 257 9.9. Using the "auto-proxy" facility ........................................................................... 258 Autoproxy bean definitions .............................................................................. 258 BeanNameAutoProxyCreator ................................................................... 259 DefaultAdvisorAutoProxyCreator .............................................................. 259 AbstractAdvisorAutoProxyCreator ............................................................ 260 Spring Framework 4.0.0.RELEASE Spring Framework Reference Documentation ix Using metadata-driven auto-proxying ............................................................... 260 9.10. Using TargetSources ...................................................................................... 262 Hot swappable target sources ......................................................................... 263 Pooling target sources .................................................................................... 263 Prototype target sources ................................................................................. 265 ThreadLocal target sources ............................................................................. 265 9.11. Defining new Advice types ............................................................................. 265 9.12. Further resources ........................................................................................... 266 10. Testing ..................................................................................................................... 267 10.1. Introduction to Spring Testing ......................................................................... 267 10.2. Unit Testing ................................................................................................... 267 Mock Objects ................................................................................................. 267 Environment ........................................................................................... 267 JNDI ...................................................................................................... 267 Servlet API ............................................................................................. 267 Portlet API ............................................................................................. 268 Unit Testing support Classes .......................................................................... 268 General utilities ...................................................................................... 268 Spring MVC ........................................................................................... 268 10.3. Integration Testing ......................................................................................... 268 Overview ........................................................................................................ 268 Goals of Integration Testing ............................................................................ 269 Context management and caching ........................................................... 269 Dependency Injection of test fixtures ....................................................... 269 Transaction management ........................................................................ 270 Support classes for integration testing ..................................................... 270 JDBC Testing Support .................................................................................... 271 Annotations .................................................................................................... 271 Spring Testing Annotations ..................................................................... 271 Standard Annotation Support .................................................................. 276 Spring JUnit Testing Annotations ............................................................. 277 Meta-Annotation Support for Testing ........................................................ 278 Spring TestContext Framework ....................................................................... 279 Key abstractions ..................................................................................... 280 Context management .............................................................................. 281 Dependency injection of test fixtures ........................................................ 297 Testing request and session scoped beans .............................................. 299 Transaction management ........................................................................ 301 TestContext Framework support classes .................................................. 304 Spring MVC Test Framework .......................................................................... 306 Server-Side Tests ................................................................................... 306 Client-Side REST Tests .......................................................................... 312 PetClinic Example .......................................................................................... 313 10.4. Further Resources ......................................................................................... 314 IV. Data Access ..................................................................................................................... 316 11. Transaction Management .......................................................................................... 317 11.1. Introduction to Spring Framework transaction management .............................. 317 11.2. Advantages of the Spring Framework’s transaction support model ..................... 317 Global transactions ......................................................................................... 317 Local transactions ........................................................................................... 318 Spring Framework 4.0.0.RELEASE Spring Framework Reference Documentation x Spring Framework’s consistent programming model ......................................... 318 11.3. Understanding the Spring Framework transaction abstraction ............................ 319 11.4. Synchronizing resources with transactions ....................................................... 323 High-level synchronization approach ................................................................ 323 Low-level synchronization approach ................................................................. 323 TransactionAwareDataSourceProxy ................................................................. 324 11.5. Declarative transaction management ............................................................... 324 Understanding the Spring Framework’s declarative transaction implementation ... 325 Example of declarative transaction implementation ........................................... 326 Rolling back a declarative transaction .............................................................. 330 Configuring different transactional semantics for different beans ........................ 331 <tx:advice/> settings ....................................................................................... 333 Using @Transactional ..................................................................................... 335 @Transactional settings .......................................................................... 339 Multiple Transaction Managers with @Transactional ................................. 340 Custom shortcut annotations ................................................................... 341 Transaction propagation .................................................................................. 341 Required ................................................................................................ 342 RequiresNew .......................................................................................... 342 Nested ................................................................................................... 343 Advising transactional operations ..................................................................... 343 Using @Transactional with AspectJ ................................................................. 346 11.6. Programmatic transaction management ........................................................... 347 Using the TransactionTemplate ....................................................................... 347 Specifying transaction settings ................................................................ 349 Using the PlatformTransactionManager ............................................................ 349 11.7. Choosing between programmatic and declarative transaction management ........ 350 11.8. Application server-specific integration .............................................................. 350 IBM WebSphere ............................................................................................. 351 Oracle WebLogic Server ................................................................................. 351 11.9. Solutions to common problems ....................................................................... 351 Use of the wrong transaction manager for a specific DataSource ....................... 351 11.10. Further Resources ....................................................................................... 351 12. DAO support ............................................................................................................ 352 12.1. Introduction .................................................................................................... 352 12.2. Consistent exception hierarchy ....................................................................... 352 12.3. Annotations used for configuring DAO or Repository classes ............................ 353 13. Data access with JDBC ............................................................................................ 355 13.1. Introduction to Spring Framework JDBC .......................................................... 355 Choosing an approach for JDBC database access ........................................... 355 Package hierarchy .......................................................................................... 356 13.2. Using the JDBC core classes to control basic JDBC processing and error handling ................................................................................................................. 357 JdbcTemplate ................................................................................................. 357 Examples of JdbcTemplate class usage ................................................... 357 JdbcTemplate best practices ................................................................... 359 NamedParameterJdbcTemplate ....................................................................... 361 SQLExceptionTranslator .................................................................................. 363 Executing statements ...................................................................................... 365 Running queries ............................................................................................. 365 Spring Framework 4.0.0.RELEASE Spring Framework Reference Documentation xi Updating the database .................................................................................... 366 Retrieving auto-generated keys ....................................................................... 367 13.3. Controlling database connections .................................................................... 367 DataSource .................................................................................................... 367 DataSourceUtils .............................................................................................. 369 SmartDataSource ........................................................................................... 369 AbstractDataSource ........................................................................................ 369 SingleConnectionDataSource .......................................................................... 369 DriverManagerDataSource .............................................................................. 369 TransactionAwareDataSourceProxy ................................................................. 370 DataSourceTransactionManager ...................................................................... 370 NativeJdbcExtractor ........................................................................................ 370 13.4. JDBC batch operations .................................................................................. 371 Basic batch operations with the JdbcTemplate ................................................. 371 Batch operations with a List of objects ............................................................. 372 Batch operations with multiple batches ............................................................ 373 13.5. Simplifying JDBC operations with the SimpleJdbc classes ................................ 374 Inserting data using SimpleJdbcInsert .............................................................. 374 Retrieving auto-generated keys using SimpleJdbcInsert .................................... 375 Specifying columns for a SimpleJdbcInsert ...................................................... 376 Using SqlParameterSource to provide parameter values ................................... 376 Calling a stored procedure with SimpleJdbcCall ............................................... 377 Explicitly declaring parameters to use for a SimpleJdbcCall ............................... 379 How to define SqlParameters .......................................................................... 380 Calling a stored function using SimpleJdbcCall ................................................. 381 Returning ResultSet/REF Cursor from a SimpleJdbcCall ................................... 381 13.6. Modeling JDBC operations as Java objects ..................................................... 382 SqlQuery ........................................................................................................ 383 MappingSqlQuery ........................................................................................... 383 SqlUpdate ...................................................................................................... 384 StoredProcedure ............................................................................................. 385 13.7. Common problems with parameter and data value handling .............................. 388 Providing SQL type information for parameters ................................................. 389 Handling BLOB and CLOB objects .................................................................. 389 Passing in lists of values for IN clause ............................................................ 390 Handling complex types for stored procedure calls ........................................... 391 13.8. Embedded database support .......................................................................... 392 Why use an embedded database? .................................................................. 392 Creating an embedded database instance using Spring XML ............................ 392 Creating an embedded database instance programmatically .............................. 392 Extending the embedded database support ...................................................... 393 Using HSQL ................................................................................................... 393 Using H2 ........................................................................................................ 393 Using Derby ................................................................................................... 393 Testing data access logic with an embedded database ..................................... 393 13.9. Initializing a DataSource ................................................................................. 394 Initializing a database instance using Spring XML ............................................. 394 Initialization of Other Components that Depend on the Database ............... 395 14. Object Relational Mapping (ORM) Data Access .......................................................... 397 14.1. Introduction to ORM with Spring ..................................................................... 397 Spring Framework 4.0.0.RELEASE Spring Framework Reference Documentation xii 14.2. General ORM integration considerations ......................................................... 398 Resource and transaction management ........................................................... 398 Exception translation ....................................................................................... 399 14.3. Hibernate ....................................................................................................... 399 SessionFactory setup in a Spring container ...................................................... 400 Implementing DAOs based on plain Hibernate 3 API ........................................ 400 Declarative transaction demarcation ................................................................ 402 Programmatic transaction demarcation ............................................................ 404 Transaction management strategies ................................................................ 405 Comparing container-managed and locally defined resources ............................ 407 Spurious application server warnings with Hibernate ......................................... 408 14.4. JDO .............................................................................................................. 409 PersistenceManagerFactory setup ................................................................... 409 Implementing DAOs based on the plain JDO API ............................................. 410 Transaction management ................................................................................ 412 JdoDialect ...................................................................................................... 413 14.5. JPA ............................................................................................................... 414 Three options for JPA setup in a Spring environment ........................................ 414 LocalEntityManagerFactoryBean .............................................................. 414 Obtaining an EntityManagerFactory from JNDI ......................................... 415 LocalContainerEntityManagerFactoryBean ............................................... 415 Dealing with multiple persistence units ..................................................... 417 Implementing DAOs based on plain JPA .......................................................... 418 Transaction Management ................................................................................ 420 JpaDialect ...................................................................................................... 421 15. Marshalling XML using O/X Mappers ......................................................................... 423 15.1. Introduction .................................................................................................... 423 Ease of configuration ...................................................................................... 423 Consistent Interfaces ...................................................................................... 423 Consistent Exception Hierarchy ....................................................................... 423 15.2. Marshaller and Unmarshaller .......................................................................... 423 Marshaller ...................................................................................................... 423 Unmarshaller .................................................................................................. 424 XmlMappingException ..................................................................................... 425 15.3. Using Marshaller and Unmarshaller ................................................................. 425 15.4. XML Schema-based Configuration .................................................................. 427 15.5. JAXB ............................................................................................................. 427 Jaxb2Marshaller ............................................................................................. 428 XML Schema-based Configuration ........................................................... 428 15.6. Castor ........................................................................................................... 429 CastorMarshaller ............................................................................................ 429 Mapping ......................................................................................................... 429 XML Schema-based Configuration ........................................................... 429 15.7. XMLBeans ..................................................................................................... 430 XmlBeansMarshaller ....................................................................................... 430 XML Schema-based Configuration ........................................................... 430 15.8. JiBX .............................................................................................................. 431 JibxMarshaller ................................................................................................ 431 XML Schema-based Configuration ........................................................... 431 15.9. XStream ........................................................................................................ 432 Spring Framework 4.0.0.RELEASE Spring Framework Reference Documentation xiii XStreamMarshaller ......................................................................................... 432 V. The Web ........................................................................................................................... 434 16. Web MVC framework ................................................................................................ 435 16.1. Introduction to Spring Web MVC framework .................................................... 435 Features of Spring Web MVC ......................................................................... 436 Pluggability of other MVC implementations ...................................................... 437 16.2. The DispatcherServlet .................................................................................... 437 Special Bean Types In the WebApplicationContext ........................................... 440 Default DispatcherServlet Configuration ........................................................... 441 DispatcherServlet Processing Sequence .......................................................... 441 16.3. Implementing Controllers ................................................................................ 443 Defining a controller with @Controller .............................................................. 443 Mapping Requests With Using @RequestMapping ........................................... 444 New Support Classes for @RequestMapping methods in Spring MVC 3.1 .. 446 URI Template Patterns ........................................................................... 447 URI Template Patterns with Regular Expressions ..................................... 448 Path Patterns ......................................................................................... 449 Patterns with Placeholders ...................................................................... 449 Matrix Variables ...................................................................................... 449 Consumable Media Types ....................................................................... 450 Producible Media Types .......................................................................... 451 Request Parameters and Header Values ................................................. 451 Defining @RequestMapping handler methods .................................................. 452 Supported method argument types .......................................................... 452 Supported method return types ............................................................... 454 Binding request parameters to method parameters with @RequestParam ... 455 Mapping the request body with the @RequestBody annotation .................. 456 Mapping the response body with the @ResponseBody annotation ............. 457 Creating REST Controllers with the @RestController annotation ................ 457 Using HttpEntity ...................................................................................... 457 Using @ModelAttribute on a method ....................................................... 458 Using @ModelAttribute on a method argument ......................................... 459 Using @SessionAttributes to store model attributes in the HTTP session between requests ................................................................................... 461 Specifying redirect and flash attributes ..................................................... 461 Working with "application/x-www-form-urlencoded" data ............................ 462 Mapping cookie values with the @CookieValue annotation ........................ 462 Mapping request header attributes with the @RequestHeader annotation ... 463 Method Parameters And Type Conversion ............................................... 463 Customizing WebDataBinder initialization ................................................. 464 Support for the Last-Modified Response Header To Facilitate Content Caching ................................................................................................. 465 Assisting Controllers with the @ControllerAdvice annotation ...................... 465 Asynchronous Request Processing .................................................................. 466 Exception Handling for Async Requests ................................................... 467 Intercepting Async Requests ................................................................... 467 Configuration for Async Request Processing ............................................ 468 Testing Controllers ......................................................................................... 469 16.4. Handler mappings .......................................................................................... 469 Intercepting requests with a HandlerInterceptor ................................................ 469 Spring Framework 4.0.0.RELEASE Spring Framework Reference Documentation xiv 16.5. Resolving views ............................................................................................. 471 Resolving views with the ViewResolver interface .............................................. 471 Chaining ViewResolvers ................................................................................. 473 Redirecting to views ....................................................................................... 474 RedirectView .......................................................................................... 474 The redirect: prefix ................................................................................. 475 The forward: prefix ................................................................................. 475 ContentNegotiatingViewResolver ..................................................................... 475 16.6. Using flash attributes ..................................................................................... 478 16.7. Building URIs ................................................................................................. 479 16.8. Building URIs to Controllers and methods ....................................................... 480 16.9. Using locales ................................................................................................. 480 Obtaining Time Zone Information .................................................................... 481 AcceptHeaderLocaleResolver .......................................................................... 481 CookieLocaleResolver ..................................................................................... 481 SessionLocaleResolver ................................................................................... 481 LocaleChangeInterceptor ................................................................................ 482 16.10. Using themes ............................................................................................... 482 Overview of themes ........................................................................................ 482 Defining themes ............................................................................................. 482 Theme resolvers ............................................................................................. 483 16.11. Spring’s multipart (file upload) support ........................................................... 483 Introduction .................................................................................................... 483 Using a MultipartResolver with Commons FileUpload ........................................ 484 Using a MultipartResolver with Servlet 3.0 ....................................................... 484 Handling a file upload in a form ...................................................................... 484 Handling a file upload request from programmatic clients .................................. 486 16.12. Handling exceptions ..................................................................................... 486 HandlerExceptionResolver ............

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值