Command handling
A command is used to change the state of an application. Commands allow you to express clear intentions which simplify understanding and debugging of the application.
In this module, commands are used to handle form submissions. The command handling process is divided into two parts: the command itself and the command handler.
Add the following dependency to your project's build.gradle
file:
Command
A command is a data class that represents the intention to change the state of the application. It should be a data class that implements the Command
interface. It is also possible to specify the return type of a command. In case you have nothing to return, specify it as Unit
.
Here is an example of a command:
Command handler
The command handler is a class that is used to handle the command. It should implement the CommandHandler
interface.
The execute()
method is used to execute the command.
The command handler also needs to be registered as a bean in the Spring context.
Here is an example of a command handler:
Decorator
Each command handler can be wrapped with a decorator. This allows you to add additional functionality to the command handler. Default decorators are provided these are useful for logging and error handling.
LogDecorator logs the command details.
ExecutionTimeDecorator logs the execution time of the command handler.
Last updated