SPRINGMVC Study Notes (15)-Data echo

Source: Internet
Author: User

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

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.