java - the name of the unified field questions about jquery send request parameters and spring boot parameter acquisition request

  Before encounter this problem, I really did not think there ever be such a problem in the java web. - - !!!

  The problem is this: still jquery, jquery I use to send serialized json data submitted to the designated rest controller api, but 500 no message available error and the console has seen NullPointerException error. I read request packet to get on the browser, the request is normally sent out, that might not js problem. js and java code (sample) probably as follows:

  js:

var name = /*...*/;
var email = /*...*/;

var postData = JSON.stringify({
    name: name,
    email: email,
});

$.ajax({/*...*/});

  controller.java:

/* controller class */
@PostMapping("/api/xxx")
public Map<String, String> xxx(@RequestBody MyBean foo) {
    ArrayList<String> names = foo.getNames();
    ArrayList<String> emails = foo.getEamils();
    // ...
}

  May be familiar already know where the wrong. . . But I was the first to do java web. . . After debugging found that the problem actually lies on the field name is not on. . .

  We should be on top of js or java code, js code is to send the name and email, java code that should be getName () and getEmail (), or js code changed names and emails. This parsing process data pit is really dead. . .

Guess you like

Origin www.cnblogs.com/darkchii/p/12590657.html