ssm 框架中批量删除操作功能实现流程!

首先mapper类定义:

public interface VideoMapper {

void deleteAllVideo(String[] ids);

}

再次是videomapper.xml中的映射管理:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper 
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
"mybatis-3-mapper.dtd">

<mapper namespace="com.zhiyou100.video.mapper.VideoMapper">


<delete id="deleteAllVideo" parameterType="arraylist">
delete from video 
<where>
<foreach collection="array" item="id"
separator="," open="id in (" close=")">
#{id}
</foreach>
</where>

</delete>

</mapper>


service层处理:

public interface VideoService {

void deleteAllVideo(String[] ids);

}

service impl 层处理:

@Service
public class VideoServiceImpl implements VideoService{
@Autowired

VideoMapper vm;

@Override
public void deleteAllVideo(String[] ids) {
vm.deleteAllVideo(ids);

}

}




jsp页面处理:(核心关键点)

<%@page language="java"%>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>JSP Page</title>
        <script src="${pageContext.request.contextPath }/static/js/jquery-1.12.4.min.js"></script>
    <script src="${pageContext.request.contextPath }/static/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath }/static/js/jquery-confirm.min.js"></script>
        <link href="${pageContext.request.contextPath }/static/css/jquery-confirm.min.css" rel="stylesheet">
        <link href="${pageContext.request.contextPath }/static/css/bootstrap.min.css" rel="stylesheet">
        <script>
$(function(){
$("#all").click(function(){
$("input[name=ids]").prop({checked:$("#all").prop("checked")});
$("#span").text($("input[name=ids]:checked").length);
});
$("input[name=ids]").click(function(){
$("#all").prop({checked:$("input[name=ids]:checked").size()==$("input[name=ids]").length});
$("#span").text($("input[name=ids]:checked").length);
});

$("#submit").click(function(){
$.confirm({
content: '确认删除吗',
buttons: {
确认: function () {
$("#formId").submit();
},
取消: function () {
$.alert('已取消!');
}
}
});
});

</script>
</head>
<body>
<jsp:include page="/WEB-INF/view/admin/header.jsp">
<jsp:param value="video" name="fromJsp"/>
</jsp:include>
<div class="container ">
<div class="jumbotron" >
<h3>视频列表-视频管理</h3>
</div>

<div class="navbar-form navbar-left ">

<button class="btn btn-primary" type="button" id="submit">批量删除 <span class="badge" id="span"></span></button>

 </div>

<div class="bs-example" data-example-id="simple-table">
<form action="${pageContext.request.contextPath }/admin/video/deleteAll.action" id="formId" method="post">
<table class="table">
  <thead>
        <tr>
        <th><input type="checkbox" id="all"></th>
          <th>序号</th>
<th>名称</th>
<th>介绍</th>
<th>讲师</th>
<th>课程</th>
<th>时长(秒)</th>
<th>播放次数</th>
<th>编辑</th>
<th>删除</th>
        </tr>
      </thead>
      <tbody>
      <c:forEach var="video" items="${ page.rows }" varStatus="status">
        <tr>
          <th><input type="checkbox" name="ids" value="${video.id}"></th>
          <th scope="row">${(page.page-1)*5+status.count }</th>
          <td>${video.video_title }</td>
          <td>${video.video_descr }</td>
          <td>${video.speakerName }</td>
          <td>${video.courseName }</td>
          <td>${video.video_length }</td>
          <td>${video.video_play_times }</td>
          <td><a href="${pageContext.request.contextPath }/admin/video/update.action?id=${video.id}"><span class="glyphicon glyphicon-edit" ></span></a></td>
          <td><a id="delete" onclick="return confirm('确定删除吗?')" href="${pageContext.request.contextPath }/admin/video/deleteVideo.action?id=${video.id}"><span class="glyphicon glyphicon-trash" ></span></a></td>
        </tr>
        </c:forEach>
      </tbody>
    </table>
</form>
</div>

</body>

</html>

controller类处理:

@Controller
@RequestMapping("/admin/video")
public class AdminVideoController {
@Autowired
VideoService vs;
@Autowired
SpeakerService ss;
@Autowired

CourseService cs;


//批量删除视频
@RequestMapping("/deleteAll")
public String deleteAll(String[] ids,Model md){
if(ids==null){
return "forward:/admin/video/listVideo.action";
}
vs.deleteAllVideo(ids);
return "forward:/admin/video/listVideo.action";
}


}

猜你喜欢

转载自blog.csdn.net/qq_41338740/article/details/81035596
今日推荐