Skip to main content

Web Application Edition (Validator, Listener, Interceptor)

Demonstrates a basic webmvc application. For more usage, refer to dawdler-client-plug-web.

1. Download and Run​

Download the sample dawdler-tutorial.zip.

After extracting it, go into the simple-single-web directory.

Run the main method of UserWebApplication.java.

@DawdlerBootApplication
public class UserWebApplication {
public static void main(String[] args) throws Throwable {
DawdlerWebApplication.run(UserWebApplication.class, args);
}
}

1.1 Project Structure​

controller -> UserController.java entry point of the web api

entity -> User.java entity class

1.2 Configuration Files​

1.2.1 undertow.yml​

Common web container configuration

undertow configuration

1.2.2 web-conf.xml​

Web configuration - component scanning

After startup, visit http://localhost:8085/user/info?id=1 with postman or a browser.

1.3 Validator Framework​

Validation rules are usually generated automatically from the database by the code generator.

For how to use the validator framework, refer to the dawdler-client-plug-validator module.

You can also look at UserController-validator.xml to learn how the validator framework is used.

1.4 Using Listeners​

The sample is in UserWebListener.java.

See WebContextListener - listener.

1.5 Using Interceptors​

The sample is in UserWebInterceptor.java.

See HandlerInterceptor - interceptor.

1.6 Running as a Jar​

Run

mvn clean package

to get simple-single-web-0.0.1-jdk25-SNAPSHOT-all.jar

Then run

java -jar simple-single-web-0.0.1-jdk25-SNAPSHOT-all.jar

1.7 Verification​

After startup, visit http://localhost:8085/user/info?id=1.