lazy saunter

(personal learnings in computation)

Wednesday, June 13, 2018

Spring MVC (Spring Boot)

Spring came out with a new product a few years back called Spring Boot.  Basically, it is a stripped-down framework for creating Java Spring applications very quickly.  In my experience, creating a basic web app with Spring Boot approaches the simplicity of doing the same task in a language/framework better known for this sort of task, like Ruby on Rails.

Again, in my experience...until this product came out, setting up a Java web app was time-consuming, tedious, and prone to errors.  For a simple web app, the up-front time didn't warrant even considering Java for the job.  However, now with one command line command, an entire application can be created.  The dependencies necessary for creating a web app, connecting to a database, and many other tasks can be specified in that one command.

Enter the task at hand.  I want to create a simple web site to display a list of records from a database.  Solution (glossing over a lot of detail, just to give the basic steps):

1. Use the Spring Boot initializr command line tool to create the application
2. Configure my database connection in the application.properties file
3. Create a service class to query the database using JdbcTemplate, or create go the JpaRepository interface route to use built-in queries
4. Create the domain object class for the item being retrieved from the DB
5. Create the controller class/method that accepts a URL request and maps it to a method that calls the service class method or the repository methods
6. The controller can put the results in the ModelMap that will be available to the web page template.
7. Create the web page template to display the result

Spring Boot "ships with" (or makes the dependencies very easy to pull in) the Thymeleaf web page template.  For a monolithic Java web app like the one I want to create, the tight coupling between the Java backend business logic code and the front-end web page is acceptable.  There are newer, more decoupled design patterns out there now that I may address at some point.

Conveniently, the Thymeleaf web page can easily be augmented with jquery and the jquery tablesorter to allow for row striping and column sorting, even showing the ascending and descending caret icons in the column headers.  Very similar to the setup I wrote about a few years back.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home