Java 如何将单击的单选按钮的值传递给Spring MVC控制器?
我正在我的一个项目中使用SpringMVC控制器 下面是我的JSP代码,其中将显示三个单选按钮。一个是Java 如何将单击的单选按钮的值传递给Spring MVC控制器?,java,jquery,spring,jsp,spring-mvc,Java,Jquery,Spring,Jsp,Spring Mvc,我正在我的一个项目中使用SpringMVC控制器 下面是我的JSP代码,其中将显示三个单选按钮。一个是Insert,第二个单选按钮是Update,第三个单选按钮是Delete 单击Insert单选按钮后,它会在Insert单选按钮旁边显示两个文本框,另外两个单选按钮也是如此。这是我的 $(文档).ready(函数(){ $(“.changeAction”)。在(“单击”,函数(){ $('.variable').html('') var divId=“#”+$(this.attr(“div i
Insert
,第二个单选按钮是Update
,第三个单选按钮是Delete
单击Insert
单选按钮后,它会在Insert
单选按钮旁边显示两个文本框,另外两个单选按钮也是如此。这是我的
$(文档).ready(函数(){
$(“.changeAction”)。在(“单击”,函数(){
$('.variable').html('')
var divId=“#”+$(this.attr(“div id”);
var myInput='节点数据'
$(divId).html(myInput);
})
})
插入
更新
删除
下面是我在控制器代码中的方法-
@RequestMapping(value = "testOperation", method = RequestMethod.GET)
public Map<String, String> testOperation() {
final Map<String, String> model = new LinkedHashMap<String, String>();
return model;
}
@RequestMapping(value = "testOperation", method = RequestMethod.POST)
public Map<String, String> testOperations(@RequestParam String name,
@RequestParam String node,
@RequestParam String data) {
final Map<String, String> model = new LinkedHashMap<String, String>();
System.out.println(name);
System.out.println(node);
System.out.println(data);
return model;
}
@RequestMapping(value=“testOperation”,method=RequestMethod.GET)
公共映射测试操作(){
最终地图模型=新LinkedHashMap();
收益模型;
}
@RequestMapping(value=“testOperation”,method=RequestMethod.POST)
公共映射testOperations(@RequestParam字符串名称,
@RequestParam字符串节点,
@请求参数(字符串数据){
最终地图模型=新LinkedHashMap();
System.out.println(名称);
System.out.println(节点);
系统输出打印项次(数据);
收益模型;
}
问题陈述:-
假设我单击Insert
单选按钮,在第一个文本中键入Hello
,在第二个文本框中键入World
,然后我将点击提交按钮,然后我在节点中看到Hello
值和数据中的World
值,这是正确的
但不知何故,name
变量是空的,而不是我单击insert单选按钮时,它应该显示insert
值
同样的事情也应该发生在更新和删除单选按钮上
你知道我做错了什么吗?用这个替换你的Javascript。这对我有用
$(document).ready(function(){
$(".changeAction").on("click", function(){
$('.changeable').html('')
var divId = $(this).attr("div-id");
$("#dynamicName").val(divId);
divId = "#"+divId;
var myInput = '<label for="Node"> Node </label> <input type="text" name="node" size="20" /> <label for="Data"> Data </label> <input type="text" name="data" size="100"/>'
$(divId).html(myInput);
})
})
$(文档).ready(函数(){
$(“.changeAction”)。在(“单击”,函数(){
$('.variable').html('')
var divId=$(this.attr(“divId”);
$(“#dynamicName”).val(divId);
divId=“#”+divId;
var myInput='节点数据'
$(divId).html(myInput);
})
})
下面是JSFIDLE将代码更改为
从
@RequestParam String name
对,
因为您提到单选按钮的名称为tt
。因此无法获得像插入、更新、删除这样的值,它根本不起作用。事实上,如果我单击insert单选按钮,现在如果我使用您的javascript,也不会生成两个文本框。。。您可以查看一下您的JSFIDLE示例。。也没有文本框生成..@AKIWEB我的错误。道歉。现在检查它是否正在工作。我已经更新了我的答案,并同时更新了它们
@RequestParam String name
@RequestParam String tt