Do add new and edit function, $.ajax submit form, if ID is empty go new, not empty go edit
The controller layer receives the parameters. (Long ID)
At the beginning, JS inside the logic is that the new and edit button click to enter a different method, if it is added, send Ajax request to pass {id:0;name:name;country:country}, edit the words will be passed {id:id;name:name; Country:country}.
Later someone optimized my JS code, using $ ("#addForm"). Serialize () in the way (provided that the introduction of bootstrap, and each input box must have a name), regardless of the ID, send such a request.
So the background error ... The specific error I have forgotten, but it is said that the corresponding parameters can not be found.
Then, he began to check my controller code, the new method, found that my parameters are all (long id,string name,string country. ) immediately added the annotation @requestparam (value = "id", required = false) long ID:
After that, it's still not right. Because long is not a package type, if the data is empty, the following occurs when the request is sent = =
Well, if you change to a long type, the request will match.
This is the most pit place, to use the package type cannot pass parameters with the basic type!!!
Then again, I am familiar with the null pointer exception:
Controller Layer Method: if (id==0) {...} The following error:
Well, take notes:
This exception is thrown when an application attempts to use null where the object is needed. This situation includes:
1. Call an instance method of the null object.
2. Access or modify the fields of the null object.
3. Use NULL as an array to get its length.
4. Use NULL as an array to access or modify its time slice.
5. Throw null as the Throwable value.
Change to (Id==null) just fine. However, he said the ID is best not to pass long type of things.
ID, it is best to use a string, as for the editor when the data type is good. method to determine null: Stringutils.isempty (ID)
Then the if is the IF, the else is the else ... Finally, no error.
New, edit feature implementation error logging ...