【问题标题】:When Check boxes are unchecked, got the error Required long[] parameter 'checked' is not present未选中复选框时,出现错误Required long[] parameter 'checked' is not present
【发布时间】:2018-08-19 18:47:01
【问题描述】:

我有复选框的 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">

在服务器端

@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;
}

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

【问题讨论】:

  • required = false

标签: java html spring spring-mvc checkbox


【解决方案1】:

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

@Valid @RequestParam(value = "checked", required = false) long[] checkboxvalues

【讨论】:

  • @gil.fernandes 非常感谢。
猜你喜欢
  • 2020-12-17
  • 2021-12-04
  • 2011-02-09
  • 2019-03-11
  • 1970-01-01
  • 2020-02-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多