title: Javascript AJAX call to SpringBoot controller and getting response in JSON
body: <p>I am trying to hit my SpringBoot controller with a JSON and for that I am using AJAX. I want my controlelr to receive the AJAX call, extract the JSON, works with the values and return a JSON response back to the script which I will then utilize in some way.</p>
  
  <p>I am not able to figure out how to code my controller so as to handle the AJAX and also if the request should be POST or GET ?</p>
  
  <p>Here is my script code:</p>
  
  <pre><code>&lt;script&gt;
      database.on('child_added', function (snapshot) {
          var data = {};
          data["FirstName"] = snapshot.val().FirstName;
          data["LastName"] = snapshot.val().LastName;
          data["Number"] = snapshot.val().Number;
  
          $.ajax({
            type: "GET",
            contentType: "application/json",
            url:"my-localhost/application/print",
            data: JSON.stringify(data),
            dataType: 'json',
            cache: false,
            success: function(){
              console.log("Successfully sent payload")
            },
            error: function(e){
              console.log("Error": , e)
            }
          });
  &lt;/script&gt;
  </code></pre>
  
  <p>Here is my controller for now. I dont know how and what to change in it and how to send the response back to the script:</p>
  
  <pre><code>@RestController
  @RequestMapping("/application")
  public class AppController
  {
      @GetMapping("/print")
      public void print()
      {
          System.out.println("Hello World");
      }
  }
  </code></pre>