Working with Spring Boot + HTML Forms + JQuery

In this post we’ll will see how to handle HTML form requests with Spring Boot Rest API using JQuery with Ajax.

I was finding this difficult initially and then realized that it is as simple as that. So i thought i could write a simple login screen sending the login form data to the API and display the response from it using Ajax call in JQuery.

Requirements:

  • Spring Boot Framework (To create the API and a Standalone Application)
  • Jquery (To make client side requests)

pom.xml (Maven Configurations)

Main.java (Configure SpringBootApplication Main class)

Account.java (Model for our Login Form)

FormController.java

@RequestBody controller will help us to get the JSON Object sent by JQuery Ajax Call. The Json Object will be mapped to the members in the Model. Make sure to use the same member names.

Jquery Call (Index.js)

Download the code from GitHub- click here

Output will be like this:

Let me know in the comments, if you find any difficulties. Thanks for reading.