WebX framework instructions

foreword 

There are many standard MVC open source frameworks (Struts, SpringMVC, Webx). For coders living in the open source world, SpringMVC and Struts are the most familiar and familiar frameworks.

 

Know yourself and the enemy

Taking the configuration of SpringMVC as an example, we often focus on the following aspects:

1. The configuration of the request dispatcher (DispatcherServlet) in the web.xml file. As shown below:

Intercept HTTP requests ending with do.

 

2. View controller (ViewResolver), velocity, freemarker, jsp, etc. Take jsp as an example. As shown below:

All views are configured to be found in /WEB-INF/view.

 

3. Interceptor. As shown below:

 

4. Adapter (Handleradapter). As shown below:

Configure the mapping relationship between url requests and processing functions.

 

5. Request path mapping (HandlerMapping). As shown below:

The handler function is actually called through the HandlerAdapter.

 

After three or two configurations, the project can be successfully accessed.

Note: There are two main reasons why SpringMVC is used as an example.

  • SpringMVC, like Webx we will talk about later, is based on the Spring container.
  • SpringMVC is simpler

Webx framework

Homepage: http://openwebx.org/

Framework Guide: http://openwebx.org/docs/Webx3_Guide_Book.html

 

frame building

Execution environment: windows, maven

Steps:

1. Create a new directory, for example: D:\workspace. Note that it cannot be executed successfully in the drive letter directory.

2. Execute the following command:

mvn archetype:generate -DgroupId=com.alibaba.webx -DartifactId=mywebx -Dversion=1.0-SNAPSHOT -Dpackage=com.alibaba.webx.mywebx -DarchetypeArtifactId=archetype-webx-quickstart -DarchetypeGroupId=com.alibaba.citrus.sample -DarchetypeVersion=1.0 -DinteractiveMode=false

After the command is executed, you will see a new directory: mywebx. This project is actually a skeleton generated by Maven from the archetype of webx in the central repository. The archetype is archetype-webx-quickstart.

 

Framework

Webx solves the problem that a single project contains different architecture configurations. For example, when different permissions, business functions, and page display of the same member user are distinguished in the project according to business needs, the project can be divided from a business perspective and configured webx-account.xml, webx- gateway.xml, etc. Facilitate parallel business development.

(1) The specific implementation of business function modules;

(2) The page display of the business function module;

(3) Simple verification in the background of business function modules;

(4) The overall configuration for the business function;

 

Description of each configuration file in the WEB-INF folder

  • logback.xml: log configuration;
  • web.xml: WEB project initialization configuration information;
  • webx.xml: The general configuration of webx, the beans initialized by the webx container can be depended on by all sub-business containers.
  • webx-app1.xml: webx sub-business configuration, sub-business configuration can create spring container, but sub-business containers cannot be injected into each other.

For details, please refer to the framework specification "3.1. Initialization of Webx"

 

Description of each configuration file in the WEB-INF/common folder

  • pipeline.xml: Interceptor configuration file, equivalent to Interceptor in SpringMVC (Struts).
  • pipeline-exception.xml: Exception interception configuration file.
  • resources.xml: Resource file loading configuration, responsible for resource redirection, renaming, etc.
  • uris.xml: External address url call configuration file.
  • webx-component-and-root.xml: Configure template rendering engine, mapping rules, etc.
  • webx-component.xml: Defines tool classes that template pages can use directly.

It can be seen from these configurations that webx is similar to SpringMVC and Struts that we have contacted, but the former has more fine-grained control, while the latter we use more open source encapsulation, so there is less configuration.

 

Code structure and writing

For developers, the most important thing is to get started with this framework. From the project receiving the request to the server responding and returning the information, webx has its own rules, which are different from the open source frameworks we have come into contact with. As shown below:

Depending on whether there is action in the parameters in the Http request, the content executed by Webx in the code layer is also different.

 

Request without action parameter

The steps of webx execution are as follows:

Step 1. If the Login.java code exists in the control layer screen, execute the Login.java code.

Step 2: Execute login.vm in the layout of the template layer (if there is no layout template with the corresponding name in the layout, the default template default.vm will be called).

Step 3: Execute login.vm in the template layer screen.

 

Request with action parameter

The steps of webx execution are as follows:

Step 1. Execute the LoginController.java code in the control layer action. The specified class must exist, otherwise a 404 exception will occur.

Step 2: If the Login.java code exists in the control layer screen, execute the Login.java code.

Step 3. Execute login.vm in the layout of the template layer (if there is no layout template with the corresponding name in the layout, the default template default.vm will be called).

Step 4: Execute login.vm in the template layer screen.

 

Control layer action , screen layer writing

Webx stipulates that the default entry function of the action and screen layers is execute, that is, when the class name and the path can match (the path and the class name can be named in camel case, or they can be connected with an underscore "_" in the middle, only the first letter can be Ignore case), webx will execute the execute() method under the class name. Example:

 

Commonly used methods in engineering

Control layer action: handles user operation actions, such as logging in, submitting data, etc.

Control layer screen: Process the required content for page display.

In the old version of webx (version is less than webx3.0.9), a Java class in the screen layer can only handle one page. The action layer can handle multiple different business actions.

 

The action layer code has changed, the specific example is as follows:

(1) The specific method of access must be specified when submitting, and the prefix of "event_submit_" is required.

(2) When specifying a specific action, you need to pay attention to the package path.

 

interceptor

The configuration for interceptors in Webx is mainly concentrated in pipeline.xml. In daily business development, verification of login and permissions is inevitable, and this part of the business is perfect as an interceptor. For detailed configuration methods, please refer to the framework specification "6.3.3. Use of Pipeline".

Guess you like

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