Send Json with Ajax to Spring mvc

2

I can not send a json to a Spring MVC controller, I do not have any errors, but the controller does not print anything, I do not know what I'm failing.

Javascript Ajax:

var search = {
  "pName" : "bhanu",
  "lName" : "prasad"
}

var enviar = JSON.stringify(search);

$.ajax({
  type: "POST",
  contentType: 'application/json; charset=utf-8',
  url: 'http://localhost:8080/HelloSpringMVC/j',
  data: enviar, // Note it is important
  success: function(result) {
    // do what ever you want with data
  }
});

Spring MVC:

 @RequestMapping(value = "/j", method = RequestMethod.POST)
 public void posted(@RequestBody Search search) {
     System.out.println("Post");
     System.out.println(search.toString());
 }
    
asked by Silvia 27.03.2018 в 19:48
source

0 answers