我有复选框的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;
}
答案 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
}