表名:manager
class="table-box">
字段 | 类型 | 是否必填 | 备注 |
---|
id | int | 是 | 管理员ID,主键 |
user | varchar(100) | 是 | 登陆账户 |
pw | varchar(100) | 是 | 密码 |
safety_code | varchar(10) | 是 | 安全码 |
CREATE TABLE IF NOT EXISTS manager(
id INT NOT NULl PRIMARY KEY AUTO_INCREMENT,
user VARCHAR(100) NOT NULL COMMENT "登陆账户",
pw VARCHAR(100) NOT NULL COMMENT "密码",
safety_code VARCHAR(10) NOT NULL COMMENT "安全码"
)ENGINE=InnoDB;
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
表名:audit_logs 审计记录
class="table-box">字段 | 类型 | 是否必填 | 备注 |
---|
id | int | 是 | 管理员ID,主键 |
option | varchar(100) | 是 | 操作类型,update,delete,insert |
detail | varchar(1024) | 是 | 操作日志 |
create_by | varchar(100) | 是 | 操作管理员名称 |
create_time | TIMESTAMP | 是 | 创建时间 |
CREATE TABLE IF NOT EXISTS audit_logs(
id INT NOT NULl PRIMARY KEY AUTO_INCREMENT,
option VARCHAR(100) NOT NULL COMMENT "操作类型",
detail VARCHAR(1024) NOT NULL COMMENT "操作管理员名称",
create_by VARCHAR(100) NOT NULL COMMENT "登陆账户",
create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL COMMENT "创建时间"
)ENGINE=InnoDB;
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
3.2 结构设计
3.2.1 通用结构
3.2.1.1 student结构
stuct Student{
int id,
QString name,
QString sex,
QString sfz,
QString tel,
QStrnig address,
QString weixin,
QString qq,
QString status,
QString create_time,
QString create_by,
QString update_time,
QString update_by
};
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
3.2.1.2 usr 结构
stuct User{
int id,
QString user,
QString pw;
QString safety_code
} ;
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
3.2.1.3 audit_logs 结构
struct AuditLogs{
int id ,
QString option,
QString detail,
QString create_by,
QString create_time
};
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
3.2 接口结构
3.2.1 StudentListRequest 学生信息列表请求
struct StudentListRequest{
int page,
int size,
QString id,
QString name,
QString sex,
QString sfz,
QString weixin,
QString qq
};
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
3.2.2 StudentListRequest 学生信息列表响应
struct StudentListResponse{
int msg_code,
QString msg,
int current,
int total,
vector<Student> vecStudent
};
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
3.2.3 LoginRequest 登录请求
struct LoginRequest{
QString user;
QString pw;
};
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
3.2.4 LoginResponse 登录响应
struct LoginResponse{
int msg_code,
QString msg,
QString user,
QString loginTime
};
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
3.2.5 AuditLogsRequest 审计请求
struct AuditLogsRequest{
QString option,
QString detail,
QString createBy
};
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
3.3 接口说明
接口表示view层与controller层的对接接口,view层只需要通过controller层的接口调用获取数据,剩下展示的内容有view层进行展示。
3.3.1 学生相关接口
view和controller对接的接口
3.3.1 添加用学生信息
bool addStudentInfo(Student info);
QString sql = QString("insert into student (name,sex,sfz,tel,address,weixin,qq,status,create_by) "
"values ('%0','%1','%2','%3','%4','%5','%6','%7','%8');")
.arg(info.name)
.arg(info.sex)
.arg(info.tel)
.arg(info.address)
.arg(info.weixin)
.arg(info.qq)
.arg(QString::number(1))
.arg("test");
QSqlQuery query;
if(!query.exec(sql)){
qInfo()<<"init db data failed!"<<query.lastError()<< ":" << query.lastQuery();
return Result(0,"");
}
return Result(0,"");
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
class="hide-preCode-box">
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
3.3.2 删除学生信息
bool deleteStudentInfo(QString id);
3.3.3 更新学生信息
bool updateStudentInfo(QString id,Student newInfo);
3.3.4 查询
StudentListResponse selectStudentList(StudentListRequest studentListRequest);
StudentListResponse res;
QString where = getStudentListRequestWhere(studentListRequest);
res.total = getCountSelectStudentList(studentListRequest);
res.current = studentListRequest.page;
res.msg_code = 0;
QSqlQuery query;
QString currentOffset = QString::number(studentListRequest.page * studentListRequest.size);
QString strSize = QString::number(studentListRequest.size);
QString sql = "select * from student " +where +"limit "+ currentOffset +","+ strSize;
if(!query.exec(sql)){
res.msg_code = -1;
res.msg = query.lastError().text();
return res;
}
qInfo()<<"last:" << query.lastQuery();
while (query.next()) {
Student stu;
stu.id = query.value(0).toString();
stu.name = query.value(1).toString();
stu.sex = query.value(2).toString();
stu.sfz = query.value(3).toString();
stu.tel = query.value(4).toString();
stu.address = query.value(5).toString();
stu.weixin = query.value(6).toString();
stu.qq = query.value(7).toString();
res.vecStudent.push_back(stu);
}
return res;
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
class="hide-preCode-box">
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
3.3.2 登录相关
3.3.2.1 登录请求
LoginResponse userLogin(LoginResponse loginResponse);
if(pw.isNull() || pw.isEmpty()){
return Result(LOGIN_ERROR_PASSWORD_EMPTY,LOGIN_ERROR_PASSWORD_EMPTY_MSG);
}
Result res(0,"");
QSqlQuery query;
query.clear();
QString sql = QString("SELECT * FROM manager WHERE user = '%1'").arg(user);
query.prepare(sql);
qInfo() << query.lastQuery();
if (!query.exec()) {
qDebug() << "Error: Failed to insert student." << query.lastError();
return res;
}
QString spw;
while (query.next()) {
int id = query.value("id").toInt();
spw = query.value("pw").toString();
}
if(pw == spw){
return Result(LOGIN_OK,LOGIN_OK_MSG);
}
return Result(LOGIN_ERROR_PASSWORD,LOGIN_ERROR_PASSWORD_MSG);
class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
class="hide-preCode-box">
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
3.3.3 审计相关
3.3.31 添加审计日志
void addAuditLogs(AuditLogsRequest auditLogsRequest);
四、部署
4.1 部署概述
该学生管理系统由 Qt 前端应用程序和 MySQL 数据库组成。Qt 应用程序通过读取配置文件 my.xml 连接到位于服务器上的 MySQL 数据库。
4.2 部署步骤
-
- 安装mysql数据库
-
- 导入初始化表init.sql
-
- 配置my.xml,配置文件需要和程序放在同一个目录中
五、编译环境说明
操作系统:win10
QT:版本

编译环境配置:

五、源码地址:
https://gitcode.net/arv002/database/-/tree/master/StudentManagementSystem/StudentManagementSystem
https://gitcode.net/arv002/database/-/tree/master/StudentManagementSystem/StudentManagementSystem
其他QT文章
1. QT开发环境安装以配置。
2. QT线段画板实战
3. 半小时玩转QT桌面系统托盘(含托盘消息)
4. QT入门开发一个时钟
5. 半小时教你做大转盘游戏(QT篇)
6. 手把手教你制作【带吸附效果的线段绘制】(QT)
7. 手把手教你开发-滚动效果号码抽奖(QT)
8. 100行代码实现贪吃蛇小游戏
9.C++实现《扫雷》游戏(入门经典)
10. svg转图片工具开发
11. Qt网路与通信(获取本机网络信息)
12. Qt网路与通信(UDP客户与服务)
13. Qt网络与通信(TCP聊天室)
14. Qt多线程以及线程池
15. Qt散点图、折线图、柱状图、盒须图、饼状图、雷达图开发实例
16. 取色器(QT)
17. MQTT客户端入门开发
18.QT文件上传带进度条实例(含源码)
19. Qt音乐播放器开发实例(可毕设含源码)
20. Qt学生管理系统-- 数据库课程设计(付源码)
data-report-view="{"mod":"1585297308_001","spm":"1001.2101.3001.6548","dest":"http://iyenn.com/rec/1724008.html","extend1":"pc","ab":"new"}">>
id="blogExtensionBox" style="width:400px;margin:auto;margin-top:12px" class="blog-extension-box"> class="blog_extension blog_extension_type1" id="blog_extension">
class="blog_extension_card" data-report-click="{"spm":"1001.2101.3001.6470"}" data-report-view="{"spm":"1001.2101.3001.6470"}">
class="blog_extension_card_left">
class="blog_extension_card_cont">
class="blog_extension_card_cont_l">
Qt小王子
class="blog_extension_card_cont_r">
微信公众号
Qt分享+螺蛳粉购买
评论记录:
回复评论: