欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Homework System

程序员文章站 2022-06-02 12:38:30
...

一.项目应用技术
jsp
spring boot
jpa
mysql
二.项目结构
mvc
Homework System

三.项目原型及操作流程
系统登陆界面:Homework System
学生登陆:
Homework System
教师登陆
Homework System
教师操作界面:
Homework System
添加学生作业
Homework System
添加学生信息
Homework System
显示学生提交的所有作业
Homework System
学生操作界面:
学生登陆查看作业
Homework System
提交作业
Homework System

四.部分项目代码
作业提交:

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String id = req.getParameter(“id”);
System.out.println(id);
Homework homework = HomeworkJdbc.showHomeworkDetails(id);//访问数据库
req.setAttribute(“homework”,homework);
req.getRequestDispatcher(“jsp/submitHomework.jsp”).forward(req,resp); //展示内容
}

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

    req.setCharacterEncoding("utf-8");

    StudentHomework studentHomework = new StudentHomework();

    studentHomework.setStudentId(Long.parseLong(req.getParameter("studentId")));
    studentHomework.setHomeworkId(Long.parseLong(req.getParameter("homeworkId")));
    studentHomework.setHomeworkTitle(req.getParameter("title"));
    studentHomework.setHomeworkContent(req.getParameter("content"));
    Date date = new Date();
    studentHomework.setCreateTime(date);

    boolean result = HomeworkJdbc.addStudentHomework(studentHomework);

    req.setAttribute("isOK", result);   //用于判断是否提交成功
    req.setAttribute("type","addStudentHomework");
    req.getRequestDispatcher("jsp/s_return.jsp").forward(req,resp);
}

数据库线程池:
public class DatabasePool {

private static HikariDataSource hikariDataSource;

//双重锁
public static HikariDataSource getHikariDataSource(){

    if(null != hikariDataSource){
        return hikariDataSource;
    }

    synchronized (DatabasePool.class) {
        if (null != hikariDataSource) {
            HikariConfig hikariConfig = new HikariConfig();
            String driverName = "com.mysql.cj.jdbc.Driver";
            hikariConfig.setUsername("root");
            hikariConfig.setPassword("12345678");
            hikariConfig.setDriverClassName(driverName);
            hikariConfig.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/test?serverTimezone=UTC");


            hikariDataSource = new HikariDataSource(hikariConfig);
            return hikariDataSource;
        }
    }
    return null;
}

}