New, edit feature implementation error logging ...

Source: Internet
Author: User

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 ...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.