Advanced parameter bindings (arrays and list bindings)

Source: Internet
Author: User
Tags wrapper

1. Binding Arrays:(1) Requirements

Select multiple items on the Product List page and delete them.

(2). Demand Analysis

Feature requires a checkbok in front of each item in the Product List page, select multiple items and click the Delete button to pass the Product ID to the controller and delete the product information according to the product ID.

We demonstrate the ability to get an array of IDs

(4). JSP modification

Modify Itemlist.jsp page, add multi box, submit URL is queryitem.action

<formAction= "${pagecontext.request.contextpath}/queryitem.action"Method= "POST">Query criteria:<Tablewidth= "100%"Border=1><tr><TD>Product ID<inputtype= "text"name= "Item.id" /></TD><TD>Product Name<inputtype= "text"name= "Item.name" /></TD><TD><inputtype= "Submit"value= "Query"/></TD></TR></Table>Product List:<Tablewidth= "100%"Border=1><tr>    <TD>Choose</TD>    <TD>Product Name</TD>    <TD>Commodity price</TD>    <TD>Production Date</TD>    <TD>Product Description</TD>    <TD>Operation</TD></TR><C:foreachItems= "${itemlist}"var= "Item"><TR>    <TD><inputtype= "checkbox"name= "IDs"value= "${item.id}"/></TD>    <TD>${item.name}</TD>    <TD>${item.price}</TD>    <TD><fmt:formatdatevalue= "${item.createtime}"pattern= "Yyyy-mm-dd HH:mm:ss"/></TD>    <TD>${item.detail}</TD>        <TD><ahref= "${pagecontext.request.contextpath}/itemedit.action?id=${item.id}">Modify</a></TD></TR></C:foreach></Table></form>

Page select multiple checkboxes to pass to the Controller method

itself belongs to a form form, the submission URL is queryitem.action

(4) Controller

The Controller method can be received with string[] or Pojo string[] property. You can either choose one of two options.

Define QUERYVO, such as:

Itemcontroller Modify the Queryitem method:

/** * Wrapper type binding array type, can be used in two ways, Pojo properties receive, and receive directly *   @param  @return*/@RequestMapping ("Queryitem") public String Queryitem (Queryvo Queryvo, integer[] IDs) {    System.out.println (Queryvo.getitem (). GetId ());    System.out.println (Queryvo.getitem (). GetName ());    System.out.println (Queryvo.getids (). length);    System.out.println (ids.length);     return "Success";}

Effects, such as:

2. Bind the form's data to the list (1) requirement

Implement batch modification of commodity data.

(2). Development analysis

Development analysis

1. Product information can be modified on the Product List page.

2. The modified product data can be submitted in bulk.

(3). Define Pojo

List to store the object and place the defined list in the wrapper class Queryvo

Use the wrapper Pojo object to receive, such as:

(4) JSP transformation

The HTML code that the front-end page should display, such as:

Analysis Discovery: The name attribute must be a list property name + Subscript + Element property.

JSP to do the following transformation:

<C:foreachItems= "${itemlist}"var= "Item"Varstatus= "S"><TR>    <TD><inputtype= "checkbox"name= "IDs"value= "${item.id}"/></TD>    <TD>        <inputtype= "hidden"name= "Itemlist[${s.index}].id"value= "${item.id}"/>        <inputtype= "text"name= "Itemlist[${s.index}].name"value= "${item.name}"/>    </TD>    <TD><inputtype= "text"name= "Itemlist[${s.index}].price"value= "${item.price}"/></TD>    <TD><inputtype= "text"name= "Itemlist[${s.index}].createtime"value= "<fmt:formatdate value="${item.createtime} "pattern= "Yyyy-mm-dd HH:mm:ss"/>"/></TD>    <TD><inputtype= "text"name= "Itemlist[${s.index}].detail"value= "${item.detail}"/></TD>        <TD><ahref= "${pagecontext.request.contextpath}/itemedit.action?id=${item.id}">Modify</a></TD></TR></C:foreach>

${current} items in the current iteration (in the collection)

${status.first} to determine whether the current item is the first item in the collection, the return value is TRUE or False

${status.last} to determine whether the current item is the most

Varstatus properties are summarized under common parameters:

${status.index} output line number, starting from 0.

${status.count} output line number, starting from 1.

${status. Next, the return value is TRUE or False

Begin, end, step, respectively: Starting sequence number, ending the serial number, jumping pace.

1.1.1. Effects

This shows only the list's bindings, which can receive the list data.

Can get the data, do not do the database operation.

Test results such as:

Note: the data that receives the list type must be a property of Pojo, and if the parameter of the method is ArrayList type, the data cannot be received correctly.

Advanced parameter bindings (arrays and list bindings)

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.