MyBatis注解开发实现学生管理页面(分页pagehelper,多条件搜索,查看课程信息)

news/2024/7/9 23:52:00 标签: mybatis, java, vue

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>studentSystemWork</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.16</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.5.1</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.25</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <!--servlet-->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
        </dependency>
        <!--jackson-->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.7.3</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.7.3</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.7.3</version>
        </dependency>
        <!--StringUtils-->
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.4</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13</version>
            <scope>test</scope>
        </dependency>
        <!-- Beanutils -->
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.8.3</version>
        </dependency>

        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.1</version>
        </dependency>
        <!-- DBUtils -->
        <dependency>
            <groupId>commons-dbutils</groupId>
            <artifactId>commons-dbutils</artifactId>
            <version>1.6</version>
        </dependency>
        <!--log4j-->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <!--c3p0-->
        <dependency>
            <groupId>com.mchange</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.5</version>
        </dependency>
        <!--分页插件-->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>5.1.10</version>
        </dependency>
    </dependencies>

</project>

index.html

<!DOCTYPE html>
<html>

<head>
    <title></title>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="element-ui-2.13.0/lib/theme-chalk/index.css" />
    <script type="text/javascript" src="vue/vue-v2.6.10.js"></script>
    <script type="text/javascript" src="element-ui-2.13.0/lib/index.js"></script>
    <script type="text/javascript" src="vue/axios-0.18.0.js"></script>
</head>

<body>
<div id="app">
    <template>
        <el-table :data="tableData" @selection-change="handleSelectionChange" size="medium"
                  highlight-current-row="true" style="width: 100%">
            <el-table-column type="selection" width="55" prop="sid">
            </el-table-column>
            <el-table-column width="100px" label="序号" type="index">
            </el-table-column>
            <el-table-column label="姓名" prop="sname">
            </el-table-column>
            <el-table-column label="性别" prop="gender">
            </el-table-column>
            <el-table-column label="班级" prop="tbClass.caption">
            </el-table-column>
            <el-table-column>
                <template slot="header" slot-scope="scope">
                    <el-input v-model="search" size="mini" placeholder="请输入姓名" />
                </template>
            </el-table-column>
            <!-- <el-table-column>
                <template slot="header" slot-scope="scope">
                    <el-select v-model="cid" placeholder="请选择班级">
                        <el-option v-for="item in classes"
                          :key="item.cid"
                          :label="item.caption"
                          :value="item.cid">
                        </el-option>
                      </el-select>
                </template>
            </el-table-column> -->
            <el-table-column>
                <template slot="header" slot-scope="scope">
                    <el-radio v-model="sex" label="男">男</el-radio>
                    <el-radio v-model="sex" label="女">女</el-radio>
                </template>
            </el-table-column>
            <el-table-column>
                <template slot="header" slot-scope="scope">
                    <el-button type="success" @click="findAll()">搜索</el-button>
                </template>
                <template slot-scope="scope">
                    <el-button size="mini" @click="handleLook(scope.$index, scope.row)">查看课程信息</el-button>
                </template>
            </el-table-column>
        </el-table>
    </template>
    <br />
    <el-row>
        <el-button type="warning" @click="delAll()">删除选中</el-button>
    </el-row>
    <template>
        <div class="block" align="right">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                           :current-page="currentPage" :page-sizes="[3, 4, 5, 6]" :page-size="pageSize"
                           layout="total, sizes, prev, pager, next, jumper" :total="totalCount">
            </el-pagination>
        </div>
    </template>

    <!-- 查看课程信息 -->
    <el-dialog title="查看课程信息" :visible.sync="dialogFormVisible">
        <el-form ref="ruleForm" :model="ruleForm" label-width="80px">
            <el-form-item label="学生姓名">
                <el-input v-model="ruleForm.sname" style="width: 210px;" readonly></el-input>
            </el-form-item>
        </el-form>
        <el-table :data="tableCourse" @selection-change="handleSelectionChange" size="medium"
                  highlight-current-row="true" style="width: 100%">
            <el-table-column width="100px" label="序号" type="index">
            </el-table-column>
            <el-table-column label="课程" prop="courses[0].cname">
            </el-table-column>
            <el-table-column label="成绩" prop="num">
            </el-table-column>
            <el-table-column label="老师" prop="courses[0].teacher.tname">
            </el-table-column>
        </el-table>
    </el-dialog>
</div>
</body>
<script>
    axios.defaults.withCredentials = true
    new Vue({
        el: "#app",
        data: {
            /*表格数据*/
            tableData: [],
            tableCourse: [],
            /*条件查询关键字*/
            search: '',
            sex: "",
            //批量删除存放选中的复选框
            multipleSelection: [],
            //存放删除的数据
            delarr: [],
            //当前页
            currentPage: 1,
            //每页显示条数
            pageSize: 3,
            //总条数
            totalCount: '',
            //总页数
            totalPage: '',
            // 是否展示课程信息对话框
            dialogFormVisible: false,
            ruleForm: {
                sid: '',
                sname: '',
                gender: '',
                tbClass: '',
                class_id: '',
            },
        },
        methods: {

            findAll() {
                let param = new URLSearchParams();
                param.append("type", "showStuByPage");
                param.append("page", this.currentPage);
                param.append("rows", this.pageSize);
                param.append("sname", this.search);
                param.append("gender", this.sex);
                axios({
                    method: "post",
                    url: "http://localhost:8080/studentSystemWork_war_exploded/studentServlet",
                    data: param
                }).then(obj => {
                    this.tableData = obj.data.list;
                    this.totalCount = obj.data.total;
                });
            },

            handleSizeChange: function (size) {
                this.pageSize = size;
                this.findAll();
            },

            handleCurrentChange: function (currentPage) {
                this.currentPage = currentPage;
                this.findAll();
            },

            delAll() {
                //获取删除的ID
                this.delarr = [];
                for (let i = 0; i < this.multipleSelection.length; i++) {
                    this.delarr.push(this.multipleSelection[i].sid);
                }
                //判断要删除的文件是否为空
                if (this.delarr.length == 0) {
                    this.$message.warning("请选择要删除的数据!")
                } else {
                    this.$confirm("是否确认删除?", "提示", { type: 'warning' }).then(() => {
                        //点击确认删除
                        let param = new URLSearchParams();
                        param.append("sids", this.delarr.join())
                        param.append("type", "deleteStudents")
                        axios({
                            method: "post",
                            url: "http://localhost:8080/studentSystemWork_war_exploded/studentServlet",
                            data: param
                        }).then(obj => {
                            if (obj.data) {
                                this.$message.success("删除成功!");
                                setTimeout(function () {
                                    window.location.href = "index.html"
                                }, 1500)
                            } else {
                                this.$message.error("删除失败!")
                            }
                        });
                    });
                }
            },

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

            handleLook(index, row) {
                this.dialogFormVisible = true;
                this.ruleForm = row;
                let param = new URLSearchParams();
                param.append("type","getStudentCourseById")
                param.append("sid",row.sid);
                axios({
                    method: "post",
                    url: "http://localhost:8080/studentSystemWork_war_exploded/scoreServlet",
                    data: param
                }).then(obj => {
                    this.tableCourse = obj.data;
                });
            },

        },

        created() {
            this.findAll();
        }

    })
</script>

</html>

studentDao

java">package com.etime.dao;

import com.etime.pojo.Student;
import com.etime.pojo.TbClass;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface StudentDao {
    @Select({"<script> select count(*) from student " +
            "<where>  " +
            "<if test = \"sname != ''\"> " +
                "and sname like concat('%',#{sname},'%')  " +
            "</if>  " +
            "<if test = \"gender != ''\"> " +
                "and gender = #{gender} " +
            "</if> " +
            "</where> </script>"})
    int getCountStudent(Student student);

    @Select({"<script> select * from student " +
            "<where>  " +
            "<if test = \"sname != ''\"> " +
            "and sname like concat('%',#{sname},'%')  " +
            "</if>  " +
            "<if test = \"gender != ''\"> " +
            "and gender = #{gender} " +
            "</if> " +
            "</where> </script>"})
    @Results({
            @Result(property = "sid",column = "sid"),
            @Result(property = "gender",column = "gender"),
            @Result(property = "class_id",column = "class_id"),
            @Result(property = "sname",column = "sname"),
            @Result(property = "tbClass",column = "class_id",javaType = TbClass.class,
                    one = @One(select = "com.etime.dao.TbClassDao.getClassByCid"))
    })
    List<Student> showStuByPage(Student student);

    @Delete({"<script>delete from student where sid in " +
            "<foreach collection=\"list\" open=\"(\" close=\")\" item=\"sid\" separator=\",\"> " +
            "#{sid} " +
            "</foreach>" +
            "</script>"})
    int deleteStudents(List<Integer> list);
}

具体完整代码看资源


http://www.niftyadmin.cn/n/5078832.html

相关文章

S7-1200与力控通过S7协议通讯

测试环境&#xff1a;Win10、力控7.2SP3、1214DCDCDC 博途工控人平时在哪里技术交流博途工控人社群 博途工控人平时在哪里技术交流博途工控人社群 在画面管理中&#xff0c;有种弹出画面&#xff0c;也就是窗口提示画面&#xff0c; 1-PLC端配置 PLC IP设置为192.168.2.10 …

vim多文件的打开与关闭问题

vim命令模式下 &#xff1a; e 文件名字&#xff0c;打开文件&#xff1b; &#xff1a; bd &#xff0c;关闭当前文件

前端页面布局之【Flex布局】详解

目录 &#x1f31f;前言&#x1f31f;浏览器支持&#x1f31f;Flex简介&#x1f31f;Flex基本概念&#x1f31f;容器属性&#x1f31f;项目排列方向&#x1f31f;项目包裹方式&#x1f31f;项目水平对齐方式&#x1f31f;项目的垂直对齐方式&#x1f31f;多行对齐方式 &#x1…

C++ 基础知识 问答题(五)

PART1 1.int型整数的最大值和最小值分别是什么&#xff1f;如何用二进制表示&#xff1f;使用最大值和最小值进行计算时会出现什么问题&#xff1f; 2.类声明成指针相对于声明成对象有什么好处? 3.迭代器可以加减常数吗&#xff1f; 4.动态绑定是如何实现的&#xff1f; …

我的编程初学者之旅:那些愚蠢的代码

我的编程初学者之旅&#xff1a;那些愚蠢的代码 在编程的早期阶段&#xff0c;我犯了许多愚蠢的错误&#xff0c;这些错误让我深感尴尬&#xff0c;但也让我学到了很多。我想分享一些我曾经写过的愚蠢代码&#xff0c;希望它们能帮助其他初学者避免类似的错误。 没有正确理解…

Python Loguru 日志打印

在开发过程中&#xff0c;我们经常需要记录应用程序的运行状态和错误信息。日志是一种重要的工具&#xff0c;可以帮助我们快速定位和解决问题。Python3提供了多种日志库&#xff0c;其中Loguru是一个简单易用的日志库&#xff0c;它提供了丰富的功能和灵活的配置选项&#xff…

SpringBoot 实现EMQ设备的上下线告警

前言 上下线通知 我遇到了一个难题&#xff0c;即在使用EMQ X 4.4.10的开源版本时&#xff0c;我需要实现设备的上下线状态监控&#xff0c;但该4.4.10开源版本并未内置设备上下线提醒模块&#xff0c;只有企业版才内置了该模块。这为我带来了一些技术上的难题&#xff0c;迫…

Rn使用FlatList导航栏自动回到中间

import { useState, useRef } from react import { FlatList, View, Text, StyleSheet, TouchableOpacity } from react-nativeconst Center () > {const tabs ["语文", "数学", "英语", "政治", "历史", "地理&q…