目录

一、效果展示

首页

分类查询

批量删除

单个删除

修改

新建

二、部分代码展示

前台页面

Servlet展示

Mapper

三、源码获取


一、效果展示

首页

黑马程序员javaee视频 黑马程序员javaee最新视频_elementui

 分类查询

黑马程序员javaee视频 黑马程序员javaee最新视频_黑马程序员javaee视频_02

 批量删除

黑马程序员javaee视频 黑马程序员javaee最新视频_java_03

 单个删除

黑马程序员javaee视频 黑马程序员javaee最新视频_黑马程序员javaee视频_04

修改

黑马程序员javaee视频 黑马程序员javaee最新视频_mybatis_05

新建

黑马程序员javaee视频 黑马程序员javaee最新视频_黑马程序员javaee视频_06

二、部分代码展示

前台页面

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <script src="js/vue.js"></script>
    <script src="element-ui/lib/index.js"></script>
    <link rel="stylesheet" href="element-ui/lib/theme-chalk/index.css">

    <style>
        .el-table .warning-row {
            background: oldlace;
        }

        .el-table .success-row {
            background: #f0f9eb;
        }
    </style>

</head>
<body>

<div id="app">

    <!--    搜索表单-->
    <el-form :inline="true" :model="brand" class="demo-form-inline">

        <el-form-item label="当前状态">
            <el-select v-model="brand.status" placeholder="当前状态">
                <el-option label="启用" value="1"></el-option>
                <el-option label="禁用" value="0"></el-option>
            </el-select>
        </el-form-item>

        <el-form-item label="品牌名称">
            <el-input v-model="brand.brandName" placeholder="品牌名称"></el-input>
        </el-form-item>

        <el-form-item label="企业名称">
            <el-input v-model="brand.companyName" placeholder="企业名称"></el-input>
        </el-form-item>

        <el-form-item>
            <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>

    </el-form>

    <el-row>
        <el-button type="danger" plain @click="deleteByIds">批量删除</el-button>
        <el-button type="primary" plain @click="dialogVisible = true">新建</el-button>
    </el-row>

    <!--    弹出新建对话框-->
    <el-dialog
            title="新建数据"
            :visible.sync="dialogVisible"
            width="30%">

        <el-form ref="form" :model="brands" label-width="80px">
            <el-form-item label="品牌名称">
                <el-input v-model="brands.brandName"></el-input>
            </el-form-item>

            <el-form-item label="企业名称">
                <el-input v-model="brands.companyName"></el-input>
            </el-form-item>

            <el-form-item label="排序">
                <el-input v-model="brands.ordered"></el-input>
            </el-form-item>

            <el-form-item label="备注">
                <el-input type="textarea" v-model="brands.description"></el-input>
            </el-form-item>

            <el-form-item label="状态">
                <el-switch v-model="brands.status" active-value="1" inactive-value="0"></el-switch>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="addBrand">提交</el-button>
                <el-button @click="dialogVisible = false">取消</el-button>
            </el-form-item>
        </el-form>


    </el-dialog>


    <!--    表格-->
    <template>
        <el-table
                :data="tableData"
                style="width: 100%"
                :row-class-name="tableRowClassName"
                @selection-change="handleSelectionChange">

            <el-table-column
                    type="index"
                    width="50">
            </el-table-column>

            <el-table-column
                    type="selection"
                    width="55">
            </el-table-column>

            <el-table-column
                    prop="brandName"
                    label="品牌名"
                    align="center">
            </el-table-column>


            <el-table-column
                    prop="companyName"
                    label="公司名"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="ordered"
                    align="center"
                    label="排序顺序">
            </el-table-column>
            <el-table-column
                    prop="description"
                    align="center"
                    label="描述">
            </el-table-column>

            <el-table-column
                    prop="statusStr"
                    align="center"
                    label="当前状态">
            </el-table-column>

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

                <template slot-scope="scope">
                    <el-row>
                        <el-button type="primary" @click="update_No1(scope.$index, scope.row)">修改</el-button>
                        <el-button type="danger" @click="deleteById(scope.$index, scope.row)">删除</el-button>
                    </el-row>
                </template>

            </el-table-column>

        </el-table>
    </template>

    <!--    弹出修改对话框-->
    <el-dialog
            title="修改品牌"
            :visible.sync="dialogVisibleUpdate"
            width="30%">

        <el-form ref="form" :model="brand" label-width="80px">
            <el-form-item label="品牌名称">
                <el-input v-model="brand.brandName"></el-input>
            </el-form-item>

            <el-form-item label="企业名称">
                <el-input v-model="brand.companyName"></el-input>
            </el-form-item>

            <el-form-item label="排序">
                <el-input v-model="brand.ordered"></el-input>
            </el-form-item>

            <el-form-item label="备注">
                <el-input type="textarea" v-model="brand.description"></el-input>
            </el-form-item>

            <el-form-item label="状态">
                <el-switch v-model=" brand.status"
                           active-text="启用"
                           inactive-text="禁用"
                           active-value="1"
                           inactive-value="0">
                </el-switch>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="update_No2">提交</el-button>
                <el-button @click="dialogVisibleUpdate = false">取消</el-button>
            </el-form-item>
        </el-form>


    </el-dialog>

    <!--    分页-->
    <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[5, 10, 15, 20]"
            :page-size="100"
            layout="total, sizes, prev, pager, next, jumper"
            :total="totalCount">
    </el-pagination>
</div>

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

<script>

    new Vue({
        el: "#app",

        // 页面加载完之后,执行的方法
        mounted() {
            this.selectAll();
        }

        ,
        methods: {

            // 查询分页数据
            selectAll() {
                axios({
                    method: "post",
                     url: "http://localhost:8080/brand-demo/brand/selectByPageAndCondition?currentPage=" + this.currentPage + "&pageSize=" + this.pageSize,
                    //url: "http://localhost:8080/brand-demo/brand/selectByPage?currentPage=" + _this.currentPage + "&pageSize=" + _this.pageSize,
                    data: this.brand
                }).then(resp => {
                    this.tableData = resp.data.rows;
                    this.totalCount = resp.data.totalCount;
                })
            },

            tableRowClassName({row, rowIndex}) {
                if (rowIndex === 1) {
                    return 'warning-row';
                } else if (rowIndex === 3) {
                    return 'success-row';
                }
                return '';
            },

            handleSelectionChange(val) {
                this.multipleSelection = val;
            },

            onSubmit() {
               // console.log(this.brand);
                this.selectAll();
            },

            // 添加数据
            addBrand() {
                axios({
                    method: "post",
                    url: "http://localhost:8080/brand-demo/brand/add",
                    data: this.brands
                }).then(resp => {
                    // 判断响应数据是否为 success
                    if (resp.data == "success") {
                        this.dialogVisible = false;
                        this.selectAll();

                        this.$message({
                            showClose: true,
                            message: '恭喜你,添加成功',
                            type: 'success'
                        });
                    }
                })
            },

            deleteByIds() {

                // 删除前判断
                this.$confirm('此操作将永久删除被选数据, 是否继续?', '删除', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {

                    for (var i = 0; i < this.multipleSelection.length; i++) {
                        var selectIds = this.multipleSelection[i];
                        this.selectedIds[i] = selectIds.id;
                    }

                    axios({
                        method: "post",
                        url: "http://localhost:8080/brand-demo/brand/deleteByIds",
                        data: this.selectedIds
                    }).then(resp => {
                        // 判断响应数据是否为 success
                        if (resp.data == "success") {

                            this.selectAll();

                            this.$message({
                                message: '恭喜你,删除成功',
                                type: 'success'
                            });
                        }
                    })

                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },

            deleteById(index, row) {
                // 删除前判断
                this.$confirm('此操作将永久删除被选数据, 是否继续?', '删除', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios({
                        method: "post",
                        url: "http://localhost:8080/brand-demo/brand/deleteById",
                        data: row.id
                    }).then( resp => {
                        // 判断响应数据是否为 success
                        if (resp.data == "success") {

                            this.selectAll();

                            this.$message({
                                message: '恭喜你,删除成功',
                                type: 'success'
                            });
                        }
                    })

                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },

            update_No1(index, row){
                this.dialogVisibleUpdate = true;
                this.brand = row;
            },

            update_No2(){
                axios({
                    method: "post",
                    url: "http://localhost:8080/brand-demo/brand/update",
                    data: this.brand
                }).then( resp => {
                    // 判断响应数据是否为 success
                    if (resp.data == "success") {
                        this.dialogVisibleUpdate = false;
                        this.selectAll();

                        this.$message({
                            showClose: true,
                            message: '恭喜你,修改成功',
                            type: 'success'
                        });
                    }
                })
            },

            // 分页
            handleSizeChange(val) {
                this.pageSize = val;
                this.selectAll();
            },
            handleCurrentChange(val) {
                // console.log(`当前页: ${val}`);
                this.currentPage = val;
                this.selectAll();
            }

        },
        data() {
            return {

                totalCount: 100,
                pageSize: 5,

                // 搜索表单数据
                brand: {
                    status: '',
                    brandName: '',
                    companyName: '',
                    id: '',
                    ordered: '',
                    description: ''
                },

                // 新增表单数据
                brands: {
                    status: '',
                    brandName: '',
                    companyName: '',
                    id: '',
                    ordered: '',
                    description: ''
                },

                // 修改表单数据
                brandss: {
                    status: '',
                    brandName: '',
                    companyName: '',
                    id: '',
                    ordered: '',
                    description: ''
                },
                // 被选中的id
                selectedIds: []
                ,
                // 添加对话框是否标记
                dialogVisible: false,

                // 修改对话框是否标记
                dialogVisibleUpdate: false,

                // 数据模型,复选框选中几何
                multipleSelection: [],

                // 分页
                currentPage: 1,

                // 表格数据
                tableData: [{
                    brandName: '',
                    companyName: '',
                    ordered: '',
                    status: '',
                    description: ''
                }]
            }
        }

    })


</script>


</body>
</html>

 Servlet展示

private BrandService brandService = new BrandServiceImpl();

    public void selectAll(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
        List<Brand> brands = brandService.selectAll();

        String json = JSON.toJSONString(brands);

        response.setContentType("text/json;charset=utf-8");

        response.getWriter().write(json);
    }

Mapper

// 查询所有
    @Select("select * from tb_brand")
    @ResultMap("brandResultMap")
    List<Brand> selectAll();