Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Spring MVC中获取单选按钮选择值_Spring_Button_Model View Controller_Radio - Fatal编程技术网

如何在Spring MVC中获取单选按钮选择值

如何在Spring MVC中获取单选按钮选择值,spring,button,model-view-controller,radio,Spring,Button,Model View Controller,Radio,我正在用SpringMVC开发一个web应用程序。我有一个用户添加表单。有两种类型的用户,客户和员工。使用单选按钮选择用户类型。根据选择的用户类型,我希望将表单中填写的数据发送到数据库中的两个表中。有谁能告诉我如何检查选中的单选按钮并相应地执行所需的查询。 下面是我的两个单选按钮JSP <label class="radio-inline"> <input type="radio" name="customer" id="customer" valu

我正在用SpringMVC开发一个web应用程序。我有一个用户添加表单。有两种类型的用户,客户和员工。使用单选按钮选择用户类型。根据选择的用户类型,我希望将表单中填写的数据发送到数据库中的两个表中。有谁能告诉我如何检查选中的单选按钮并相应地执行所需的查询。 下面是我的两个单选按钮JSP

     <label  class="radio-inline">
       <input type="radio" name="customer" id="customer"  value="customer" checked="checked"/>Customer
     </label>
     <label  class="radio-inline">
       <input  type="radio" name="staff"  id="staff" value="staff"/>Staff Member
     </label>

首先,你必须给你的
单选按钮指定与评论中提到的M.Deinum相同的名称

 <label  class="radio-inline">
   <input type="radio" name="radioName" id="customer"  value="customer" checked="checked"/>Customer
 </label>
 <label  class="radio-inline">
   <input  type="radio" name="radioName"  id="staff" value="staff"/>Staff Member
 </label>
客户现在将携带单选按钮的值。如果用户选择了staff,则customer的值将为“stuff”;如果用户选择了customer,则customer的值将为“customer”


对我来说很好。

首先,你必须给你的
单选按钮起一个与评论中提到的M.Deinum相同的名字:

 <label  class="radio-inline">
   <input type="radio" name="radioName" id="customer"  value="customer" checked="checked"/>Customer
 </label>
 <label  class="radio-inline">
   <input  type="radio" name="radioName"  id="staff" value="staff"/>Staff Member
 </label>
客户现在将携带单选按钮的值。如果用户选择了staff,则customer的值将为“stuff”;如果用户选择了customer,则customer的值将为“customer”


对我来说很好。

您使用单选按钮的方式不对。它们应该具有相同的名称,这最终是发送到后端的参数的名称。这也是一个实际的单选按钮。你用错了单选按钮。它们应该具有相同的名称,这最终是发送到后端的参数的名称。这也是一个实际的单选按钮。谢谢你……)这是个错误。。。现在开始工作,谢谢……)这是个错误。。。现在一切正常
...
public ModelAndView saveOrUpdate(@ModelAttribute("newUser") User, @RequestParam("radioName") String customer,
BindingResult validationResult) throws SQLIntegrityConstraintViolationException {
...