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);