Day7 SSM之权限控制

authentication

通过security的authentication可以获取通过验证的用户信息,比如用户名。
security:authentication
首先我们需要引入标签库

<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %>

然后通过security:authentication 获取用户信息

<security:authentication property="principal.username"></security:authentication>

security还可以控制权限,比如管理员的页面和普通用户的页面就不一样:
在这里插入图片描述
这是通过authorize的access的角色判断实现的,只有拥有"ADMIN"权限的用户才有资格看到用户管理功能。
在这里插入图片描述

通过Ajax进行批量删除

首先我们需要绑定删除按钮的点击事件
在这里插入图片描述
然后实现该事件,需要引入jquery包

<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
    function deleteAll() {
        var checkNum = $("input[name='ids']:checked").length;
        if (checkNum == 0) {
            alert("请至少选择一项");
            return;
        }
        if (confirm("确认要删除吗")) {
            var userList = new Array();
            $("input[name='ids']:checked").each(function () {
                userList.push($(this).val())
            });
        }
        $.ajax({
            type: "post",
            url: "${pageContext.request.contextPath}/user/deleteAll.do",
            data: {userList: userList.toString()},
            success: function () {
                alert("删除成功");
                location.reload();
            },
            error: function () {
                alert("删除失败");
            }
        })
    }
</script>

在这里插入图片描述

在这里插入图片描述
这样就实现了批量删除功能。

猜你喜欢

转载自blog.csdn.net/qq_35692783/article/details/96473310
今日推荐