重点看方法和写的过程具体输出的值我还没有写全,就是修改添加的值有N个,我的代码只写了N-n个
在使用之前记得先导入jar包
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.12.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.12.4</version>
</dependency>
一步步执行的代码都贴出来:
点击修改按钮此时需要选中前端的某一条数据,然后到test方,然后执行,获取到了选中的那条i数据的id(这里是key1)
然后传入赋值,然后用ajax方法,记住后端的方法,返回那里
<li><a href="javascript:test()"><span><img src="../images/t02.png" /></span>修改</a></li>
function test(){
var ids=$("[name='ids']");
var sel=[]
ids.each(function () {
if(this.checked){
sel.push(this.value)
}
});
if (sel.length==0||sel.length>1){
alert("请选择一个客户");
return ;
}
// window.location="${pageContext.request.contextPath}/custmgr/updateCmLevelView?key1="+sel[0];
/* var form = new FormData(document.getElementById("uploadForm"));*/
var key1=sel[0];
$.ajax({
url:"/custmgr/updateCmLevelView?key1="+key1,
type: 'GET',
dataType:"json",
processData: false, // 告诉jQuery不要去处理发送的数据
contentType: false, // 告诉jQuery不要去设置Content-Type请求头,
// contentType: 'application/json' 向后台传值为json格
// 式,需要与JSON.stringify({ stuID: stuID2 })使用
success: function (data) {
$("input[name='cmName']").val(data.cmName);
$("input[name='cmtype']").val(data.cmtype);
$("input[name='cmlevel']").val(data.cmlevel);
$("input[name='holdDate']").val(data.holdDate);
// alert(data.cmtype);
},
error: function () {
alert(data);// 请求失败时的回调函数
}
});
openWindow(12)
}
@RequestMapping("updateCmLevelView")
public @ResponseBody CmLevelBean updateCmLevelView(CmLevelBean cmLevelBean,@RequestParam Integer key1){
Pagination<CmLevelBean> page = new Pagination<CmLevelBean>(1,10);
page.setQueryObject(cmLevelBean);
cmLevelBean.setKey1(new Integer(key1));
cmLevelService.getByPage(page);
// request.setAttribute("level",page);
return (CmLevelBean)page.getList().get(0);
}
当然了在调用的时候也还有其他的
<div id="light12" class="firstScan_main">
<form action="updateCmLevel" method="post" enctype="multipart/form-data" commandName="cmLevelBean">
<div class="formbody">
<div class="formtitle"><span>修改等级认定记录</span></div>
<ul class="forminfo">
<li><label>客户经理编号</label><form:select path="cmId" cssClass="dfselect" >
<form:option value="-1" label="-请选择-"></form:option>
<form:options items="${data}" itemLabel="name" itemValue="id" ></form:options>
</form:select> </li>
<li><label>认定时间</label> <form:input path="holdDate" readonly="true" type="text" id="holdDate" cssClass="dfinput" /> </li>
<li><label>认定级别</label><input name="cmlevel" type="text" class="dfinput" value="${data.cmlevel}"/> </li>
<li><label>认定类型</label><input name="cmtype" type="text" class="dfinput" value="${data.cmtype}"/> </li>
<li><label>附件上传</label><input name="attachmentfile" type="file" class="dfselect1"/></li>
<li> <input name="" type="submit" class="btn" value="修改"/> <input name="" type="reset" class="btn" value="关闭" onclick="closeWindow('light12')"/></li>
</ul>
</div>
</form>
</div>
<script type="text/javascript">
这里是上面的完整的
<%@ page language="java" contentType="text/html;charset=UTF-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=