本篇本章针对数据库的课设进行了重构优化,将后端使用的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&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai&useUnicode=true&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映射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();
}
}