数据库课设2.0——重构后端

学生选课系统---数据库课程设计SQL Server 可以直接从我的GitHub中获取文档: 学生选课系统GitHub 一 题目 学生选课系统 二 需求分析 1.根据学生专业学年学期等信息,录入课程完成课程计划 2.根据课程计划,录入任课教师信息 3.学生可以根据学年学期等信息,选择课程完成选课要求 三 结构概念设计 计划受众表信息 学生表信息 教师表信息 课程表信息 教学计划表信息 任课表信息 学生选课表信... 阅读详情

本篇本章针对数据库的课设进行了重构优化,将后端使用的JDBC包连接数据库的DB层舍弃,转用Mybatis框架进行数据库的访问和数据持久化。

开发环境

系统:Windows10(64位)家庭版
数据库:Mysql
框架:Mybatis、Spring
开发语言及工具:Java,采用IDEA进行开发(IDEA本身具有优秀的集成环境和丰富的插件)。对于UI部分采用了IDEA的可视化UI开发插件——JFormDesigner

大作业要求及最终成品的功能描述

会议室预定及租借管理系统

该系统主要针对会议室租借管理而设计的方案,该方案包括了会议室的信息管理、预约与取消预约和设备管理系统。

数据库系统的业务描述
用户:管理员 普通用户
主要功能:
1、会议室借还
2、设备更新与维护
3、费用统计
系统边界或限制:
普通用户:
浏览会议室的预约情况与设备、人数
预定与取消预订(仅限本用户的订单)
登记预定信息
上报设备状况
付款
管理员:
浏览和修改会议室状态、设备与人数
预定与取消预订(所有的订单)
收取用户缴费并修改用户待缴费用

界面设计:
界面设计
本程序具有一定的缺陷,本次重构工作的目的是将原有的笨重的JDBC连接方式改为更高效、简单的流行框架代为执行。在网络搜索和学习之后决定采用SSM体系框架。

程序设计思路

Mapper层:
负责sql语句的传入与结果集的返还。

mybatis-config.xml:
Mybatis的配置文件,负责数据库的连接与配置

beans.xml:
Spring的配置文件

Dao层:
数据持久化层,有数据结果的实体类和用户实体类

Service层:
负责实现程序的各种业务逻辑,并且初步处理数据库返还的结果集。

GUI层:
负责提供可视化界面,读取用户各种信息,将Service层初步处理的结果集进行进一步处理并呈现。

MybatisUtil:
Mybatis的工具类,帮助Mapper映射器在其他方法中的调用

在这里插入图片描述

具体代码实现

重构前的代码为使用JDBC进行连接,非常麻烦,而且采集的数据集不能自动映射和转换,Mybatis很好地解决了这一问题。
以下是Mybatis的配置文件,个人信息已隐去

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <environments default="development">
        <environment id="development">
            <transactionManager type="JDBC"/>
            <dataSource type="POOLED">
                <property name="driver" value="com.mysql.cj.jdbc.Driver"/>
                <property name="url" value="jdbc:mysql://localhost:3306/roommanage?useSSL=true&amp;allowPublicKeyRetrieval=true&amp;serverTimezone=Asia/Shanghai&amp;useUnicode=true&amp;characterEncoding=utf-8"/>
                <property name="username" value="登入数据库的账户名"/>
                <property name="password" value="登入密码"/>
            </dataSource>
        </environment>
    </environments>

    <mappers>
        <mapper resource="Mapper/UserMapper.xml"/>
        <mapper resource="Mapper/UserServiceMapper.xml"/>
    </mappers>
</configuration>

以下为Service层中的接口Reservation。用户和管理员分别实现这个接口的业务操作,但两个角色具有不同的权限

package Service.AfterLogin;

import Dao.otherEntity.Appointment;
import Dao.otherEntity.Meetingroom;
import Dao.otherEntity.Requirement;

import java.util.Vector;

//Reservation接口会有两个实现类,一个为Admin所用,一个为CommonUser所用。区别在User的Identity验证时所体现。
public interface Reservation {
    public Vector[] getAllmeetingroom();
    public Vector[] select (Requirement requirement);
    public boolean book (Appointment appointment);
    public boolean cancel (Appointment appointment);
    public boolean report (Meetingroom meetingroom);
    public boolean setMeetingroomstd(String Rno, int std);
    public boolean setMeetingroomEqup(String Rno, int std);
    public Vector[] getAppointment(String date);
    public boolean addAppointment(Appointment appointment);//Ano:预定信息编号
    public boolean removeAppointment(Appointment appointment);
    public Vector[] getAllEqupment();
    public boolean setEqupmentstd(String Pno, int std);//Pno:设备编号
    public boolean setUsermoney(String Uno, int ammount);
    public boolean changePw();
    public int showUsermonye(String Uno);
}

Admin

package Service.AfterLogin.Impl;

import Dao.User;
import Dao.otherEntity.Appointment;
import Dao.otherEntity.Device;
import Dao.otherEntity.Meetingroom;
import Dao.otherEntity.Requirement;
import Mapper.UserServiceMapper;
import MybatisUtil.MyBatisUtil;
import Service.AfterLogin.Reservation;
//import DBUtil.DBUtil;
import org.apache.ibatis.session.SqlSession;

import java.sql.Time;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Vector;

public class AdminReserve implements Reservation {
    private User user;

    public void setUser(User user) {
        this.user = user;
    }

    public AdminReserve(User user) {
        this.user = user;
    }

    public Vector[] getAllmeetingroom() {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        UserServiceMapper RoomMapper = sqlSession.getMapper(UserServiceMapper.class);
        List<Meetingroom> allMeetingroom = RoomMapper.getAllMeetingroom();
        Vector[] Data = new Vector[2];
        Vector data = new Vector();
        Vector colNames = new Vector();
        colNames.add("会议室号");
        colNames.add("设备状态");
        colNames.add("会议室状态");
        colNames.add("会议室位置");
        for(Meetingroom meetingroom : allMeetingroom){
            Vector row = new Vector();
            row.add(meetingroom.getRno());
            row.add(meetingroom.getRestd());
            row.add(meetingroom.getRsta());
            row.add(meetingroom.getRoa());
            data.add(row);
        }
        sqlSession.close();
            Data[0] = data;
            Data[1] = colNames;
            return Data;
    }

    public boolean setMeetingroomstd(String Rno, int std) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        UserServiceMapper RoomMapper = sqlSession.getMapper(UserServiceMapper.class);
        int Update = RoomMapper.updateMeetingroomStd(Rno,std);
        boolean isUpdate = false;
        if(Update > 0) {
            isUpdate = true;
            System.out.println("已成功修改会议室开放状态");
        }
        sqlSession.close();
        return isUpdate;

    }

    public boolean setMeetingroomEqup(String Rno, int std) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        UserServiceMapper RoomMapper = sqlSession.getMapper(UserServiceMapper.class);
        int Update = RoomMapper.updateMeetEquipStd(Rno,std);
        boolean isUpdate = false;
        if(Update > 0) {
            isUpdate = true;
            System.out.println("已成功修改会议室设备状态");
        }
        sqlSession.commit();
        sqlSession.close();
        return isUpdate;
    }

    public Vector[] getAppointment(String date) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        UserServiceMapper AppMapper = sqlSession.getMapper(UserServiceMapper.class);
        List<Appointment> appointmentByDate = AppMapper.getAppointmentByDate(date);
        Vector[] Data = new Vector[2];
        Vector data = new Vector();
        Vector colNames = new Vector();
        colNames.add("预约号");
        colNames.add("用户号");
        colNames.add("会议室号");
        colNames.add("开始时间");
        colNames.add("结束时间");
        colNames.add("日期");
        for(Appointment appointment : appointmentByDate){
            Vector row = new Vector();
            row.add(appointment.getAno());
            row.add(appointment.getUno());
            row.add(appointment.getRno());
            row.add(appointment.getSTIME());
            row.add(appointment.getETIME());
            row.add(appointment.getDate());
            data.add(row);
        }
        sqlSession.close();
        Data[0] = data;
        Data[1] = colNames;
        return Data;
    }

    public boolean addAppointment(Appointment appointment) {
        boolean isAdd = false;
        if(!isBooked(appointment.getRno(),appointment.getSTIME(),appointment.getETIME(),appointment.getDate())) {
            SqlSession sqlSession = MyBatisUtil.getSqlSession();
            UserServiceMapper AppMapper = sqlSession.getMapper(UserServiceMapper.class);

            //添加预约单,并且用isAdd作为添加订单成功的标识
            int isAddAppointment = AppMapper.addAppointment(user.getUno(), appointment.getRno(), appointment.getSTIME(), appointment.getETIME(), appointment.getDate());
            System.out.println("isAddAppointment:"+isAddAppointment);
            if(isAddAppointment > 0) {
                isAdd = true;
            }
            sqlSession.commit();
            sqlSession.close();
        }
        return isAdd;
    }

    public boolean removeAppointment(Appointment appointment) {
        int hours;
        int pri=0;
        int money;
        boolean isSuccess = false;

        //计算原预订时长,方便返还费用
        hours = user.countTime(appointment.getSTIME(),appointment.getETIME());
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        UserServiceMapper AppMapper = sqlSession.getMapper(UserServiceMapper.class);

        System.out.println("cancel Uno;"+appointment.getUno());
        //取消预订,并通过sql执行的修改数来判断是否成功取消。若sql返还的受影响记录为0,说明没有修改成功
        int cancelAppointment = AppMapper.cancelAppointment(appointment.getAno(), appointment.getUno());
        boolean isCancel = false;
        if(cancelAppointment > 0){
            isCancel = true;
        }

        //获取原预订会议室的价格并计算费用
        pri = AppMapper.getRpriOfRoom(appointment.getRno());
        money = hours*pri;

        //修改用户待缴费用
        int updateUserMoney = AppMapper.updateUserMoney(appointment.getUno(), money);
        boolean isUpdate = false;
        if(updateUserMoney>0){
            isUpdate = true;
        }

        //两个都成功时,才判定该行动成功
        if(isCancel == true && isUpdate == true){
            isSuccess = true;
        }
        sqlSession.commit();
        sqlSession.close();
        return isSuccess;
    }

    public Vector[] getAllEqupment() {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        UserServiceMapper DeviceMapper = sqlSession.getMapper(UserServiceMapper.class);
        List<Device> allequipment = DeviceMapper.getAllequipment();
        Vector[] Data = new Vector[2];
        Vector data = new Vector();
        Vector colNames = new Vector();
        colNames.add("设备编号");
        colNames.add("会议室号");
        colNames.add("设备名字");
        colNames.add("损坏情况");
        for(Device device : allequipment){
            Vector row = new Vector();
            row.add(device.getPno());
            row.add(device.getRno());
            row.add(device.getPname());
            row.add(device.getDamage());
            data.add(row);
        }
        sqlSession.close();
            Data[0] = data;
            Data[1] = colNames;
            return Data;
    }

    public boolean setEqupmentstd(String Pno, int std) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        UserServiceMapper RoomMapper = sqlSession.getMapper(UserServiceMapper.class);
        int Update = RoomMapper.updateDeviceStd(Pno,std);
        boolean isUpdate = false;
        if(Update > 0) {
            isUpdate = true;
            System.out.println("已成功修改设备表设备状态");
        }
        sqlSession.commit();
        sqlSession.close();
        return isUpdate;
    }

    public boolean setUsermoney(String Uno, int ammount) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        UserServiceMapper RoomMapper = sqlSession.getMapper(UserServiceMapper.class);
        int Update = RoomMapper.updateUserMoney(Uno,ammount);
        boolean isUpdate = false;
        if(Update > 0) {
            isUpdate = true;
            System.out.println("已成功修改用户待缴费用");
        }
        sqlSession.close();
        return isUpdate;
    }

    public boolean changePw() {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        UserServiceMapper Mapper = sqlSession.getMapper(UserServiceMapper.class);
        int Update = Mapper.changePW(user.getUno(), user.getPassword());
        boolean isUpdate = false;
        if(Update > 0) {
            isUpdate = true;
            System.out.println("已成功修改用户密码!");
        }
        sqlSession.commit();
        sqlSession.close();
        return isUpdate;
    }

    public int showUsermonye(String Uno) {
        int money=0;
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        UserServiceMapper MoneyMapper = sqlSession.getMapper(UserServiceMapper.class);
        money = MoneyMapper.showUserMoneyByUno(Uno);
        sqlSession.close();
        return money;
    }
        private boolean isBooked (String Rno, String stime, String etime, String date) {
            boolean isbooked = false;
            Date Stime = new Date();
            Date Etime = new Date();
            SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
            try{
                Stime = sdf.parse(stime);
                Etime = sdf.parse(etime);
            } catch (ParseException pe) {

            }
            Time s = new Time(Stime.getTime());
            Time e = new Time(Etime.getTime());
            SqlSession sqlSession = MyBatisUtil.getSqlSession();
            UserServiceMapper AppMapper = sqlSession.getMapper(UserServiceMapper.class);
            List<Appointment> appointmentByDate = AppMapper.isBookedAppointmentByDate(Rno, date);
            for(Appointment appointment : appointmentByDate){
                Time S = Time.valueOf(appointment.getSTIME());
                Time E = Time.valueOf(appointment.getETIME());
                if(!(s.after(E) || e.before(S))){
                    isbooked = true;
                }
            }
            sqlSession.close();
            return isbooked;
        }

    /////////////////此函数管理员不需要////////////////////////
    public Vector[] select(Requirement requirement) {
        return new Vector[0];
    }
    public boolean report(Meetingroom meetingroom) {
        return false;
    }
    public boolean book(Appointment appointment) {
        return false;
    }
    public boolean cancel(Appointment appointment) {
        return false;
    }

}


CuserImpl

package Service.AfterLogin.Impl;

import Dao.User;
import Dao.otherEntity.AppMeetingRoom;
import Dao.otherEntity.Appointment;
import Dao.otherEntity.Meetingroom;
import Dao.otherEntity.Requirement;
import Mapper.UserServiceMapper;
import MybatisUtil.MyBatisUtil;
import Service.AfterLogin.Reservation;
import org.apache.ibatis.session.SqlSession;

import java.sql.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Date;

public class CommonReserve implements Reservation {
    private User user;

    public void setUser(User user) {
        this.user = user;
    }

    public CommonReserve(User user) {
        this.user = user;
    }

    //普通用户只能查询到处于开放状态的会议室
    public Vector[] getAllmeetingroom() {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        UserServiceMapper RoomMapper = sqlSession.getMapper(UserServiceMapper.class);
        List<Meetingroom> allMeetingroom = RoomMapper.getAllMeetingroom();
        Vector[] Data = new Vector[2];
        Vector data = new Vector();
        Vector colNames = new Vector();
        colNames.add("会议室号");
        colNames.add("设备状态");
        colNames.add("会议室价格");
        colNames.add("会议室位置");
        colNames.add("是否有投影仪");
        colNames.add("是否有电脑");
        colNames.add("是否有音响");
        for(Meetingroom meetingroom : allMeetingroom){
            Vector row = new Vector();
            row.add(meetingroom.getRno());
            row.add(meetingroom.getRestd());
            row.add(meetingroom.getRpri());
            row.add(meetingroom.getRoa());
            row.add(meetingroom.getHpjt());
            row.add(meetingroom.getHcmp());
            row.add(meetingroom.getHado());
            data.add(row);
        }
        sqlSession.close();
            Data[0] = data;
            Data[1] = colNames;
            return Data;
    }

    public Vector[] select(Requirement requirement) {
        String select = "select room.*,DATE,STIME,ETIME from room left join appointment on room.RNO=appointment.RNO where RSTA=1";
        if(requirement.dateValid) {
            select = select.concat(" and DATE ='"+requirement.date+"'");
        }
        int hpjt=0,hcmp=0,hado=0;
        if(requirement.haveProjector) {
            select = select.concat(" and HPJT=1");
            hpjt=1;
        }
        if(requirement.haveComputer) {
            select = select.concat(" and HCMP=1");
            hcmp=1;
        }
        if(requirement.haveAudio) {
            select = select.concat(" and HADO=1");
            hado=1;
        }
        if(requirement.maxPoeplenumValid) {
            select = select.concat(" and RCA="+requirement.maxPeoplenum);
        }
        if(requirement.pricePerhourValid) {
            select = select.concat(" and RPRI="+requirement.pricePerhour);
        }
        select = select.concat(";");
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        UserServiceMapper SelectMapper = sqlSession.getMapper(UserServiceMapper.class);
        List<AppMeetingRoom> AppMeetingroom = SelectMapper.SelectRoom(requirement.date, hpjt,hcmp,hado,requirement.maxPeoplenum,requirement.pricePerhour);
        Vector[] Data;
        Data = new Vector[2];
        Vector data = new Vector();
        Vector colNames = new Vector();
        colNames.add("会议室号");
        colNames.add("会议室位置");
        colNames.add("承担人数");
        colNames.add("价格");
        colNames.add("日期");
        colNames.add("预约开始时间");
        colNames.add("预约结束时间");
        for(AppMeetingRoom meetingroom : AppMeetingroom){
            Vector row = new Vector();
            row.add(meetingroom.getRno());
            row.add(meetingroom.getRoa());
            row.add(meetingroom.getRca());
            row.add(meetingroom.getRpri());
            row.add(meetingroom.getDate());
            row.add(meetingroom.getSTIME());
            row.add(meetingroom.getETIME());
            data.add(row);
        }
        sqlSession.close();
        Data[0] = data;
        Data[1] = colNames;
        return Data;

    }

    public boolean book(Appointment appointment) {
        boolean isSuccess = false;

        //首先判断该时段是否被预订
        if(!isBooked(appointment.getRno(),appointment.getSTIME(),appointment.getETIME(),appointment.getDate())) {
            SqlSession sqlSession = MyBatisUtil.getSqlSession();
            UserServiceMapper AppMapper = sqlSession.getMapper(UserServiceMapper.class);
            boolean isAdd = false;

            //添加预约单,并且用isAdd作为添加订单成功的标识
            int isAddAppointment = AppMapper.addAppointment(user.getUno(), appointment.getRno(), appointment.getSTIME(), appointment.getETIME(), appointment.getDate());
            System.out.println("isAddAppointment:"+isAddAppointment);
            if(isAddAppointment > 0) {
                isAdd = true;
            }
            int hours;
            int pri=0;
            int money;
            hours = user.countTime(appointment.getSTIME(),appointment.getETIME());

            //查询预订会议室的价格并计算费用
            pri = AppMapper.getRpriOfRoom(appointment.getRno());
            System.out.println("hours:"+hours);
            money = hours*pri;
            System.out.println("money:"+money);



            //更新用户待缴费用,并且以isUpdate作为更新成功的标识
            boolean isUpdate = false;
            int Update = AppMapper.addUserMoney(user.getUno(), money);
            if(Update > 0){
                isUpdate = true;
            }
            System.out.println("isAdd:"+isAdd);
            System.out.println("isUpdate:"+isUpdate);

            //当两者同为成功时,改流程才算成功
            if(isUpdate == true && isAdd == true){
                isSuccess = true;
            }
            sqlSession.commit();
            sqlSession.close();
        }
        return isSuccess;
    }

    public boolean cancel(Appointment appointment) {
        int hours;
        int pri=0;
        int money;
        boolean isSuccess = false;

        //计算原预订时长,方便返还费用
        hours = user.countTime(appointment.getSTIME(),appointment.getETIME());
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        UserServiceMapper AppMapper = sqlSession.getMapper(UserServiceMapper.class);

        //取消预订,并通过sql执行的修改数来判断是否成功取消。若sql返还的受影响记录为0,说明没有修改成功
        int cancelAppointment = AppMapper.cancelAppointment(appointment.getAno(), user.getUno());
        boolean isCancel = false;
        if(cancelAppointment > 0){
            isCancel = true;
        }
        pri = AppMapper.getRpriOfRoom(appointment.getRno());
        money = hours*pri;

        //修改用户待缴费用
        int updateUserMoney = AppMapper.updateUserMoney(appointment.getUno(), money);
        boolean isUpdate = false;
        if(updateUserMoney>0){
            isUpdate = true;
        }

        //两个都成功时,才判定该行动成功
        if(isCancel == true && isUpdate == true){
            isSuccess = true;
        }
        sqlSession.commit();
        sqlSession.close();
        return isSuccess;
    }

    public boolean report(Meetingroom meetingroom) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        UserServiceMapper Mapper = sqlSession.getMapper(UserServiceMapper.class);
        int Update = Mapper.reportEquipStd(meetingroom.getRno());
        boolean isUpdate = false;
        if(Update > 0) {
            isUpdate = true;
            System.out.println("已成功上报设备损坏!");
        }
        sqlSession.commit();
        sqlSession.close();
        return isUpdate;
    }

    //普通用户只能查询自己的预约
    public Vector[] getAppointment(String date) {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        UserServiceMapper AppMapper = sqlSession.getMapper(UserServiceMapper.class);
        List<Appointment> appointmentByDate = AppMapper.getAppointmentByUno(user.getUno());
        Vector[] Data = new Vector[2];
        Vector data = new Vector();
        Vector colNames = new Vector();
        colNames.add("预约号");
        colNames.add("用户号");
        colNames.add("会议室号");
        colNames.add("开始时间");
        colNames.add("结束时间");
        colNames.add("日期");
        for(Appointment appointment : appointmentByDate){
            Vector row = new Vector();
            row.add(appointment.getAno());
            row.add(appointment.getUno());
            row.add(appointment.getRno());
            row.add(appointment.getSTIME());
            row.add(appointment.getETIME());
            row.add(appointment.getDate());
            data.add(row);
        }
        sqlSession.close();
        Data[0] = data;
        Data[1] = colNames;
        return Data;
    }

    public boolean changePw() {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        UserServiceMapper Mapper = sqlSession.getMapper(UserServiceMapper.class);
        int Update = Mapper.changePW(user.getUno(), user.getPassword());
        boolean isUpdate = false;
        if(Update > 0) {
            isUpdate = true;
            System.out.println("已成功修改用户密码!");
        }
        sqlSession.commit();
        sqlSession.close();
        return isUpdate;
    }

    //普通用户只能查看自己的余额
    public int showUsermonye(String Uno) {
        int money=0;
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        UserServiceMapper MoneyMapper = sqlSession.getMapper(UserServiceMapper.class);
        money = MoneyMapper.showUserMoneyByUno(user.getUno());
        sqlSession.close();
        return money;
    }

    private boolean isBooked (String Rno, String stime, String etime, String date) {
        boolean isbooked = false;
        Date Stime = new Date();
        Date Etime = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        try{
            Stime = sdf.parse(stime);
            Etime = sdf.parse(etime);
        } catch (ParseException pe) {

        }
        Time s = new Time(Stime.getTime());
        Time e = new Time(Etime.getTime());
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        UserServiceMapper AppMapper = sqlSession.getMapper(UserServiceMapper.class);
        List<Appointment> appointmentByDate = AppMapper.isBookedAppointmentByDate(Rno, date);
        for(Appointment appointment : appointmentByDate){
            Time S = Time.valueOf(appointment.getSTIME());
            Time E = Time.valueOf(appointment.getETIME());
            if(!(s.after(E) || e.before(S))){
                isbooked = true;
            }
        }
        sqlSession.close();
        return isbooked;
    }

    //////////////以下函数普通user无法使用。/////////////////////////////////////////////
    public boolean setMeetingroomstd(String Rno, int std) {
        return false;
    }
    public boolean removeAppointment(Appointment appointment) {
        return false;
    }
    public boolean addAppointment(Appointment appointment) {
        return false;
    }
    public boolean setMeetingroomEqup(String Rno, int std) {
        return false;
    }
    public Vector[] getAllEqupment() {
        return new Vector[0];
    }
    public boolean setEqupmentstd(String Pno, int std) {
        return false;
    }
    public boolean setUsermoney(String Uno, int ammount) {
        return false;
    }

}


Mapper层的具体情况如下:
Mapper层文件
一个Mapper映射xml文件对应一个接口

每个接口就是一个包含CRUD等操作的映射器,在业务层借助MybatisUtil工具类的帮助实现映射器实例化,查询和返还数据集。

MybatisUtil 在需要调用Mapper映射器时,会需要此工具类

package MybatisUtil;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class MyBatisUtil {
    private static SqlSessionFactory sqlSessionFactory;
    static {
        try {
            //获取sqlSessionFactory对象
            String resource = "mybatis-config.xml";
            InputStream inputStream = Resources.getResourceAsStream(resource);
            sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    //既然有了 SqlSessionFactory,顾名思义,我们可以从中获得 SqlSession 的实例。
    // SqlSession 提供了在数据库执行 SQL 命令所需的所有方法。你可以通过 SqlSession 实例来直接执行已映射的 SQL 语句。
    public static SqlSession getSqlSession(){
        return sqlSessionFactory.openSession();
    }

}
代码重构:发现和解决后端开发中的常见问题 通过解决长函数、过长的参数列表、重复代码和复杂的条件逻辑等常见的坏味道,我们可以改善代码的可读性、可维护性和可测试性。重构需要谨慎进行,并结合单元测试来确保重构后的代码的正确性。本文将介绍一些常见的后端开发中的坏味道,并提供相应的代码示例,以及如何进行重构来改善代码质量。将重复的代码抽取到单独的函数或方法中,然后在需要使用的地方调用该函数或方法。这样可以提高代码的可读性和可维护性,减少重复代码,并促进单元测试。使用策略模式或将复杂的条件逻辑抽取为独立的函数,以提高代码的可读性和可维护性。 阅读详情

相关推荐

Java职工管理系统课设源码重构指南

Java桌面应用开发中,Swing+JDBC构建的职工信息管理系统是经典教学案例,其背后涉及GUI线程安全、JDBC连接池原理、中文编码治理及模块化演进等核心工程能力。理解Swing事件分发机制可规避界面假死,掌握手动连接池实现有助于深入事务控制与资源复用,而UTF-8三重编码对齐则直击MySQL中文乱码根因。该系统天然适配校招面试场景——DAO抽象、内存泄漏防护、JUnit测试覆盖等均映射高频考点。本文以典型课设DOC源码为起点,聚焦Swing桌面应用的真实约束与可维护升级路径,提供从运行到生产可用的全链

weixin_33883104的博客 231

作为一个后端研发,我是如何进行系统重构的

在本文中,我们探讨了系统重构对于后端研发的重要性,并介绍了如何通过通用业务流程和技术模块的重新设计来提升系统效率和稳定性。

yufengzxj 1669

Arduino蜂鸣器播放《Astronomia》:从乐谱到代码的嵌入式音乐实现

在嵌入式系统开发中,通过编程控制硬件执行特定任务是核心基础。其原理在于利用微控制器生成精确的时序和频率信号,驱动执行器(如蜂鸣器、电机)完成预定动作。这项技术的价值在于实现了软件逻辑与物理世界的直接交互,是物联网设备、智能硬件开发的基石。常见的应用场景包括电子玩具的音效生成、报警器设计以及交互式艺术装置。本文以热门歌曲《Astronomia》的播放为例,具体展示了如何运用Arduino的`tone()`函数和数组数据结构,将抽象的乐谱转化为可执行的频率与延时控制代码,完整呈现了从**核心硬件解析**到**软

weixin_29796279的博客 348

阶段项目:学生信息管理系统数据库设计

问题描述:一、后台数据库的设计1)设计数据库2)插入数据3)查询数据4)修改数据5)管理数据1.导出数据到各种异构数据源、导出脚本2.附加和分离数据库二、前端界面的开发(后期我们可以用dNet开发) 问题描述:        上海某高校拟开发一套高校信息管理系统,该系统包括学生档案管理、学生成绩管理、教员信息管理、教务排课等模块,实现学生档案录入、修改、查询,成绩录入、修改、查询,教务排课管理等功能。        开发此模

My_daily_life的博客 3470

视觉惯性SLAM系列——ORB-SLAM3的整体介绍及各个线程的功能(五)

跟踪线程(Tracking Thread)作用:负责处理每一帧图像,进行相机位姿的估计和定位。它首先执行与前一帧图像的特征匹配,然后通过仅运动(motion-only)BA(Bundle Adjustment)优化位姿。如果跟踪失败,它会尝试在所有地图中进行重定位。此外,跟踪线程还负责决定何时插入新的关键帧,以及何时将关键帧从局部地图中移除。详细介绍见局部建图线程(Local Mapping Thread)作用:管理局部地图,向活跃地图添加关键帧和点,移除多余的关键帧和点。

曾经也曾立志 1004

STM32N6:MCU+NPU架构如何重塑边缘AI部署新范式

STM32N6作为业界首款MCU+NPU架构的通用微控制器,通过集成600 GOPS算力的NPU与800MHz Cortex-M55内核,实现了边缘AI部署的革命性突破。该方案在工业视觉和智能家居等场景中,以超低功耗和成本提供实时AI处理能力,性能较传统MCU提升超100倍,重塑了边缘智能设备的设计范式。

g8f9d0s1a2的博客 1292

重构了后端服务,我学到了这些东西

我是Kurio(来自印度尼西亚的一款新闻聚合器)的软件工程师。Kurio是一款聚合器应用程序,我们的主要工作是:收集发布合作伙伴网站上的新闻或文章,并通过我们的应用程序将其提供给用户。与其他新闻聚合器一样,我们为用户提供了多种新闻内容,例如按我们的top_stories逻辑进行排序的新闻、按照趋势进行分类的新闻以及来自特定发布商的新闻。移动端的Kurio新闻布局Feed的构建过程由我们的Feed服...

cpongo5 322

基于深度强化学习的无地图移动机器人导航:让机器人在未知环境中智能前行

虽然仍然面临sim-to-real差距、安全性保证等挑战,但随着算法的不断改进和计算能力的提升,基于DRL的无地图导航技术将在服务机器人、工业自动化、太空探索等领域发挥越来越重要的作用,为人类生产和生活带来更大便利和价值。对于复杂环境下的动态目标导航问题,研究人员提出了多智能体协同控制算法(如Teamwork-Net算法),通过多个智能体分别控制机器人的运动速度与运动方向,协同实现更高效、更稳定的导航性能。深度强化学习结合了深度学习的感知能力和强化学习的决策能力,非常适合解决无地图导航问题。

weixin_45131592的博客 903

03 服务端重构总结

花费了差不多1个多月的时间,任天赋、王帅琪和我三人功共同完成了隐私信息管理系统的前后端代码的重构工作。 其中,王帅琪独立完成了前端代码的重构工作,任天赋负责服务端代码中大部分“写”的操作以及与第三方平台对接的代码工作,我负责的是服务端代码中绝大部分与前端对接的“读”的操作以及与隐私合规平台预设规则对接的代码工作。 下面谈一谈我在进行重构过程中的体会和看法。 重构的原因 之所以进行重构,是因为之前的...

多啦的博客 1003

05 Transformer 到底解决了什么问题

Transformer 是现代大语言模型的底层骨架。本文不推公式,而是从 CNN、RNN/LSTM 的瓶颈讲起,解释 Transformer 如何通过自注意力同时解决长距离依赖和并行训练问题,并说明它为什么能支撑 GPT、BERT 和现代大模型的规模化。

老于的笔记的专栏 248

1.14、基于NARX神经网络的磁悬浮建模(matlab)

数据准备:首先,需要准备用于训练和测试的磁悬浮系统的输入和输出数据,包括磁力、电流、位置、速度等信息。数据可以被保存在MATLAB的数据文件中,并加载到工作空间中。使用MATLAB的神经网络工具箱,创建一个NARX神经网络。需要定义网络的层次结构、节点数、激活函数等参数。通常,NARX网络包括自回归层和外部输入层。数据预处理:对加载的数据进行预处理,包括去除噪声、归一化处理等操作,以确保数据质量和网络训练的稳定性。使用MATLAB的训练函数,如trainlm或者trainbr,对NARX神经网络进行训练。

XU157303764的博客 1999

运维系列【仅供参考】:Chat2DB 3.0 发布:SQL 界的 “Cursor”到底有多炸?

Chat2DB 3.0 发布:SQL 界的 “Cursor”到底有多炸?

weixin_54626591的博客 2140

多模态论文笔记——BLIP

本文详细介绍这几年AIGC火爆的隐藏功臣,多模态模型:BLIP。

haopinglianlian的博客 2454

最完整Syncthing 2.0版本解析:从数据库重构到性能飞跃的全维度升级指南

当你面对TB级文件同步缓慢如蜗牛、日志文件杂乱无章难以调试、跨设备连接频繁中断等问题时,Syncthing 2.0的发布带来了革命性的解决方案。作为一款开源的持续文件同步工具(Continuous File Synchronization),Syncthing 2.0通过底层架构重构、性能优化和用户体验升级,彻底改变了分布式文件同步的游戏规则。 读完本文后,你将获得: - 数据库迁移的完整操作指...

gitblog_00237的博客 1343

Python对象的基本组成和内存示意图及引用的本质

在Python中,变量也称为:对象的引用(reference)。变量存储的就是对象的地址。变量不需要显式声明类型。根据变量引用的对象,Python解释器自动确定数据类型。一个内存块,拥有特定的值,支持特定类型的相关操作。变量位于:栈内存(压栈出栈等细节,后续再介绍)。⚠️Python是动态类型语言。变量通过地址引用了“对象”。

Calor13的博客 557

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

我用 Claude Code 三天重构了整个后端,这是完整记录

三天重构两万行代码,这件事本身不是重点。有了 AI 编程工具,"重构"这件所有人都知道该做但没人敢做的事,终于有了可行路径。技术债不会自己消失,但还清它的成本,正在急剧下降。

qq_23829681的博客 1243

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

系统架构重构

下面,我们针对系统架构和设计中的“坏味”(注:“坏味”是 Martin Fowler 的一个著名概念),分别总结出的一些“重构模式”,看看这些模式是如何把这些设计“坏味”去掉的。1,实体重新命名问题:进行架构和设计时所界定出来的系统组成元素(子系统、构件、模块等)名称使用混乱,不能很好地表达该系统元素的用途或语义,使系统结构难以理解。事实上,一个架构发展的历程中,命名的逐渐混乱,是促使架构老化的重

微软新技术 1872

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

我下个月就要跳槽了,还重构什么代码!

点击上方“Java后端技术”,点击右上角-设为星标有趣有深度的文章每天八点半准时送达!作者 :木易小光 |  微信公众号:木易小光代码重构,国内的IT行业的企业,不敢说1...

Java后端技术 792

Java前后端分离重构_浅谈前后端分离与实践(一)

一、起源(故事纯属虚构,如有雷同,纯属巧合)传说在很久很久以前,我们有志之士有了个创业的想法,于是乎开始了自己的创业之梦,但是人手不足啊,于是乎所有角色老子一个人全包了:Roles: PM, DBA, RD, FED, Designer, ...Skills: Linux, MySQL, JAVA, JavaScript, HTML, CSS, ...Tools: phpmyadmin, phot...

weixin_28732953的博客 546

有关重构项目的一些小经验

最近开始重构,发现重构真的是即恶心又爽的一件事。不断的发现问题,解决问题。 个人觉得后端重构要注意以下的几个点: 最重要的一点:新启一套接口和方法去重构,同时保证两套系统的可用性。 1.定义和前端协议参数的时候,名称,参数类型一定要统一,并列成一个表格放在公司wiki上。 (1)类似我们原有代码,对于定义定向id,有的叫targetingId,有的叫mid。可理解性差。不同get接口应该传的...

third_的博客 4321

API 前后端分离重构

背景 后端出现大量前端代码,造成逻辑混乱,代码可读可维护性差。前端采用原始的jquery开发,前端技术已经远远落后于市面主流技术,造成开发效率低,代码混乱。 解决 采用主流前后端分离技术,包括 1.前端路由做流程控制 2.使用mvvm框架 做数据绑定 等等… 效果 后端只写接口,很多工作迁到前端,前后端语言各司其

sm_Bo的博客 1278

数据库课程设计

SqlServer数据库课程设计 假期刚回来就迎来一份数据库设计,好不容易花两个星期写完了,老师竟然说一个题目不能超过三个人,逼着我把需求给改了,难受的一匹 下面粘一下课设 资源下载地址 不知道为啥下载要一个积分,将就着看吧,没积分注册个账号上传点东西就有了。一共写了40多页,老师给打回去我又改了一次,还没要我的文档,不得不说老师扣的有点细。 ...

某翟的博客 13万+

【前端】重构方案了解一下

前端重构方案 前言 前端技术发展很快,很多项目面临前端部分重构,很开心可以让我进行这次项目前端的重构方案编写,在思考的同时参考了网上很多资料,希望本篇重构方案有一定的完整性,可以带给大家一些在面临重构时有用的东西,同时希望路过的大牛小牛不领赐教,能给我略微指点下重构相关的点,在下感激不尽~ 一、原项目梳理 首先对原来项目做一个大概的梳...

weixin_34318956的博客 1204

数据库课设

数据库课设-学生选课系统课设要求:课设内容:开发环境:源代码: ** 课设要求: 要求B/S结构,前台语言框架不限,后台数据库不限建议(SQL SERVER、MySQL) 课设内容: 实践内容13 学生选课系统 建立一个学生选课系统, 编写应用程序完成系统开发。 建立基本表: 学生(学号,姓名,性别,年龄,系别) 课程(课程号,课程名,开课系,任课教师) 学习(学号,课程号,成绩) 要求有以下子...

simple的博客 2万+

自己动手做后端(一) MySQL数据库搭建

前言 记录自己首次学习Java和MySQL,并搭建web后端的学习过程。作为一个学过一年C和C++的菜鸡,在听说要一个月内学会用Java搭建Web后端的时候,还是很虚的。但在真正接触Java之后,发现这个语言还是比C++方便太多了,又发出了初学python时的感慨——”C语言果然是最难的!“。 搭建MySQL数据库 我的数据库是使用MySQL 8.0 MySQL使用的是SQL语言,对初学者来说还是...

weixin_43551812的博客 1万+
上一篇: 数据库大作业--1.0设计总结
ELucubrate
博客等级 码龄7年 3粉丝 9原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值