小编Yas*_*ara的帖子

如何在spring mvc controller中接收html复选框值

问题是如果未选中复选框请求无法在springMVC控制器中找到正确的映射函数.因为它似乎只在检查时发送真值,但如果未检查则不发送false值.

<form action="editCustomer" method="post">
  <input type="checkbox" name="checkboxName"/>
</form>
Run Code Online (Sandbox Code Playgroud)

@RequestMapping(value = "/editCustomer" , method = RequestMethod. POST)
public void editCustomer(@RequestParam("checkboxName")String[] checkboxValue) 
{
  if(checkboxValue[0])
  {
    System.out.println("checkbox is checked");
  }
  else
  {
    System.out.println("checkbox is not checked");
  }
}
Run Code Online (Sandbox Code Playgroud)

html spring-mvc

4
推荐指数
2
解决办法
1万
查看次数

标签 统计

html ×1

spring-mvc ×1