Parameter bindings for SPRINMVC

Source: Internet
Author: User

The parameter binding of SPRINGMVC is to receive the requested URL or parameter data of the form through the parameters of the processor method.

The data types supported by the default parameters are:

1.HttpServletRequest: Obtain the requested parameter data from the request object and place it on the controller's formal parameter

2.HttpServletResponse: Response data via Response object

3.HttpSession session domain data is manipulated through the session object.

The 4.MODEL/MODELMAP model is an interface that is used to set the modal data for the response. These two are similar.

@RequestMapping ("/queryitembyid.do")

Public String Queryitembyid (Model model,httpservletrequest request) {

1. Get the Product ID parameter

String id = request.getparameter ("id");

2. Check Product data

Item item = this. Itemservice.queryitembyid (Integer. parseint(id));

3. Responding to model data by using model

/**

* AddAttribute and AddObject are the same meaning

*/

Model.addattribute ("Item", item);

return  "Item/itemedit"; Return the string directly to OK

}

Note: With simple Type binding parameters, it is recommended that you use a simple type of wrapper type (Integer), and that the underlying type (int) of the simple type is not recommended. The reason is that the underlying type cannot be a null value, and the exception is reported if it is not passed.

@RequestParam: Sets the parameter name of the request, matching the name of the method parameter to the property: value: Sets the parameter name of the request required: Sets whether the requested parameter must be passed. True: Must be passed;fasle: can be passed without passing. Default true. @RequestParam (value= "ItemId", required=true)

Parameter bindings for SPRINMVC

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.