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

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

日志摘要:新增了学生端个人信息、成绩查询模块,优化前端UI等,解决了一些已知的BUG

1、学生个人信息模块

UI部分

前端UI特别简单,只需稍微设计即可

ts 复制代码
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(" ")
      Image($r('app.media.TX'))
        .width(150)
        .height(150)
      Column({space:40}){
        Text(" ")
        Row(){
          Text("学号:")
            .fontSize(25)
            .fontWeight(FontWeight.Bold)
          Text(this.students.sid)
            .fontSize(25)
        }
        Row(){
          Text("姓名:")
            .fontSize(25)
            .fontWeight(FontWeight.Bold)
          Text(this.students.sname)
            .fontSize(25)
        }
        Row(){
          Text("性别:")
            .fontSize(25)
            .fontWeight(FontWeight.Bold)
          Text(this.students.ssex)
            .fontSize(25)
        }
        Row(){
          Text("出生日期:")
            .fontSize(25)
            .fontWeight(FontWeight.Bold)
          Text(this.students.birth)
            .fontSize(25)
        }
        Row(){
          Text("家庭住址:")
            .fontSize(25)
            .fontWeight(FontWeight.Bold)
          Text(this.students.address)
            .fontSize(25)
        }
      }
      .width('90%')
      .alignItems(HorizontalAlign.Start)
    }
    .width('100%')
  }

请求部分

typescript 复制代码
import http from '@ohos.net.http';
import StuInfo from '../../pojo/Student/StuInfo';
import IP from '../../IP'

class GetStudentInfo{
  baseURL:string = IP.ip
  GT():Promise<string>{
    return new Promise((resolve,reject) => {
      let Http = http.createHttp()
      Http.request(
        `${this.baseURL}/SInfo`,
        {
          method:http.RequestMethod.GET,
          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("请求失败"+error)
        })
    })
  }
}

const s1 = new GetStudentInfo()
export default s1 as GetStudentInfo

后端部分

java 复制代码
public class StudentInfo extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json");
        resp.setCharacterEncoding("UTF-8");
        HttpSession session = req.getSession();
        ServletContext con = getServletContext();
        String username = (String) session.getAttribute("username");
        if(username == null){
            username = (String) con.getAttribute("username");
        }

        //Mybatis
        SqlSession sql = MybatisUntills.getSqlSession();
        StudentMapper mapper = sql.getMapper(StudentMapper.class);
        List<Students> student = mapper.getStudent(username);
        sql.close();

        //打包成json并发送至前端
        Gson gson = new Gson();
        String jsonData = gson.toJson(student);
        resp.getWriter().write(jsonData);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}

2、成绩查询模块

成绩查询是根据学生选择的课程,由老师评分后发送给学生端,在学生端发布

UI部分

typescript 复制代码
import router from '@ohos.router'
import SGpojo from '../../pojo/Student/SGpojo'
import GetSTGrade from '../../HttpModel/Student/GetSTGrade'
import promptAction from '@ohos.promptAction'
@Entry
@Component

struct StudentGrades{

  @State gardess:SGpojo[] = []

  aboutToAppear(){
    this.GetGrade()
  }

  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(" ")
      Text("您本学期的成绩如下")
      .fontSize(30)
      .fontWeight(FontWeight.Bold)
      Text(" ")
      List({space:80}){
        ForEach(
          this.gardess,
          gardes=>{
            ListItem(){
              Row({space:30}){
                Text(" ")
                Column({space:20}){
                  Text(gardes.cname)
                    .fontColor(Color.Green)
                    .fontSize(20)
                    .fontWeight(FontWeight.Bolder)
                    .fontFamily("楷体")
                 if(gardes.grade<60){
                   Text("状态:不及格")
                     .fontSize(15)
                     .fontColor(Color.Red)
                 }
                  else {
                    Text("状态:及格")
                      .fontSize(15)
                      .fontColor(Color.Green)
                  }
                }
                .justifyContent(FlexAlign.Start)
                .alignItems(HorizontalAlign.Start)
                Blank()
                if(gardes.grade<60){
                  Text(gardes.grade+"")
                    .fontWeight(FontWeight.Bolder)
                    .fontSize(30)
                    .fontColor(Color.Red)
                }
                else {
                  Text(gardes.grade+"")
                    .fontWeight(FontWeight.Bolder)
                    .fontSize(30)
                    .fontColor(Color.Green)
                }
              }
              .width('95%')
              .padding(20)
              .backgroundColor(Color.White)
              .borderRadius(15)
              .shadow({ radius: 6, color: '#1F000000', offsetX: 2, offsetY: 4 })
            }
          }
        )
      }
    }
  }

  GetGrade(){
    GetSTGrade.GSTG()
      .then(resp => {
        console.log("收到数据"+resp);
        if(resp.length === 0){
          promptAction.showToast({
            message: '您还没有选择课程哦~',
            duration: 2000,
            bottom: 50
          });
        }
        this.gardess=resp
      })
  }

}

请求部分

调用后端的接口

xml 复制代码
  <servlet>
    <servlet-name>Getgrade</servlet-name>
    <servlet-class>contaller.Course.Getgrade</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>Getgrade</servlet-name>
    <url-pattern>/Getgrade</url-pattern>
  </servlet-mapping>
typescript 复制代码
import http from '@ohos.net.http';
import SGpojo from '../../pojo/Student/SGpojo';
import IP from '../../IP'

class GetSTGrade{
  baseURL:string = IP.ip
  GSTG():Promise<SGpojo[]>{
    return new Promise((resolve,reject) => {
      let Http = http.createHttp()
      Http.request(
        `${this.baseURL}/Getgrade`,
        {
          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 st = new GetSTGrade()
export default st as GetSTGrade

3、后端部分

由于前后端都是一样的逻辑,所以这里就写一下个人信息的后端

java 复制代码
package contaller.Student;

import MyBatisModel.dao.StudentMapper;
import MyBatisModel.pojo.Students;
import MyBatisModel.utills.MybatisUntills;
import com.google.gson.Gson;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

public class StudentInfo extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json");
        resp.setCharacterEncoding("UTF-8");
        HttpSession session = req.getSession();
        ServletContext con = getServletContext();
        String username = (String) session.getAttribute("username");
        if(username == null){
            username = (String) con.getAttribute("username");
        }

        //Mybatis
        SqlSession sql = MybatisUntills.getSqlSession();
        StudentMapper mapper = sql.getMapper(StudentMapper.class);
        List<Students> student = mapper.getStudent(username);
        sql.close();

        //打包成json并发送至前端
        Gson gson = new Gson();
        String jsonData = gson.toJson(student);
        resp.getWriter().write(jsonData);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}

4、BUG修复

修复了登陆页面请求失败的问题

修复了请求后端失败的问题

相关推荐
魔道不误砍柴功1 小时前
Java 中如何巧妙应用 Function 让方法复用性更强
java·开发语言·python
NiNg_1_2341 小时前
SpringBoot整合SpringSecurity实现密码加密解密、登录认证退出功能
java·spring boot·后端
闲晨1 小时前
C++ 继承:代码传承的魔法棒,开启奇幻编程之旅
java·c语言·开发语言·c++·经验分享
Chrikk2 小时前
Go-性能调优实战案例
开发语言·后端·golang
幼儿园老大*2 小时前
Go的环境搭建以及GoLand安装教程
开发语言·经验分享·后端·golang·go
canyuemanyue2 小时前
go语言连续监控事件并回调处理
开发语言·后端·golang
杜杜的man2 小时前
【go从零单排】go语言中的指针
开发语言·后端·golang
测开小菜鸟2 小时前
使用python向钉钉群聊发送消息
java·python·钉钉
P.H. Infinity3 小时前
【RabbitMQ】04-发送者可靠性
java·rabbitmq·java-rabbitmq
生命几十年3万天3 小时前
java的threadlocal为何内存泄漏
java