增删改查,分页

SpringBoot+MybatisPlus Restful示例-LMLPHP

CREATE TABLE `tbl_book` (
  `id` int NOT NULL AUTO_INCREMENT,
  `type` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
  `name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
  `desc_ription` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
  `sensitive_Info` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
  `sensitive_Info2` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
  `create_time` datetime DEFAULT NULL,
  `update_time` datetime DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=85 DEFAULT CHARSET=utf8mb3 ROW_FORMAT=DYNAMIC;

INSERT INTO `tbl_book`(`id`, `type`, `name`, `desc_ription`, `sensitive_Info`, `sensitive_Info2`, `create_time`, `update_time`) VALUES (74, '图林原创', 'Nginx经典教程', 'F5 NGINX核心人员倾力打造,关注基础用法和现代场景,新技术趋势下经典全新解读,涵盖容器,Kubernetes,NJS语言,新协议支持等', NULL, NULL, '2023-11-10 21:12:07', NULL);
INSERT INTO `tbl_book`(`id`, `type`, `name`, `desc_ription`, `sensitive_Info`, `sensitive_Info2`, `create_time`, `update_time`) VALUES (75, '全栈开发', 'Vue.Js前端开发基础与项目实战', '系统深入从原理进行分析,详细介绍前端的发展和常用Vue.js功能模块,内容实用,全面讲解Vue.js生态链且涵盖后端架构相关知识,项目实战详细介绍实用插件和构建PC端网站的步骤及前后端开发流程', NULL, NULL, '2023-11-10 21:14:49', NULL);
INSERT INTO `tbl_book`(`id`, `type`, `name`, `desc_ription`, `sensitive_Info`, `sensitive_Info2`, `create_time`, `update_time`) VALUES (76, '架构', '凤凰架构', '从架构演进,架构设计思维,分布式基石,不可变基础设施,技术方法论5个维度全面探索如何构建可靠的大型分布式系统', NULL, NULL, '2023-11-10 21:16:38', NULL);
INSERT INTO `tbl_book`(`id`, `type`, `name`, `desc_ription`, `sensitive_Info`, `sensitive_Info2`, `create_time`, `update_time`) VALUES (77, '华章科技', 'Maven实战', '国内首本Maven著作,内容全面,实战性强,公认的Maven专家执笔,中外技术专家联合推荐,权威性无需置疑', NULL, NULL, '2023-11-10 21:18:31', NULL);
INSERT INTO `tbl_book`(`id`, `type`, `name`, `desc_ription`, `sensitive_Info`, `sensitive_Info2`, `create_time`, `update_time`) VALUES (78, 'Broadview', '深入理解Apache Dubbo与实战', NULL, NULL, NULL, '2023-11-10 21:19:46', NULL);
INSERT INTO `tbl_book`(`id`, `type`, `name`, `desc_ription`, `sensitive_Info`, `sensitive_Info2`, `create_time`, `update_time`) VALUES (79, '图林程序设计丛书', 'SQL查询', '赢得世界赞誉的SQL经典著作', NULL, NULL, '2023-11-10 21:20:27', NULL);
INSERT INTO `tbl_book`(`id`, `type`, `name`, `desc_ription`, `sensitive_Info`, `sensitive_Info2`, `create_time`, `update_time`) VALUES (80, '华章科技', '分布式中间件技术实战', NULL, NULL, NULL, '2023-11-10 21:21:31', NULL);
INSERT INTO `tbl_book`(`id`, `type`, `name`, `desc_ription`, `sensitive_Info`, `sensitive_Info2`, `create_time`, `update_time`) VALUES (81, '异步图书', 'SpringBoot源码解读与原理分析', NULL, NULL, NULL, '2023-11-10 21:22:09', NULL);
INSERT INTO `tbl_book`(`id`, `type`, `name`, `desc_ription`, `sensitive_Info`, `sensitive_Info2`, `create_time`, `update_time`) VALUES (82, '图林程序', 'SQL必知必会', '畅销全球的数据库入门经典', NULL, NULL, '2023-11-10 21:23:03', NULL);
INSERT INTO `tbl_book`(`id`, `type`, `name`, `desc_ription`, `sensitive_Info`, `sensitive_Info2`, `create_time`, `update_time`) VALUES (83, 'Java专家系列', 'JDBC数据库程序设计', '本书讨论的内容主要是如何利用Java程序语言,编写与数据库相关的应用程序.从最开始Java语言与数据库管理系统的介绍,JDBC API的实用,乃至最后Java数据库应用程序开发的实战.都将在本书中详细说明.详细的实例讲解和完整的章节安排,非常适合Java初学者快速学习实用Java开发数据库相关的应用程序,范例程序丰富,代码和运行结果以图文并茂的方式配合呈现', NULL, NULL, '2023-11-10 21:26:50', NULL);
INSERT INTO `tbl_book`(`id`, `type`, `name`, `desc_ription`, `sensitive_Info`, `sensitive_Info2`, `create_time`, `update_time`) VALUES (84, 'GOTOP', '鸟哥的Linux私房菜', '经久不衰的Linux经典教程', NULL, NULL, '2023-11-10 21:27:45', NULL);

SpringBoot+MybatisPlus Restful示例-LMLPHP

pom.xml

application.properties

SpringBoot+MybatisPlus Restful示例-LMLPHP

实体类

DAO层

SpringBoot+MybatisPlus Restful示例-LMLPHP

业务层

SpringBoot+MybatisPlus Restful示例-LMLPHP

实现类

SpringBoot+MybatisPlus Restful示例-LMLPHP

控制器

SpringBoot+MybatisPlus Restful示例-LMLPHP

统一返回

全局异常处理

 MybatisPlus 自动填充配置

 MybatisPlus分页配置

前端

<!DOCTYPE html>

<html>

<head>

    <!-- 页面meta -->

    <meta charset="utf-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <title>基于SpringBoot整合SSM案例</title>

    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">

    <!-- 引入样式 -->

    <link rel="stylesheet" href="../plugins/elementui/index.css">

    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">

    <link rel="stylesheet" href="../css/style.css">

</head>

<body class="hold-transition">

<div id="app">

    <div class="content-header">

        <h1>图书管理</h1>

    </div>

    <div class="app-container">

        <div class="box">

            <div class="filter-container">
                <el-input placeholder="图书类别" v-model="pagination.type" style="width: 200px;" class="filter-item"></el-input>
                <el-input placeholder="图书名称" v-model="pagination.name"  style="width: 200px;" class="filter-item"></el-input>
                <el-input placeholder="图书描述" v-model="pagination.descRiption" style="width: 200px;" class="filter-item"></el-input>
                <el-button @click="getAll()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
            </div>

            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>

                <el-table-column type="index" align="center" label="序号"></el-table-column>

                <el-table-column prop="type" label="图书类别" align="center"></el-table-column>

                <el-table-column prop="name" label="图书名称" align="center"></el-table-column>

                <el-table-column prop="descRiption" label="描述" align="center"></el-table-column>

                <el-table-column label="操作" align="center">

                    <template slot-scope="scope">

                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>

                        <el-button type="danger" size="mini" @click="handleDelete(scope.row)">删除</el-button>

                    </template>

                </el-table-column>

            </el-table>

            <!--分页组件-->
            <div class="pagination-container">

                <el-pagination
                        class="pagiantion"

                        @current-change="handleCurrentChange"

                        :current-page="pagination.currentPage"

                        :page-size="pagination.pageSize"

                        layout="total, prev, pager, next, jumper"

                        :total="pagination.total">

                </el-pagination>

            </div>

            <!-- 新增标签弹层 -->

            <div class="add-form">

                <el-dialog title="新增图书" :visible.sync="dialogFormVisible">

                    <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right" label-width="100px">

                        <el-row>

                            <el-col :span="12">

                                <el-form-item label="图书类别" prop="type">

                                    <el-input v-model="formData.type"/>

                                </el-form-item>

                            </el-col>

                            <el-col :span="12">

                                <el-form-item label="图书名称" prop="name">

                                    <el-input v-model="formData.name"/>

                                </el-form-item>

                            </el-col>

                        </el-row>


                        <el-row>

                            <el-col :span="24">

                                <el-form-item label="描述">

                                    <el-input v-model="formData.descRiption" type="textarea"></el-input>

                                </el-form-item>

                            </el-col>

                        </el-row>

                    </el-form>

                    <div slot="footer" class="dialog-footer">

                        <el-button @click="cancel()">取消</el-button>

                        <el-button type="primary" @click="handleAdd()">确定</el-button>

                    </div>

                </el-dialog>

            </div>

            <!-- 编辑标签弹层 -->

            <div class="add-form">

                <el-dialog title="编辑检查项" :visible.sync="dialogFormVisible4Edit">

                    <el-form ref="dataEditForm" :model="formData" :rules="rules" label-position="right" label-width="100px">

                        <el-row>

                            <el-col :span="12">

                                <el-form-item label="图书类别" prop="type">

                                    <el-input v-model="formData.type"/>

                                </el-form-item>

                            </el-col>

                            <el-col :span="12">

                                <el-form-item label="图书名称" prop="name">

                                    <el-input v-model="formData.name"/>

                                </el-form-item>

                            </el-col>

                        </el-row>

                        <el-row>

                            <el-col :span="24">

                                <el-form-item label="描述">

                                    <el-input v-model="formData.descRiption" type="textarea"></el-input>

                                </el-form-item>

                            </el-col>

                        </el-row>

                    </el-form>

                    <div slot="footer" class="dialog-footer">

                        <el-button @click="cancel()">取消</el-button>

                        <el-button type="primary" @click="handleEdit()">确定</el-button>

                    </div>

                </el-dialog>

            </div>

        </div>

    </div>

</div>

</body>

<!-- 引入组件库 -->

<script src="../js/vue.js"></script>

<script src="../plugins/elementui/index.js"></script>

<script type="text/javascript" src="../js/jquery.min.js"></script>

<script src="../js/axios-0.18.0.js"></script>

<script>
    var vue = new Vue({
        el: '#app',
        data:{
            dataList: [],//当前页要展示的列表数据
            dialogFormVisible: false,//添加表单是否可见
            dialogFormVisible4Edit:false,//编辑表单是否可见
            formData: {},//表单数据
            rules: {//校验规则
                type: [{ required: true, message: '图书类别为必填项', trigger: 'blur' }],
                name: [{ required: true, message: '图书名称为必填项', trigger: 'blur' }]
            },
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize:10,//每页显示的记录数
                total:0,//总记录数

                type:"",//图书类别
                name:"",//图书名称
                descRiption:""//描述
            }
        },

        //钩子函数,VUE对象初始化完成后自动执行
        created() {
            //调用查询全部数据的操作
            this.getAll();
        },

        methods: {
            //列表
            // getAll() {
            //     //发送异步请求
            //     axios.get("/books").then((res)=>{
            //         console.log(res)
            //         if(res.data.flag){
            //             this.dataList=res.data.data
            //         }
            //     })
            // },

            //弹出添加窗口
            handleCreate() {
                this.resetForm()
                //打开新增窗口
                this.dialogFormVisible=true
            },

            //重置表单
            resetForm() {
                //清理数据
                this.formData={}
            },

            //添加
            handleAdd () {

                axios.post("/books",this.formData).then((res)=>{
                    console.log(res)
                    if(res.data.flag){
                        this.dialogFormVisible=false
                        this.$message.success("添加成功")
                    }else{
                        //this.$message.error("添加失败")
                        this.$message.error(res.data.msg)
                    }
                }).finally(()=>{
                    //重新加载数据
                    this.getAll()
                })
            },

            //取消
            cancel(){
                //关闭新增窗口
                this.dialogFormVisible=false

                this.dialogFormVisible4Edit=false
                this.$message.info("当前操作取消")
            },
            // 删除
            handleDelete(row) {
                //弹出提示框 防止误删
                this.$confirm("此操作永久删除,是否继续?",{type: "info"}).then(()=>{
                    //确定
                    let id=row.id
                    axios.delete("/books/"+id).then((res)=>{
                        if(res.data.flag){
                            this.$message.success("删除成功")
                        }else{
                            //this.$message.error("数据同步失败,自动刷新")
                            this.$message.error(res.data.msg)
                        }
                    }).finally(()=>{
                        //重新加载数据
                        this.getAll()
                    })
                  //取消
                }).catch(()=>{
                    this.$message.info("取消操作")
                })

            },

            //弹出编辑窗口
            handleUpdate(row) {
                axios.get("/books/"+row.id).then((res)=>{
                    if(res.data.flag&&res.data.data!=null){
                        this.formData=res.data.data
                        this.dialogFormVisible4Edit=true
                    }else{
                        //this.$message.error("数据同步失败,自动刷新")
                        this.$message.error(res.data.msg)
                        this.dialogFormVisible4Edit=false
                    }
                }).finally(()=>{
                    //刷新页面
                    this.getAll()
                })
                //this.formData=row
                //this.dialogFormVisible4Edit=true
            },

            //修改
            handleEdit() {
                var data=[]
                data.push(this.formData)
                axios.put("/books",data).then((res)=>{
                    console.log(res)
                    if(res.data.flag){
                        //关闭弹窗
                        this.dialogFormVisible4Edit=false
                        this.$message.success("修改成功")
                    }else{
                        //this.$message.error("修改失败")
                        this.$message.error(res.data.msg)
                    }
                }).finally(()=>{
                    //重新加载数据
                    this.getAll()
                })
            },

            //分页查询
            getAll(){
                axios.get("/books/"+this.pagination.currentPage+"/"+this.pagination.pageSize+"?name="+this.pagination.name+"&type="+this.pagination.type+"&descRiption="+this.pagination.descRiption).then((res)=>{
                    console.log(res)
                    if(res.data.flag){
                        this.dataList=res.data.data.records
                        this.pagination.currentPage=res.data.data.current//当前页
                        this.pagination.pageSize=res.data.data.size//
                        this.pagination.total=res.data.data.total//总条数
                    }
                })
            },

            //切换页码
            handleCurrentChange(currentPage) {
                //修改页为当前页
                this.pagination.currentPage=currentPage
                //执行查询
                this.getAll()
            },

            //条件查询
        }
    })

</script>

</html>

前端页面网盘地址

链接:https://pan.baidu.com/s/1BcQXH8gdPZuPfxJ0Lx2wcg 
提取码:uude 
--来自百度网盘超级会员V4的分享

11-12 07:30