Comparison of WebWork2 and Spring MVC Framework

Comparison of WebWork2 and Spring MVC Framework

(1) Basic use of

     Spring MVC Framework and other parts of Spring can naturally be well integrated, without additional toolkits and configuration

     WebWork2 and Spring integration requires webwork2-spring.jar as a connector , and have to configure quite a few steps, but it is still simple

(2) The controller

       of the Spring MVC Framework should implement the Controller interface. The core of its processing is the handleRequest (form interaction is onSubmit) method. The main task is to construct the Model data and return it to The controller of the view display

       WebWork2 needs to extend the ActionSupport class (the default implementation of the Action interface). The core of its processing is the execute method. Since the Model data required by the view exists in the form of Action attributes, its main task is to set the values ​​of these attributes.

(3) Display view content

       Spring MVC Framework only provides taglibs for binding form field elements, and the view content display function is completed by JSTL.

       WebWork2 needs to use its own provided taglibs to display view content in order to make good use of its features, so no need JSTL

(4) Resource bundle access

      Spring MVC Framework provides a common method: specify (centrally) store the property file of the resource bundle, and can be used in good combination with JSTL's <fmt:message>

       WebWork2 uses the property file corresponding to the Action class name or its parent class name to store the resource bundle; the resource bundle can be scattered into the property file corresponding to each Action class name, or can be concentrated in the property file corresponding to the parent class name, use <ww: text>Access

(5) Form interaction

     Spring MVC Framework uses the Command object (POJO) to encapsulate the data passed by the form interaction, and uses taglibs to bind the properties of the Command object to the form field element to read and set the value of the form field element. Some Complex

     WebWork2 naturally binds Action attributes to form field elements, which is more concise and clear, but the processing of error messages after verification failure is not as simple as Spring MVC Framework

(6) Data validity verification

        Spring MVC Framework needs to write its own validator and validation rules Mixed with implementation logic, it is not conducive to reuse

        WebWork2 to provide a more flexible verification mechanism: first, the verification rules and implementation logic are separated, which is easy to reuse; secondly, WebWork2 and XWork provide common validators, so there is no need to write them yourself; In addition, the validation rules are saved in XML files. To modify the validation rules, you only need to modify the XML file without modifying the code. Finally, if there is no suitable validator, you can also extend the custom validator yourself, and write it once and reuse it

(7) Personal opinion

     I think it is better to use WebWork2 to implement the Web application layer. Although some additional configuration is required, WebWork2 has some advantages, such as the simplicity of the form interaction mentioned above, the separation of data validation rules and implementation, and the integration of OGNL features, Velocity technology, etc.

Note: Spring also supports a variety of web-layer frameworks such as Velocity. Without in-depth research, you can go and see for yourself and compare.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327050162&siteId=291194637