SPRINGMVC Study Notes (15)-Data echo
- SPRINGMVC Learning Note 15-data echo
- Pojo Data echo method
- Simple Type data echo
This paper introduces several implementation methods of data echo in SPRINGMVC
Data echo: After submission, if an error occurs, the data just submitted is echoed to the submission page just now.
Pojo Data echo method
1.SPRINGMVC Pojo data is echoed by default.
Pojo data is passed into the controller method, Springmvc automatically puts Pojo data into the request domain, key equals Pojo type (lowercase first letter)
Use the @ModelAttribute specified Pojo to echo the key to the page in request
2. @ModelAttribute You can also upload the return value of the method to the page
On the Product Query list page, check the product information by product type. The Product Type Query method is defined in the controller, and the product type is eventually uploaded to the page.
// 商品分类//itemtypes表示最终将方法返回值放在request中的key@ModelAttribute("itemtypes")publicgetItemTypes() { new HashMap<String, String>(); itemTypes.put("101""数码"); itemTypes.put("102""母婴"); return itemTypes;}
Itemtypes data can be obtained on the page.
<TD>Product Name:<input name="Itemscustom.name" />Product Type:<Select name="ItemType"> <c:foreach Items="${itemtypes}" var="ItemType"> <option value="${itemtype.key}">${itemtype.value}</option> </C:foreach> </Select></td>
3. Using the model in the simplest way, you can use the@ModelAttribute
//可以直接使用model将提交pojo回显到页面//model.addAttribute("items", itemsCustom);
Simple Type data echo
Using the model in the simplest way
model.addAttribute("id", id);
Author @brianway More articles: personal website | CSDN | Oschina
SPRINGMVC Study Notes (15)-Data echo