Springmvc @RequestParam

Source: Internet
Author: User

Error Description:

[Java] view plaincopy

  1. @RequestMapping (value = "/index")

  2. PublicString Index (@RequestParam(value ="Action", required =false)  

  3. String action, @RequestParam(value = "Notincludetypeid", required = false )  

  4. int Notincludetypeid) {  

  5. // .... Omit Code

  6. }

When the optional parameter "Notincludetypeid" is empty, the system appears with the following error:

[Plain] view plaincopy

    1. optional int parameter  ' Notincludetypeid '  is not present   

    2. but cannot be translated into a null value due to being  declared as a primitive type.   

    3. consider declaring it as object wrapper for the corresponding  primitive type.  

Cause of Error:

Spring defaults to NULL when the optional parameter "Notincludetypeid" does not exist, but the assignment fails because Notincludetypeid is already set to the base type int!

Workaround:

"Consider declaring it as Object wrapper for the corresponding primitive type." It is recommended that you use the wrapper type instead of the base type, such as "Integer" instead of "int"


Springmvc @RequestParam

Related Article

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.