Springmvc Study Notes (15)-data echo

Source: Internet
Author: User

Springmvc Study Notes (15)-data echo
Springmvc Study Notes (15)-data echo

This article introduces several implementation methods for data echo in springmvc.

Data ECHO: after submission, if an error occurs, display the data you just submitted to the submission page.

Pojo data echo Method

1. springmvc displays pojo data by default.

After the pojo data is passed into the controller method, springmvc automatically places the pojo data in the request field, and the key is equal to the pojo type (lower case)

Use@ModelAttributeSpecify the key for pojo echo to the page in the request

2.@ModelAttributeYou can also pass the return value of the method to the page.

On the product query list page, you can query product information by product type. Define the item type query method in the controller, and finally upload the item type to the page.

// Item category // itemtypes indicates that the method return value is put in the key @ ModelAttribute ("itemtypes") public Map in the request.
  
   
GetItemTypes () {Map
   
    
ItemTypes = new HashMap
    
     
(); ItemTypes. put ("101", "digital"); itemTypes. put ("102", "Mother and Baby"); return itemTypes ;}
    
   
  

You can obtain itemTypes data on the page.

Product Name:Product Type:$ {Itemtype. value}            

3. Use model in the simplest way.@ModelAttribute

// You can directly use the model to display the submitted pojo back to the page. // model. addAttribute ("items", itemsCustom );
Simple type data echo

Use model in the simplest way

model.addAttribute("id", id);

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.