# 10.3 Validator Configuration

The configuration of a Validator is identical to that of an interceptor. You can use the @Before annotation to specify which Validator class should be used before invoking a particular action method in a controller. Here's a sample code snippet:

public class UserController extends Controller {
    @Before(LoginValidator.class)  // Configuration is identical to that of interceptors
    public void login() {
        // Login logic here
    }
}
1
2
3
4
5
6

In this example, the LoginValidator class is invoked before the login action method in the UserController. If the Validator passes, the login method will execute. If the Validator fails, the handleError method in the LoginValidator will be invoked. This setup allows you to isolate validation logic from your controller, making the code more maintainable and easier to test.

Last Updated: 9/22/2023, 7:24:41 AM