示例图如下:
前台代码如下:
<input type="button" class="searchbtns" value="推送选中用户" onclick="AllShouldPush()">
<table class="personlist">
<thead>
<tr>
<td>序号</td>
<td>用户名称</td>
<td>手机号</td>
<td>剩余树</td>
<td>上次收货时间</td>
<td>距上次收货的天数</td>
<td><input type="checkbox" name="titleCheck" onclick="checkAll(this)" id="titleCheck">选中</td>
<td>推送时间</td>
<td>操作</td>
</tr>
</thead>
<tbody>
<c:forEach items="${logList}" var="log" varStatus="st">
<tr>
<td>${st.index+1 }</td>
<td>${log.realname}</td>
<td>${log.mobile} </td>
<td>${log.treeCount}</td>
<td><fmt:formatDate value="${log.lastSuccessTime}" pattern="yyyy-MM-dd HH:mm:ss" /></td>
<td>${log.dayCount}</td>
<td>
<input type="checkbox" name="ids" value="${log.id }">
</td>
<td><fmt:formatDate value="${log.pushTime}" pattern="yyyy-MM-dd HH:mm:ss" /></td>
<td>
<input type="button" class="btn_addPic" value="推送" onclick="toPush(${log.id})" style="color: blue">
</td>
</tr>
</c:forEach>
</tbody>
</table>
<!--点击选中框-->
function checkAll(t){
if(t.checked){
$(".personlist :checkbox").prop("checked", true);
}else{
$(".personlist :checkbox").prop("checked", false);
}
}
<!--点击选中推送用户按妞,执行ajax-->
function AllShouldPush(){
//选出勾选的记录
var str = "";
$('input[name="ids"]:checked').each(function(){
str = str + $(this).val() +",";
});
// alert(str);
if(str == ""){
alert("请勾选需要操作的记录");
}else{
var id = str;
if(confirm("确定推送给选中的用户?")){
$.ajax({
url:"/userTree/toPushChecked.html?idss="+id,
type: "post",
dataType:"json",
cache:false,
async: false,
success: function(obj){
}
});
}
}
}
后台代码解析选中的数据id如下
@RequestMapping("/toPushChecked.html")
@ResponseBody
public String toPushChecked(Model model, HttpServletRequest request,
@RequestParam(value = "idss", required = false) String idss) {
if(StringUtils.isNotBlank(idss)){
//将数据按照逗号分开放入数组中
String[] s = idss.split(",");
List<Long> ids = new ArrayList<Long>();
//将数组的值,循环出来放到集合中
for (int i=0;i<s.length;i++) {
ids.add(Long.parseLong(s[i]));
}
//循环出每一个id
if(ids != null && ids.size()>0){
for (Long id : ids) {
}
}
}
}