当前位置: 首页 > news >正文

天马学航——智慧教务系统(移动端)开发日志三

天马学航——智慧教务系统(移动端)开发日志三

日志摘要:更新了学生选课模块、我的课程模块以及退课的功能,优化了后端数据库的缓存

1、学生选课模块

学生选课模块主要实现,学生根据需求进行选课操作,通过后端查询到所有教师的课程,展示在前端,然后根据前端进行选择,选择后发给后端,后端再进行判断,将选课信息返回前端

界面效果
image-20240620111914879
前端源码
struct SelectCourse {@State courses:SCourse[] = []aboutToAppear(){this.getCourse()}build() {Column({ space: 5 }) {Text(" ")Row({ space: 10 }) {Text(" ")Image($r('app.media.back')).width(30).height(30).onClick(function () {//返回上一页router.back() //直接返回})Text("学生选课").fontSize(30).fontWeight(FontWeight.Bolder)}.width('100%')Text("----------------------------------------------")Text(" ")List({space:50}){ForEach(this.courses,course=>{ListItem(){Row({space:30}){Text(" ")Column({space:20}){Text(course.cname).fontColor(Color.Green).fontSize(15).fontWeight(FontWeight.Bolder).fontFamily("楷体")Text("课程号:"+course.cid).fontSize(10).fontColor(Color.Red)Text("任课教师:"+course.tname).fontSize(10).fontColor(Color.Green)}.justifyContent(FlexAlign.Start).alignItems(HorizontalAlign.Start)Blank()Button("选择").onClick(()=>{console.log("学生点击了:"+course.cname)StudentAddCourse.STA(course.cid,course.cname,course.tname).then(resp=>{console.log("前端收到消息!"+resp)promptAction.showToast({message: resp,duration: 2000,bottom: 50});})})}.width('95%').height(150)//.padding(20).backgroundColor(Color.White).borderRadius(15).shadow({ radius: 6, color: '#1F000000', offsetX: 2, offsetY: 4 })}})}.width('100%')}.width('100%')}getCourse(){GetCourse.GC().then(resp=>{console.log("请求成功"+resp)if(resp.length === 0){promptAction.showToast({message: '暂无可选课程',duration: 2000,bottom: 50});}this.courses = resp;})}
}
请求源码
请求所有课程部分
class GetCourse {baseURL: string = IP.ipGC(): Promise<SCourse[]> {return new Promise((resolve, reject) => {let Http = http.createHttp()Http.request(`${this.baseURL}/GCourse`,{method: http.RequestMethod.GET,connectTimeout: 10000,readTimeout: 10000}).then(resp=>{if(resp.responseCode === 200){console.log("请求成功"+resp.result)resolve(JSON.parse(resp.result.toString()))}else {console.log("请求发现异常"+resp.responseCode)}}).catch(error=>{console.log("请求失败")})})}
}const gc = new GetCourse()
export default gc as GetCourse
向后端发送选课结果部分
class StudentAddCourse{baseURL: string = IP.ipSTA(cid:string,cname:string,cteacher:string):Promise<string>{const data = {cid:cid,cname:cname,cteacher:cteacher}return new Promise((resolve, reject) => {let httpRequest = http.createHttp()httpRequest.request(`${this.baseURL}/StuSelectcourse`,{method:http.RequestMethod.GET,extraData:data,connectTimeout: 10000,readTimeout:10000},).then(resp=>{if(resp.responseCode === 200){console.log("请求成功:"+resp.result)resolve(resp.result.toString())}else {console.log("请求失败:"+resp.responseCode)}}).catch(error=>{console.log("检查链接!")})})}
}const aa = new StudentAddCourse()
export default aa as StudentAddCourse
后端源码
请求所有课程部分
public class getCourse extends HttpServlet {@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {resp.setContentType("application/json");resp.setCharacterEncoding("UTF-8");//MybatisSqlSession sql = MybatisUntills.getSqlSession();CourseMapper mapper = sql.getMapper(CourseMapper.class);List<SelectCourse> allCourse = mapper.getAllCourse();//执行并返回数据for (SelectCourse selectCourse : allCourse) {System.out.println(selectCourse.getCid()+selectCourse.getCname()+selectCourse.getTname());}sql.close();//打包Gson gson = new Gson();String JsonData = gson.toJson(allCourse);//发送resp.getWriter().write(JsonData);}@Overrideprotected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {doGet(req, resp);}
}
接收学生选课信息部分
public class StuSelectCourse extends HttpServlet {@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {resp.setContentType("application/json");resp.setCharacterEncoding("UTF-8");ServletContext c = getServletContext();HttpSession session = req.getSession();String username = (String) session.getAttribute("username");if(username == null){username = (String) c.getAttribute("username");}String cid = req.getParameter("cid");String cname = req.getParameter("cname");String ct = req.getParameter("cteacher");System.out.println("课程号"+cid);//MybatisSqlSession sql = MybatisUntills.getSqlSession();CourseMapper mapper = sql.getMapper(CourseMapper.class);Map<String,Object> map1 = new HashMap<String, Object>();map1.put("cid",cid);map1.put("sid",username);String strings = mapper.showStudentCourse(map1);if(strings!=null){resp.getWriter().write("后端返回信息:该课程已存在!");sql.close();}else {Map<String,Object> map = new HashMap<String, Object>();map.put("cid",cid);map.put("sid",username);int i = mapper.addStudentCourse(map);sql.commit();if(i==1){resp.getWriter().write("后端返回信息:选课成功!");System.out.println("成!");}else {resp.getWriter().write("后端返回信息:选课失败!");}sql.close();}}@Overrideprotected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {doGet(req, resp);}
}

2、我的课程(退课模块)

主要显示该用户选择的所有课程,并提供退课的选项,后端查询,前端显示,前端选择,后端判断,将信息返回前端

界面效果
image-20240620111914879
前端源码
struct MyCourse{@State courses:StudentMyCourse[] = []aboutToAppear(){this.MyCourses()}build() {Column({ space: 5 }) {Text(" ")Row({ space: 10 }) {Text(" ")Image($r('app.media.back')).width(30).height(30).onClick(function () {//返回上一页router.back() //直接返回})Text("我的课程").fontSize(30).fontWeight(FontWeight.Bolder)}.width('100%')Text("----------------------------------------------")Text(" ")List({space:50}){ForEach(this.courses,course=>{ListItem(){Row({space:30}){Text(" ")Column({space:20}){Text(course.cname).fontColor(Color.Green).fontSize(15).fontWeight(FontWeight.Bolder).fontFamily("楷体")Text("课程号:"+course.cid).fontSize(10).fontColor(Color.Red)Text("任课教师:"+course.tname).fontSize(10).fontColor(Color.Green)Text("上课时间:"+course.ctime).fontSize(10).fontColor(Color.Green)}.justifyContent(FlexAlign.Start).alignItems(HorizontalAlign.Start)Blank()Button("退课").backgroundColor(Color.Red).onClick(()=>{console.log("学生点击了:"+course.cname)DeletCourse.STA(course.cname,course.cid,course.tname,course.ctime).then(resp=>{console.log("返回成功"+resp)promptAction.showToast({message: resp,duration: 2000,bottom: 50});})})}.width('95%').height(150)//.padding(20).backgroundColor(Color.White).borderRadius(15).shadow({ radius: 6, color: '#1F000000', offsetX: 2, offsetY: 4 })}})}.width('100%')}}MyCourses(){GetStudentCourse.GC().then(resp=>{console.log("返回信息成功"+resp.toString())if(resp.length === 0){promptAction.showToast({message: '您还没有选课哦~',duration: 2000,bottom: 50});}this.courses = resp})}
}
请求源码
请求所选课程
class GetStudentCourse {baseURL: string = IP.ipGC(): Promise<StudentMyCourse[]> {return new Promise((resolve, reject) => {let Http = http.createHttp()Http.request(`${this.baseURL}/GetMyCourse`,{method: http.RequestMethod.GET,connectTimeout: 10000,readTimeout: 10000}).then(resp => {if (resp.responseCode === 200) {console.log("请求成功" + resp.result)resolve(JSON.parse(resp.result.toString()))}else {console.log("请求成功,但是出现问题" + resp.responseCode)}}).catch(error => {console.log("请求失败" + error)})})}
}const sc = new GetStudentCourse()
export default sc as GetStudentCourse
向后端发送退课信息
class DeletCourse {baseURL: string = IP.ipSTA(cname: string, cid: string, tname: string,ctime: string): Promise<string> {const data = {cname: cname,cid: cid,tname: tname,ctime:ctime}return new Promise((resolve, reject) => {let httpRequest = http.createHttp()httpRequest.request(`${this.baseURL}/DeletMyCourse`,{method: http.RequestMethod.GET,extraData: data,connectTimeout: 10000,readTimeout: 10000},).then(resp=>{if(resp.responseCode===200){console.log("请求成功!"+resp.result)resolve(resp.result.toString())}else {console.log("请求发生错误"+resp.responseCode)}}).catch(err=>{console.log("请求失败"+err)})})}
}const sc = new DeletCourse()
export default sc as DeletCourse

后端代码与选课部分相同,这里不再赘述

3、BUG修复

修复了Mybatis二级缓存溢出导致查询变慢的问题

天马学航——智慧教务系统(移动端)开发日志二

日志摘要:更新了学生选课模块、我的课程模块以及退课的功能,优化了后端数据库的缓存

1、学生选课模块

学生选课模块主要实现,学生根据需求进行选课操作,通过后端查询到所有教师的课程,展示在前端,然后根据前端进行选择,选择后发给后端,后端再进行判断,将选课信息返回前端

界面效果
image-20240620111914879
前端源码
struct SelectCourse {@State courses:SCourse[] = []aboutToAppear(){this.getCourse()}build() {Column({ space: 5 }) {Text(" ")Row({ space: 10 }) {Text(" ")Image($r('app.media.back')).width(30).height(30).onClick(function () {//返回上一页router.back() //直接返回})Text("学生选课").fontSize(30).fontWeight(FontWeight.Bolder)}.width('100%')Text("----------------------------------------------")Text(" ")List({space:50}){ForEach(this.courses,course=>{ListItem(){Row({space:30}){Text(" ")Column({space:20}){Text(course.cname).fontColor(Color.Green).fontSize(15).fontWeight(FontWeight.Bolder).fontFamily("楷体")Text("课程号:"+course.cid).fontSize(10).fontColor(Color.Red)Text("任课教师:"+course.tname).fontSize(10).fontColor(Color.Green)}.justifyContent(FlexAlign.Start).alignItems(HorizontalAlign.Start)Blank()Button("选择").onClick(()=>{console.log("学生点击了:"+course.cname)StudentAddCourse.STA(course.cid,course.cname,course.tname).then(resp=>{console.log("前端收到消息!"+resp)promptAction.showToast({message: resp,duration: 2000,bottom: 50});})})}.width('95%').height(150)//.padding(20).backgroundColor(Color.White).borderRadius(15).shadow({ radius: 6, color: '#1F000000', offsetX: 2, offsetY: 4 })}})}.width('100%')}.width('100%')}getCourse(){GetCourse.GC().then(resp=>{console.log("请求成功"+resp)if(resp.length === 0){promptAction.showToast({message: '暂无可选课程',duration: 2000,bottom: 50});}this.courses = resp;})}
}
请求源码
请求所有课程部分
class GetCourse {baseURL: string = IP.ipGC(): Promise<SCourse[]> {return new Promise((resolve, reject) => {let Http = http.createHttp()Http.request(`${this.baseURL}/GCourse`,{method: http.RequestMethod.GET,connectTimeout: 10000,readTimeout: 10000}).then(resp=>{if(resp.responseCode === 200){console.log("请求成功"+resp.result)resolve(JSON.parse(resp.result.toString()))}else {console.log("请求发现异常"+resp.responseCode)}}).catch(error=>{console.log("请求失败")})})}
}const gc = new GetCourse()
export default gc as GetCourse
向后端发送选课结果部分
class StudentAddCourse{baseURL: string = IP.ipSTA(cid:string,cname:string,cteacher:string):Promise<string>{const data = {cid:cid,cname:cname,cteacher:cteacher}return new Promise((resolve, reject) => {let httpRequest = http.createHttp()httpRequest.request(`${this.baseURL}/StuSelectcourse`,{method:http.RequestMethod.GET,extraData:data,connectTimeout: 10000,readTimeout:10000},).then(resp=>{if(resp.responseCode === 200){console.log("请求成功:"+resp.result)resolve(resp.result.toString())}else {console.log("请求失败:"+resp.responseCode)}}).catch(error=>{console.log("检查链接!")})})}
}const aa = new StudentAddCourse()
export default aa as StudentAddCourse
后端源码
请求所有课程部分
public class getCourse extends HttpServlet {@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {resp.setContentType("application/json");resp.setCharacterEncoding("UTF-8");//MybatisSqlSession sql = MybatisUntills.getSqlSession();CourseMapper mapper = sql.getMapper(CourseMapper.class);List<SelectCourse> allCourse = mapper.getAllCourse();//执行并返回数据for (SelectCourse selectCourse : allCourse) {System.out.println(selectCourse.getCid()+selectCourse.getCname()+selectCourse.getTname());}sql.close();//打包Gson gson = new Gson();String JsonData = gson.toJson(allCourse);//发送resp.getWriter().write(JsonData);}@Overrideprotected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {doGet(req, resp);}
}
接收学生选课信息部分
public class StuSelectCourse extends HttpServlet {@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {resp.setContentType("application/json");resp.setCharacterEncoding("UTF-8");ServletContext c = getServletContext();HttpSession session = req.getSession();String username = (String) session.getAttribute("username");if(username == null){username = (String) c.getAttribute("username");}String cid = req.getParameter("cid");String cname = req.getParameter("cname");String ct = req.getParameter("cteacher");System.out.println("课程号"+cid);//MybatisSqlSession sql = MybatisUntills.getSqlSession();CourseMapper mapper = sql.getMapper(CourseMapper.class);Map<String,Object> map1 = new HashMap<String, Object>();map1.put("cid",cid);map1.put("sid",username);String strings = mapper.showStudentCourse(map1);if(strings!=null){resp.getWriter().write("后端返回信息:该课程已存在!");sql.close();}else {Map<String,Object> map = new HashMap<String, Object>();map.put("cid",cid);map.put("sid",username);int i = mapper.addStudentCourse(map);sql.commit();if(i==1){resp.getWriter().write("后端返回信息:选课成功!");System.out.println("成!");}else {resp.getWriter().write("后端返回信息:选课失败!");}sql.close();}}@Overrideprotected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {doGet(req, resp);}
}

2、我的课程(退课模块)

主要显示该用户选择的所有课程,并提供退课的选项,后端查询,前端显示,前端选择,后端判断,将信息返回前端

界面效果
image-20240620111914879
前端源码
struct MyCourse{@State courses:StudentMyCourse[] = []aboutToAppear(){this.MyCourses()}build() {Column({ space: 5 }) {Text(" ")Row({ space: 10 }) {Text(" ")Image($r('app.media.back')).width(30).height(30).onClick(function () {//返回上一页router.back() //直接返回})Text("我的课程").fontSize(30).fontWeight(FontWeight.Bolder)}.width('100%')Text("----------------------------------------------")Text(" ")List({space:50}){ForEach(this.courses,course=>{ListItem(){Row({space:30}){Text(" ")Column({space:20}){Text(course.cname).fontColor(Color.Green).fontSize(15).fontWeight(FontWeight.Bolder).fontFamily("楷体")Text("课程号:"+course.cid).fontSize(10).fontColor(Color.Red)Text("任课教师:"+course.tname).fontSize(10).fontColor(Color.Green)Text("上课时间:"+course.ctime).fontSize(10).fontColor(Color.Green)}.justifyContent(FlexAlign.Start).alignItems(HorizontalAlign.Start)Blank()Button("退课").backgroundColor(Color.Red).onClick(()=>{console.log("学生点击了:"+course.cname)DeletCourse.STA(course.cname,course.cid,course.tname,course.ctime).then(resp=>{console.log("返回成功"+resp)promptAction.showToast({message: resp,duration: 2000,bottom: 50});})})}.width('95%').height(150)//.padding(20).backgroundColor(Color.White).borderRadius(15).shadow({ radius: 6, color: '#1F000000', offsetX: 2, offsetY: 4 })}})}.width('100%')}}MyCourses(){GetStudentCourse.GC().then(resp=>{console.log("返回信息成功"+resp.toString())if(resp.length === 0){promptAction.showToast({message: '您还没有选课哦~',duration: 2000,bottom: 50});}this.courses = resp})}
}
请求源码
请求所选课程
class GetStudentCourse {baseURL: string = IP.ipGC(): Promise<StudentMyCourse[]> {return new Promise((resolve, reject) => {let Http = http.createHttp()Http.request(`${this.baseURL}/GetMyCourse`,{method: http.RequestMethod.GET,connectTimeout: 10000,readTimeout: 10000}).then(resp => {if (resp.responseCode === 200) {console.log("请求成功" + resp.result)resolve(JSON.parse(resp.result.toString()))}else {console.log("请求成功,但是出现问题" + resp.responseCode)}}).catch(error => {console.log("请求失败" + error)})})}
}const sc = new GetStudentCourse()
export default sc as GetStudentCourse
向后端发送退课信息
class DeletCourse {baseURL: string = IP.ipSTA(cname: string, cid: string, tname: string,ctime: string): Promise<string> {const data = {cname: cname,cid: cid,tname: tname,ctime:ctime}return new Promise((resolve, reject) => {let httpRequest = http.createHttp()httpRequest.request(`${this.baseURL}/DeletMyCourse`,{method: http.RequestMethod.GET,extraData: data,connectTimeout: 10000,readTimeout: 10000},).then(resp=>{if(resp.responseCode===200){console.log("请求成功!"+resp.result)resolve(resp.result.toString())}else {console.log("请求发生错误"+resp.responseCode)}}).catch(err=>{console.log("请求失败"+err)})})}
}const sc = new DeletCourse()
export default sc as DeletCourse

后端代码与选课部分相同,这里不再赘述

3、BUG修复

修复了Mybatis二级缓存溢出导致查询变慢的问题

相关文章:

  • 用友U9-UBF自定义报表-打印模板开发学习笔记
  • SpringBoot测试实践
  • Spark SQL 血缘解析方案
  • 【Apache Doris】周FAQ集锦:第 7 期
  • python,ipython 和 jupyter notebook 之间的关系
  • 什么是N卡和A卡?有什么区别?
  • Python设计模式 - 简单工厂模式
  • Linux驱动开发笔记(十一)tty子系统及其驱动
  • AMSR/ADEOS-II L1A Raw Observation Counts V003地球表面和大气微波辐射的详细观测数据
  • 计算机组成原理笔记-第1章 计算机系统概论
  • 大疆无人机航点飞行KMZ文件提取航点坐标
  • 保存和调取得分的简易方法
  • Github 2024-06-19 C开源项目日报 Top9
  • C#面: 能够将非静态的方法覆写成静态方法吗?
  • Jenkins macos 下 failed to create dmg 操作不被允许hdiutil: create failed - 操作不被允许?
  • 【划重点】MySQL技术内幕:InnoDB存储引擎
  • Bootstrap JS插件Alert源码分析
  • CNN 在图像分割中的简史:从 R-CNN 到 Mask R-CNN
  • CSS进阶篇--用CSS开启硬件加速来提高网站性能
  • ES6 ...操作符
  • exports和module.exports
  • JDK 6和JDK 7中的substring()方法
  • JS基础之数据类型、对象、原型、原型链、继承
  • Synchronized 关键字使用、底层原理、JDK1.6 之后的底层优化以及 和ReenTrantLock 的对比...
  • VUE es6技巧写法(持续更新中~~~)
  • 从零开始的无人驾驶 1
  • 对话:中国为什么有前途/ 写给中国的经济学
  • 分享一个自己写的基于canvas的原生js图片爆炸插件
  • 高程读书笔记 第六章 面向对象程序设计
  • 海量大数据大屏分析展示一步到位:DataWorks数据服务+MaxCompute Lightning对接DataV最佳实践...
  • 面试总结JavaScript篇
  • 巧用 TypeScript (一)
  • 容器化应用: 在阿里云搭建多节点 Openshift 集群
  • 如何优雅的使用vue+Dcloud(Hbuild)开发混合app
  • 算法-图和图算法
  • 原创:新手布局福音!微信小程序使用flex的一些基础样式属性(一)
  • 主流的CSS水平和垂直居中技术大全
  • hi-nginx-1.3.4编译安装
  • SAP CRM里Lead通过工作流自动创建Opportunity的原理讲解 ...
  • 我们雇佣了一只大猴子...
  • ​1:1公有云能力整体输出,腾讯云“七剑”下云端
  • ​马来语翻译中文去哪比较好?
  • "无招胜有招"nbsp;史上最全的互…
  • #C++ 智能指针 std::unique_ptr 、std::shared_ptr 和 std::weak_ptr
  • (C++20) consteval立即函数
  • (JS基础)String 类型
  • (Matalb回归预测)PSO-BP粒子群算法优化BP神经网络的多维回归预测
  • (八)Spring源码解析:Spring MVC
  • (二十六)Java 数据结构
  • (附源码)spring boot车辆管理系统 毕业设计 031034
  • (六) ES6 新特性 —— 迭代器(iterator)
  • .cfg\.dat\.mak(持续补充)
  • .NET 8.0 发布到 IIS
  • .net Application的目录
  • .NET 动态调用WebService + WSE + UsernameToken