取消选中复选框时,得到错误必需long []参数'checked'不存在

时间:2018-03-11 18:27:04

标签: java html spring spring-mvc checkbox

我有复选框的html代码

<input type="checkbox" value="4" name="checked" id="checkbox">
<input type="checkbox" value="5" name="checked" id="checkbox">
<input type="checkbox" value="6" name="checked" id="checkbox">

在Serverside

@RequestMapping(value="/add_attendance", method=RequestMethod.POST)
public ModelAndView Add_Attendance(@Valid @RequestParam("checked")long[] 
checkboxvalues,@RequestParam("atdate")String 
atdate,@RequestParam("company")String company)
{   
   ModelAndView mv=new ModelAndView();  
   atdservice.add(checkboxvalues, ChangeDateFormat.DateToDB(atdate), company);      
   mv.setViewName("admin/mark_attendance");
   mv.addObject("message",company+" attendance marked successfully!!");
   return mv;
}

选中至少一个复选框时,它可以正常工作。但是当所有复选框都未选中时。我收到此错误enter image description here

1 个答案:

答案 0 :(得分:1)

您可以通过将该字段声明为非必需字段来解决您的问题:

#include <iostream>
#include <string>
#include <cctype>

int main () {
  std::string input;
  bool valid;
  do {
    valid = true;
    std::cin >> input;
    for (char c : input)
      if (! std::isdigit( static_cast<unsigned char>(c) ) )
        valid = false;
  } while (! valid);
  // Here the string is guaranteed to be valid
}