Spring Boot图书管理系统项目实战-9.归还图书

导航:

pre:  8.续借图书

next:10.借还统计

只挑重点的讲,具体的请看项目源码。

1.项目源码

需要的朋友请给个赞,并留下邮箱,给你们发!

2.页面设计

2.1 bookReturn.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>归还图书</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css" th:href="@{/static/layui/css/layui.css}">
</head>

<body>
<!-- 内容主体区域 -->
<div>
    <!--<div class="demoTable" style="padding: 15px">
        搜索:
        <div class="layui-inline">
            <input class="layui-input" id="find" autocomplete="off">
        </div>
        <button class="layui-btn" data-type="reload" id="queryRole">搜索</button>
    </div>-->

    <table id="tb-bookReturn" lay-filter="tb-bookReturn"></table>

</div>

<!--编辑表单-->
<script type="text/html" id="book-toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="return"><i class="layui-icon">&#xe605;</i>归还</button>
        <button class="layui-btn layui-btn-sm" lay-event="refresh"><i class="layui-icon">&#xe666;</i>刷新
        </button>
    </div>
    <!--<div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
        <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
    </div>-->
</script>

<script type="text/html" id="barOps">
    <a class="layui-btn layui-btn-sm" lay-event="edit"><i class="layui-icon">&#xe642;</i> </a>
</script>

<script src="/static/js/jquery-1.11.3.min.js" th:src="@{/static/js/jquery-1.11.3.min.js}"></script>
<script src="/static/layui/layui.all.js" th:src="@{static/layui/layui.all.js}"></script>
<script src="/static/js/util.js" th:src="@{/static/js/util.js}"></script>

<!--ctx-->
<script th:replace="~{fragment::ctx}"/>

<script>
    var element, layer, laydate, table, form,userTable;

    function reload(){
        userTable.reload();
    }

    $(function () {
        // 使用模块
        layui.use(['element', 'layer', 'laydate', 'table', 'form'], function () {
            element = layui.element;
            layer = layui.layer;
            laydate = layui.laydate;
            table = layui.table;
            form = layui.form;
        });

        //第一个实例
         userTable = table.render({
             elem: '#tb-bookReturn'
             , height: 515
             , url: ctx+'api/bookBorrow/getPageResult' //数据接口
             , where:{borrowStatus: '0,2'}
             , page: true //开启分页
             , toolbar: '#book-toolbar'
             /*,request: {
                 pageName: 'pageNo' //页码的参数名称,默认:page
                 ,limitName: 'pageSize' //每页数据量的参数名,默认:limit
             }

             , response: {
                 statusName: 'code', //规定返回的状态码字段为code
                 statusCode: 200 //规定成功的状态码为200,默认为0
             }
             , parseData: function (res) {
                  return {
                      "code": res.code, //解析接口状态
                      "msg": res.msg, //解析提示文本
                      "count": res.records, //解析数据长度
                      "data": res.rows //解析数据列表
                  }
              }*/
            , cols: [
                [ //表头
                {type: 'checkbox', fixed: 'left'}
                , {field: 'id', title: 'ID', width: 80, sort: true, fixed: 'left',hide:true}
                , {field: 'readerCode', title: '读者编码', width: 160}
                , {field: 'readerName', title: '读者姓名', width: 160}
                , {field: 'readerSex', title: '读者性别', width: 120}
                , {field: 'readerPhone', title: '读者电话', width: 160}
                , {field: 'bookIsbn', title: '图书ISBN', width: 160}
                , {field: 'bookName', title: '图书名称', width: 160}
                , {field: 'bookAuthor', title: '图书作者', width: 120}
                , {field: 'bookCategory', title: '图书分类', width: 120}
                , {field: 'bookLocation', title: '图书位置', width: 180}
                , {field: 'bookTotal', title: '图书数量', width: 120}
                , {field: 'bookLeft', title: '图书剩余', width: 120}
                , {field: 'borrowDate', title: '借阅日期', width: 120,templet:'<div>{{ layui.util.toDateString(d.borrowDate, "yyyy-MM-dd") }}</div>'}
                , {field: 'returnDate', title: '应还日期', width: 120,templet:'<div>{{ layui.util.toDateString(d.returnDate, "yyyy-MM-dd") }}</div>'}
                , {field: 'borrowDays', title: '借阅天数', width: 120}
                , {field: 'remark', title: '备注', width: 180}
            ]
             ]
        });

        userTable.reload({
            where: { //设定异步数据接口的额外参数,任意设
                CustomName: $("#CustomName").val()//这里获取input的值
            }
            ,page: {
                curr: 1 //重新从第 1 页开始
            }
        });

        //工具栏事件
        table.on('toolbar(tb-bookReturn)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var checkData = checkStatus.data;
            var ids = [];
            switch (obj.event) {
                // 归还
                case 'return':
                    if (checkData.length == 0) {
                        layer.alert('请选择要操作的行');
                    } else {
                        layer.confirm('确定要归还吗?', function (index) {
                            for (var i = 0; i < checkData.length; i++) {
                                ids.push(checkData[i].id);
                            }
                            //layer.alert(JSON.stringify(ids));
                            $.ajax({
                                url: ctx+'api/bookBorrow/return',
                                type: 'POST',
                                contentType: "application/json",
                                dataType: "json",
                                data: JSON.stringify(ids),
                                success: function (result) {
                                    if (result.code == 200) {
                                        setTimeout(function () {
                                            layer.closeAll();//关闭所有的弹出层
                                            userTable.reload();
                                        }, 300);
                                    }else {
                                        layer.msg("操作失败!", {icon: 5});
                                    }
                                }
                            });
                        });
                    }
                    break;
                case 'refresh':
                    userTable.reload();
                    break;
                case 'getCheckData':
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了:' + data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选' : '未全选')
                    break;
            }
            ;
        });

    });


</script>
</body>

</html>

3.归还图书service

参考:借阅图书。

4.归还图书controller

参考:借阅图书。

 

需要源码的朋友留下邮箱:)

发布了370 篇原创文章 · 获赞 676 · 访问量 208万+

猜你喜欢

转载自blog.csdn.net/IndexMan/article/details/104852418