如何获取Spring MVC Controller中复选框勾选行的值

时间:2016-12-26 11:01:43

标签: java spring jsp spring-mvc

我从数据库中获取了值,并且我在JSP中显示,然后使用form:checkbox添加了复选框,并且还从外部添加了一些下拉列表。

现在,每当我选中复选框并提交表单时,我想在Spring Controller中输入3列(rowidisErrorOpsComments),然后将其发送到数据库。我怎样才能实现这一目标?

我的JSP文件编写如下:

<form:form modelAttribute="functionListWrapper" action="sent.html"  id="totalform" cssClass="form-inline"  method="post" >
<table>               

<c:forEach items="${functionListWrapper.functionList}" var="result"  varStatus="status">
    <tr>
        <td><form:checkbox path="functionList[${status.index}].receiveNewsletter" class="case"  name="case"/></td>

        <td>${result.rowid} <form:hidden path="functionList[${status.index}].rowid" name="rowid" /> </td>
        <td>${result.benchmark}</td>
        <td>${result.pageric}</td>
        <td>${result.ric}</td>
        <td>${result.target_Open_Time}</td>
        <td>${result.target_Close_Time}</td>
        <td>${result.snapDate}</td>
        <td>${result.snapTime}</td>
        <td>${result.passfail}</td>
        <td>${result.region}</td>
        <td>${result.fieldEntryDate}</td>
        <td>${result.workingweek}</td>
        <td>${result.holiday}</td>
        <td>${result.row80_1}</td>
        <td>${result.value_DT1}</td>
        <td>${result.value_TS1}</td>
        <td>${result.daylightsaving}</td>

        <td width=20>
            <form:select path= "functionList[${status.index}].isError"   id="option2" cssClass="option2" >
               <form:option value="nooption" label ="-- Select --" />
               <form:option value="false" label ="false"/>
               <form:option value="true" label ="true"/>       
            </form:select>  
        </td> 

       <td width=20>
            <form:select path= "functionList[${status.index}].opsComments"  id="option1" cssClass="option1" >
               <form:option value="-1" label ="-- Select --" />
               <form:option value="Holiday" label ="Holiday"/>
               <form:option value="Publication Issue" label ="Publication Issue"/>
               <form:option value="Production Issue" label ="Production Issue"/>                                          
            </form:select><
       </td>  

       <!--  
       <td><select id=option2 class=option2>
            <option class="nooption" value="nooption">select</option>
            <option class="true" value="true">true</option> 
            <option class="false" value="false">false</option>
            </select>   
        </td>       
        -->                                                                                                    
       <!-- 
       <td><select id=option1 class=option1>
            <option value="nooption">select</option>
            <option  value="Holiday">Holiday</option>
            <option value="Publication">Publication issue</option>
            <option value="Prodution">Production issue</option>

        </select>   
        </td>          
        --> 
    </tr>
</c:forEach>                 
</tbody> 
</table>

我的Pojo课程

import java.util.List;

public class BenchmarkData {
private String rowid;

   private String fieldEntryDate;
    private String workingweek;
    private String holiday;
    private String row80_1;
    private String value_DT1;
    private String value_TS1;
    private String daylightsaving;
    private String errornoerror;
    private Boolean isError;
    private String opsComments;
    private boolean receiveNewsletter;


    public void setRowid(String rowid) {
        this.rowid = rowid;
    }


    public String getRegion() {
        return region;
    }
    public void setRegion(String region) {
        this.region = region;
    }
    public String getPageric() {
        return pageric;
    }
    public void setPageric(String pageric) {
        this.pageric = pageric;
    }

    public Boolean getIsError() {
        return isError;
    }
    public void setIsError(Boolean isError) {
        this.isError = isError;
    }
    public String getOpsComments() {
        return opsComments;
    }
    public void setOpsComments(String opsComments) {
        this.opsComments = opsComments;
    }
    public boolean isReceiveNewsletter() {
        return receiveNewsletter;
    }
    public void setReceiveNewsletter(boolean receiveNewsletter) {
        this.receiveNewsletter = receiveNewsletter;
    }



}

My Wrapper Class

import java.util.ArrayList;
import java.util.List;

public class FunctionListWrapper {
    private List<BenchmarkData> functionList;

    public FunctionListWrapper() {
        this.functionList = new ArrayList<BenchmarkData>();
    }

    public List<BenchmarkData> getFunctionList() {
        return functionList;
    }

    public void setFunctionList(List<BenchmarkData> functionList) {
        this.functionList = functionList;
    }

    public void add(BenchmarkData benchmarkData) {
        this.functionList.add(benchmarkData);
    }
}

我的控制器

@RequestMapping(value="/benchmarksuspectsearch.html",method=RequestMethod.GET)
public  ModelAndView showBenchmarkSearch(@ModelAttribute("functionListWrapper") FunctionListWrapper functionListWrapper,
        HttpServletRequest request) {
    ModelAndView mav = new ModelAndView();
     FunctionListWrapper functionListWrapper1=new FunctionListWrapper();
     functionListWrapper1.setFunctionList(benchmarkService.GetAllData());
     mav.addObject("functionListWrapper", functionListWrapper1);     
     mav.setViewName("benchmark/benchmarksuspectsearch");
    System.out.print("controller sucessfull");
    return mav;

}



    @RequestMapping(value = "/sent.html", method = RequestMethod.GET)
    public String save(@ModelAttribute("FunctionListWrapper") FunctionListWrapper functionListWrapper, Model model){ 
      for(BenchmarkData personItem : functionListWrapper.getFunctionList()){

          String row= personItem.getRowid();

          System.out.print(row);


        }
    return webUrl;

    }

0 个答案:

没有答案