Introduction
Spring boot provides Spring Shell using which we can a build CLI app. CLI app’s are interactive way to build the application without needing web ui interface.
In this article we will use Spring Shell to build CLI app to bulk update accounts table permission.
Dependency
Lets first add the spring-shell-starter dependency:
Use Case
We will build simple command line app for updating records in the accounts table.Â
At first lets get all the accounts by the permission id equals to 2, since that represents admin permission.
We want to change the permission from admin to reader which has id = 3
Now we will log the prompt message to continue if all looks good:
For accepting users input :
If user accepts true then we will bulk update permission otherwise exit without doing anything:
Here is the Entire logic:
We have to mark the class as @Command and method as @Command
Now if we run our spring boot application, it will enter provide us the shell to execute command:
Now we can run our method to execute the commands :
Conclusion
In this article we build simple CLI app using Spring Shell that bulk updates the record in the database. Spring Shell is a robust and feature rich framework that we can leverage to build more advance CLI apps.
Read more about it here
Become Better Dev:
To upgrade your developer skills checkout below resources:
Get Ready For Spring Boot Interview. | Java Interview.
Upskill SQL by Practicing it ( 20 % off with code: ABNEW20OFF )