Spring mvc data binding problem submit form prompt HTTP status 400

We have parameters in the controller method in spring mvc, and spring mvc will automatically bind data for us.

The spring mvc method does not have to have all the attributes submitted by the form form, and there can also be parameters that are not in the request attributes (in this case, only the parameters that cannot be matched will be set to null). In both cases, no error will be reported.

However, there are several cases where an error will be reported, which may prompt HTTP status 400, The request sent by the client was syntactically incorrect, and if you add a breakpoint at this time, you will find that you cannot enter the controller at all, but the path of the url in the browser is correct. .

Errors will occur as follows:

Error (1) The parameter requested by the front desk has the corresponding parameter name in the method, but it cannot be converted into the corresponding type. For example, there is <input name="id" type="text" /> in the form, and the method public String aa(int id){ } , an error occurs when a non-integer character such as "wwwwee" is entered in the text box. A special reminder is that the java Date type must follow the format of "2016-10-10 12:10:12" in the form form (note the space in the middle, at least when it is written, that is, 2016-10-10 12 ) . The checkbox multi-select box in the form corresponds to an array of java, but not to a List.

Error (2) Duplicate parameter names in method. public String aa(User user,String name){ } , there is a name attribute in the User class, and now spring mvc does not know which attributes to bind.


Copyright statement: GOOD DEEP https://blog.csdn.net/u013378306/article/details/51275340

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324533402&siteId=291194637