基于javaweb和mysql的springboot教务管理系统(java+thymeleaf+html+spring+springboot+mysql+layui+maven)

私信源码获取及调试交流

私信源码获取及调试交流

运行环境

Java≥8、MySQL≥5.7

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

基于javaweb的SpringBoot教务管理系统(java+thymeleaf+html+spring+springboot+mysql+layui+maven)

一、项目简述

功能包括: 三角色教师 管理员,学生教务管理系统,包括院系管理,课题综合管理,信息管理,以及差旅管理,学生选题等等。

二、项目运行 环境配置:

Jdk1.8 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)

项目技术:

JSP +Spring + SpringBoot + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等

        XSSFCellStyle style1 = workBook.createCellStyle();
        XSSFFont f = workBook.createFont();
        f.setFontHeightInPoints((short) 18);//字号
        f.setFontName("仿宋_GB2312");//设置字体
        f.setBold(true);//加粗
        style1.setFont(f);
        style1.setAlignment(HorizontalAlignment.CENTER);//左右居中
        style1.setVerticalAlignment(VerticalAlignment.CENTER);//上下居中
        style1.setBorderBottom(BorderStyle.THIN);//下边框
        style1.setBorderLeft(BorderStyle.THIN);//左边框
        style1.setBorderTop(BorderStyle.THIN);//上边框
        style1.setBorderRight(BorderStyle.THIN);//右边框
        row = sheet.getRow(0);
        XSSFCell cell = row.getCell(0);
        cell.setCellStyle(style1); //获取指定行并赋值样式

        //设置标题单元格样式
        XSSFCellStyle style2 = workBook.createCellStyle();
        f = workBook.createFont();
        f.setFontHeightInPoints((short) 12);//字号
        f.setFontName("仿宋_GB2312");//设置字体
        f.setBold(true);//加粗
        style2.setFont(f);
        style2.setAlignment(HorizontalAlignment.CENTER);//左右居中
        style2.setVerticalAlignment(VerticalAlignment.CENTER);//上下居中
        style2.setAlignment(HorizontalAlignment.CENTER);
        style2.setBorderBottom(BorderStyle.THIN);
        style2.setBorderLeft(BorderStyle.THIN);
        style2.setBorderRight(BorderStyle.THIN);
        style2.setBorderTop(BorderStyle.THIN);

        // 创建行,标题行
        row = sheet.createRow(1);
        cell = row.createCell(0);
        cell.setCellValue("部 门");
        cell.setCellStyle(style2); //获取指定行并赋值样式

        region = new CellRangeAddress(1, 1, (short) 1, (short) 3);
        sheet.addMergedRegion(region);
        fun8(region, sheet, workBook);
        cell = row.createCell(1);
        cell.setCellValue(teacher.getInstituteName());
        cell.setCellStyle(style2); //获取指定行并赋值样式

        cell = row.createCell(4);
        cell.setCellValue("填报人");
        cell.setCellStyle(style2); //获取指定行并赋值样式

        region = new CellRangeAddress(1, 1, (short) 4, (short) 5);
        sheet.addMergedRegion(region);
        fun8(region, sheet, workBook);
                        for (XWPFTableCell cell : cells) {
                            paras = cell.getParagraphs();
                            for (XWPFParagraph para : paras) {
                                this.replaceInPara(para, params, doc);
                            }
                        }
                    }
                } else {
                    insertTable(table, tableList);  //插入数据
                }
            }
        }
    }

    /**
     * 正则匹配字符串
     *
     * @param str
     * @return
     */
    private Matcher matcher(String str) {
        Pattern pattern = Pattern.compile("\\$\\{(.+?)\\}", Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(str);
        return matcher;
    }

    /**
     * 根据图片类型,取得对应的图片类型代码
     *
     * @param picType
     * @return int
     */
    private static int getPictureType(String picType) {
        int res = XWPFDocument.PICTURE_TYPE_PICT;
        if (picType != null) {
            if (picType.equalsIgnoreCase("png")) {
                res = XWPFDocument.PICTURE_TYPE_PNG;
            } else if (picType.equalsIgnoreCase("dib")) {
                res = XWPFDocument.PICTURE_TYPE_DIB;
            } else if (picType.equalsIgnoreCase("emf")) {
                res = XWPFDocument.PICTURE_TYPE_EMF;
            } else if (picType.equalsIgnoreCase("jpg") || picType.equalsIgnoreCase("jpeg")) {
                res = XWPFDocument.PICTURE_TYPE_JPEG;
            } else if (picType.equalsIgnoreCase("wmf")) {
                res = XWPFDocument.PICTURE_TYPE_WMF;
            }
        }
        return res;
    }

    /**
    @ResponseBody
    @PostMapping("/teacher")
    public Msg addTeacher(
            @RequestBody @Validated(Add.class) TeacherWithBLOBs teacher,
            @ModelAttribute("id_institute") long id_institute
    ) throws MyException {
        return Msg.sqlChange((int) teacherService.addTeacher(teacher, id_institute));
    }

    @ResponseBody
    @PutMapping("/teacher")
    public Msg updateTeacher(
            @RequestBody @Validated({Update.class}) TeacherWithBLOBs teacher,
            @ModelAttribute("id_institute") long id_institute
    ) throws MyException {
        return Msg.sqlChange((int) teacherService.updateTeacher(teacher, id_institute));
    }

    //教师批量教师导入
    @PostMapping("/TeacherExcel")
    @ResponseBody
    public Msg addTeacherExcel(
            @RequestParam("excel") MultipartFile excelFile,
            @ModelAttribute("id_institute") long id_institute
    ) throws MyException, IOException {
        return excelService.teacherExcelImport(excelFile, id_institute);
    }

    //教师批量导入模板
    @GetMapping("/TeacherExcelDemo")
    public void getTeacherExcelDemo(HttpServletResponse response) throws IOException {
        excelService.teacherExcelDownload(response);
    }

//    学生管理

    @GetMapping("/StudentManagement")
    public String student() {
        }
        //遍历表格插入数据
        List<XWPFTableRow> rows = table.getRows();
        int length = table.getRows().size();
        for (int i = 1; i < length - 1; i++) {
            XWPFTableRow newRow = table.getRow(i);
            List<XWPFTableCell> cells = newRow.getTableCells();
            for (int j = 0; j < cells.size(); j++) {
                XWPFTableCell cell = cells.get(j);
                String s = tableList.get(i - 1)[j];
                cell.setText(s);
            }
        }
    }

    /**
     * 替换表格里面的变量
     *
     * @param doc    要替换的文档
     * @param params 参数
     */
    private void replaceInTable(XWPFDocument doc, Map<String, Object> params, List<String[]> tableList) {
        Iterator<XWPFTable> iterator = doc.getTablesIterator();
        XWPFTable table;
        List<XWPFTableRow> rows;
        List<XWPFTableCell> cells;
        List<XWPFParagraph> paras;
        while (iterator.hasNext()) {
            table = iterator.next();
            if (table.getRows().size() > 1) {
                //判断表格是需要替换还是需要插入,判断逻辑有$为替换,表格无$为插入
                if (this.matcher(table.getText()).find()) {
                    rows = table.getRows();
                    for (XWPFTableRow row : rows) {
                        cells = row.getTableCells();
                        for (XWPFTableCell cell : cells) {
                            paras = cell.getParagraphs();
                            for (XWPFParagraph para : paras) {
                                this.replaceInPara(para, params, doc);
                            }

        //创建工作簿
        XSSFWorkbook wb = new XSSFWorkbook();
        //创建一个sheet
        XSSFSheet sheet = wb.createSheet();

        // 创建单元格样式
        XSSFCellStyle style1 = wb.createCellStyle();
        style1.setAlignment(HorizontalAlignment.CENTER); //文字水平居中
        style1.setVerticalAlignment(VerticalAlignment.CENTER);//文字垂直居中
        style1.setBorderBottom(BorderStyle.THIN); //底边框加黑
        style1.setBorderLeft(BorderStyle.THIN);  //左边框加黑
        style1.setBorderRight(BorderStyle.THIN); // 有边框加黑
        style1.setBorderTop(BorderStyle.THIN); //上边框加黑

        XSSFFont font = wb.createFont();
        font.setFontName("宋体");
        font.setBold(true);//粗体显示
        font.setFontHeightInPoints((short) 16);

        style1.setFont(font);

        XSSFCellStyle style = wb.createCellStyle();
        style.setAlignment(HorizontalAlignment.CENTER); //文字水平居中
        style.setVerticalAlignment(VerticalAlignment.CENTER);//文字垂直居中
        style.setBorderBottom(BorderStyle.THIN); //底边框加黑
        style.setBorderLeft(BorderStyle.THIN);  //左边框加黑
        style.setBorderRight(BorderStyle.THIN); // 有边框加黑
        style.setBorderTop(BorderStyle.THIN); //上边框加黑
        XSSFFont font1 = wb.createFont();
        font1.setFontName("宋体");
        font1.setFontHeightInPoints((short) 10.5);//设置字体大小
        style.setFont(font1);

//        为单元格添加背景样式
        for (int i = 1;i < (students!=null?students.size():0) + 2; i++) {
            Row row = sheet.createRow(i); //创建行
            for (int j = 0; j < 8; j++) {//需要6列
                row.createCell(j).setCellStyle(style);
            }
        style3.setBorderTop(BorderStyle.THIN);//上边框

        //创建表格主体
        //获取教学任务
        String teachingTask = debriefing.getTeachingtask();
        String[] aa = teachingTask.split("/");

        row = sheet.createRow(2);
        region = new CellRangeAddress(2, 2 + aa.length, (short) 0, (short) 0);
        sheet.addMergedRegion(region);
        fun8(region, sheet, workBook);
        cell = row.createCell(0);
        cell.setCellValue("教学任务");
        cell.setCellStyle(style3); //赋值样式

        cell = row.createCell(1);
        cell.setCellValue("序号");
        cell.setCellStyle(style2);
        region = new CellRangeAddress(2, 2, (short) 2, (short) 6);
        sheet.addMergedRegion(region);
        fun8(region, sheet, workBook);
        cell = row.createCell(2);
        cell.setCellValue("具体内容");
        cell.setCellStyle(style2);
        row.setHeightInPoints(30);

        //填充教学任务
        int index = 3;
        for (int j = 0; j < aa.length; index++, j++) {
            row = sheet.createRow(index);
            cell = row.createCell(1);
            cell.setCellValue(j + 1);
            cell.setCellStyle(style3);
            cell = row.createCell(0);
            cell.setCellStyle(style3);
            region = new CellRangeAddress(index, index, (short) 2, (short) 6);
            sheet.addMergedRegion(region);
            fun8(region, sheet, workBook);
            cell = row.createCell(2);
            cell.setCellValue(aa[j]);
            cell.setCellStyle(style3);
            row.setHeightInPoints(30);
        }

        //获取科研及成果
        String achievementsInScientificResearch = debriefing.getAchievementsinscientificresearch();
    @ExceptionHandler
    public String exception(MaxUploadSizeExceededException e) {
        log.error("{}","文件过大");
        return "文件过大";
    }

    @ExceptionHandler
    public void exception(Exception e) throws IOException {
        log.error("{}",e);
        response.setStatus(404);
        response.sendRedirect("/error/404");
    }

}

public class LoginInterceptor extends HandlerInterceptorAdapter {

    private static final Logger log = LoggerFactory.getLogger(WebExceptionHandler.class);

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        String url = request.getRequestURI();
        return JSONObject.toJSONString(map);
    }

    @GetMapping("/Classindex")
    public String fun14(ModelMap modelMap, HttpSession httpSession) {
        Teacher teacher = (Teacher) httpSession.getAttribute("teacherInfo");
        String institute_name = teacher.getInstituteName();//学院名字
        List<Specialty> specialties = staticService.selectSpercialtyByall(institute_name);
        List<Class> classes = staticService.selectClassByall(institute_name);

        modelMap.addAttribute("Spercialtys", specialties);
        modelMap.addAttribute("Classs", classes);
        return "teacher/graduation/classxq/Classxq";
    }

    // 根据 专业,班级 等信息查询学生选题情况
    @PostMapping("/SelectAll")
    @ResponseBody
    public List<Static_student> fun15(String Spercialty, String csa) {
        List<Static_student> static_students = staticService.select_studentXT_all(null, null, null, Spercialty, null, csa);
        Collections.sort(static_students, new Comparator<Static_student>() {
            @Override
            public int compare(Static_student o1, Static_student o2) {
                return (Integer.valueOf(o1.getStuNum()) - Integer.valueOf(o2.getStuNum()));
            }
        });

        for (int i = 0; i < static_students.size(); i++) {
            if (static_students.get(i).getStuselectFlag().equals("0")) static_students.get(i).setStuselectFlag("未选题");
            if (static_students.get(i).getStuselectFlag().equals("1")) static_students.get(i).setStuselectFlag("选题待审核");
            if (static_students.get(i).getStuselectFlag().equals("2")) static_students.get(i).setStuselectFlag("选题未通过");
            if (static_students.get(i).getStuselectFlag().equals("3")) static_students.get(i).setStuselectFlag("选题通过");
        }
        return static_students;
    }

    @GetMapping("/czstudentpwd")
    public String fun16() {
        return "teacher/graduation/reStudentpwd";
    }

    // 通过学生的 id,名字,学号查询学生
    @GetMapping("/selectStudent")
    public String getStudent(String username, ModelMap modelMap) {
    Admin selectByName(String name);

    Sadmin selectSadminByName(String name);

    int updatePwdByUserName(String name,String pwd);

    List selectAdmins(Long offset);

    /**
     *  ----------
     */

    int updateSadminPwdByUserName(String name,String pwd);

    int addAdmin(Admin admin);

    int delAdmin(Admin admin);

    int updateAdmin(Admin admin);

    // 学生的增删改查
    public int add_student(String userName, String stuNum, Long id_class, String name, String gender, String pwd);

    public int delete_student(Long student_id);

    public int update_student(Long student_id, String userName, String stuNum, Long id_class, String name, String gender, String pwd);

    public List<Static_student> select_student(Long institute_id, Long specialty_id, Long class_id, Long student_id, String name);

    // 通过学生id 或者 课题id 查 课题的选择 情况
    public List<Subjectselected> select_Projectselected(Long student_id, Long project_id);

    // 已发布课题查询
    public List<Subject> select_ProjectXQ(Long institute_id, Long section_id, String name);
    // 班级的增删改查
    int add_class(Long specialty_id, String class_name);

    int delete_class(Long class_id);

    int update_class(Long class_id, Long specialty_id, String class_name);

    List<Class> select_class(Long institute_id, Long section_id, Long specialty_id, Long class_id, String class_name);// 根据学院id 或者 教研室id  或者 专业方向_id 查询所有班级

    // 根据学院生成 以专业为前提 课题一览表
    List<Project> select_project(Long institute_id, Long section_id, String section_name);
    public Msg businessData(
            @RequestParam("year") String year,
            @RequestParam("trem") String trem
    ) {
        Teacher teacher = (Teacher) request.getSession().getAttribute("teacherInfo");
        return teacherService.getBusiness(teacher.getId(), year, trem)
                .add("teacher", teacher);
    }

    @PostMapping("/business")
    @ResponseBody
    public Msg saveBusiness(
            @RequestBody BusinessDTO businessDTO
    ) {
        Teacher teacher = (Teacher) request.getSession().getAttribute("teacherInfo");
        return Msg.sqlChange((int) teacherService.saveBusiness(businessDTO, teacher));
    }

    //年度述职
    @PostMapping("/upload_year_debriefing")
    @ResponseBody
    public Msg fun10(String year, String teachingTask, String scientificResearch,
                     String otherWork, String winAward, String summary, HttpSession httpSession) {
        Teacher teacher = (Teacher) httpSession.getAttribute("teacherInfo");
        DebriefingYearWithBLOBs debriefingYear = new DebriefingYearWithBLOBs();
        debriefingYear.setIdTeacher(teacher.getId());
        debriefingYear.setYear(Long.parseLong(year));
        debriefingYear.setTeachingtask(teachingTask);
        debriefingYear.setAchievementsinscientificresearch(scientificResearch);
        debriefingYear.setOtherwork(otherWork);
        debriefingYear.setWinaward(winAward);
        debriefingYear.setSummary(summary);
        Long flag = teacherService.selectYearDebriefingFlag(teacher.getId(), Long.parseLong(year));
        if (flag == 1) {
            teacherService.updateYearDebriefing(debriefingYear);
        } else {
            int i = teacherService.insertYearDebriefing(debriefingYear);
        }

        return Msg.success();
    }
        Project project = null;
        if (project_id != null && !project_id.equals("null")) {
            Long projectID = Long.valueOf(project_id);
            project = staticService.selectProjectbyid(projectID);
        } else {
            if (project_Name != null && !project_Name.equals("null")) {
                project = staticService.selectProjectbyName(project_Name);
            }
        }

        if (project != null) { // 如果课题存在 则开始传送
            String filePath = project.getFilepath();
            File file = new File(filePath);
            if (!file.exists()) {
                file.mkdirs();
            }
            System.out.println();
            String fileName = file.getName();
            System.out.println(fileName + "****");
//            HttpHeaders headers = new HttpHeaders();
//            headers.setContentLength(100000);
//
//            headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
//            String encodeFilename = URLEncoder.encode(fileName, StandardCharsets.UTF_8.toString());
//            headers.setContentDispositionFormData("attachment", encodeFilename);

            response.setCharacterEncoding("utf-8");
            response.setContentType("application/force-download");
            String outputName = fileName;
            String encodeFilename = URLEncoder.encode(outputName, StandardCharsets.UTF_8.toString());
            response.setHeader("Content-disposition", "attachment; filename=" + encodeFilename );

            byte[] buffer = new byte[1024];
            FileInputStream fis = null;
            BufferedInputStream bis = null;
            try {
                fis = new FileInputStream(file);
                bis = new BufferedInputStream(fis);
                OutputStream os = response.getOutputStream();
                int i = bis.read(buffer);
                while (i != -1) {
                    os.write(buffer, 0, i);
                    i = bis.read(buffer);
                }if (os != null){
                    os.close();
                }
            } catch (Exception e) {
                    response.sendRedirect(contextPath + "/student/login");
                }
            }
        }else {
            response.sendRedirect(contextPath + "/login");
        }

        return false;
    }
}

@Controller
public class LoginController {

    private static final Logger LOGGER = LoggerFactory.getLogger(LoginController.class);

    @Autowired
    AdminService adminService;

    @GetMapping("/cs")
    public String cs() {
        return "cs";
    }

    @GetMapping("/login")
    public String login() {
        return "login";
    }

        cell = row.createCell(4);
        cell.setCellValue("填报人");
        cell.setCellStyle(style2); //获取指定行并赋值样式

        region = new CellRangeAddress(1, 1, (short) 4, (short) 5);
        sheet.addMergedRegion(region);
        fun8(region, sheet, workBook);
        cell = row.createCell(6);
        cell.setCellValue(teacher.getName());
        cell.setCellStyle(style2); //获取指定行并赋值样式
        row.setHeightInPoints(30);

        //设置单元格样式
        XSSFCellStyle style3 = workBook.createCellStyle();
        f = workBook.createFont();
        f.setFontHeightInPoints((short) 12);//字号
        f.setFontName("仿宋_GB2312");//设置字体
        style3.setFont(f);
        style3.setWrapText(true);
        style3.setAlignment(HorizontalAlignment.CENTER);//左右居中
        style3.setVerticalAlignment(VerticalAlignment.CENTER);//上下居中
        style3.setBorderBottom(BorderStyle.THIN);//下边框
        style3.setBorderLeft(BorderStyle.THIN);//左边框
        style3.setBorderRight(BorderStyle.THIN);//右边框
        style3.setBorderTop(BorderStyle.THIN);//上边框

        //创建表格主体
        //获取教学任务
        String teachingTask = debriefingYear.getTeachingtask();
        String[] aa = teachingTask.split("/");

        row = sheet.createRow(2);
        region = new CellRangeAddress(2, 2 + aa.length, (short) 0, (short) 0);
        sheet.addMergedRegion(region);
        fun8(region, sheet, workBook);
        cell = row.createCell(0);
        cell.setCellValue("教学任务");
        cell.setCellStyle(style3); //赋值样式

        cell = row.createCell(1);
        cell.setCellValue("序号");
        cell.setCellStyle(style2);
        region = new CellRangeAddress(2, 2, (short) 2, (short) 6);
        sheet.addMergedRegion(region);
        fun8(region, sheet, workBook);
        cell = row.createCell(2);
        cell.setCellValue("具体内容");
        cell.setCellStyle(style2);
            cell = row.createCell(2);
            cell.setCellValue(aa[j]);
            cell.setCellStyle(style3);
            row.setHeightInPoints(30);

        }

        String summary = debriefingYear.getSummary();
        row = sheet.createRow(index);
        cell = row.createCell(0);
        cell.setCellValue("工作亮点小结(不超过100字)");
        cell.setCellStyle(style3);
        region = new CellRangeAddress(index, index, (short) 1, (short) 6);
        sheet.addMergedRegion(region);
        fun8(region, sheet, workBook);
        cell = row.createCell(1);
        cell.setCellValue(summary);
        cell.setCellStyle(style3);
        row.setHeightInPoints(150);

        response.setCharacterEncoding("utf-8");
        response.setContentType("application/msexcel");
        OutputStream output = response.getOutputStream();
        String outputName = teacher.getInstituteName() + year + "年度述职表";
        String encodeFilename = URLEncoder.encode(outputName, StandardCharsets.UTF_8.toString());

        response.setHeader("Content-disposition", "attachment; filename=" + encodeFilename + ".xlsx");

        // 写excel需要使用输出流
        BufferedOutputStream outputStream = null;
        outputStream = new BufferedOutputStream(output);
        workBook.write(outputStream);
        outputStream.flush();
        outputStream.close();
        workBook.close();
    }

    //设置合并单元格边框
    public void fun8(CellRangeAddress region, XSSFSheet sheet, XSSFWorkbook workBook) {

        BorderStyle borderStyle = BorderStyle.THIN;

        RegionUtil.setBorderBottom(borderStyle, region, sheet); // 下边框
        RegionUtil.setBorderLeft(borderStyle, region, sheet); // 左边框
        RegionUtil.setBorderRight(borderStyle, region, sheet); // 右边框
        RegionUtil.setBorderTop(borderStyle, region, sheet); // 上边框
    }

    @Autowired
    HttpServletRequest request;

    @Autowired
    HttpServletResponse response;

    @Override
    public Msg login(String name, String pwd , HttpSession httpSession) {

        Sadmin sadmin = selectSadminByName(name);
        if(sadmin!=null){
            //验证密码是否与数据库中的相同
            if(sadmin.getPwd().equals(pwd)){
                User user = new User();
                //-1表示为超管
                user.setId(-1L);
                user.setRole("sadmin");
                user.setUserName(sadmin.getName());
                //生成Token 存到 Cookie
                Cookie cookie = new Cookie("token",TokenUtil.createToken(
                        user
                ));
                //该Cookie无法被js读取
                cookie.setHttpOnly(true);
                cookie.setPath("/");
                response.addCookie(cookie);
                return Msg.success();
            }
            return Msg.error("密码错误");
        }else {
            Admin admin = selectByName(name);
            if(admin == null){
                return Msg.error("账号不存在");
            }else {
                if(admin != null && admin.getPwd().equals(pwd)){
                    User user = new User();
                    user.setId(admin.getId());
                    user.setRole("admin");
                    user.setUserName(admin.getName());
                    Cookie cookie = new Cookie("token",TokenUtil.createToken(
                            user
                    ));
                    cookie.setPath("/");
                    cookie.setHttpOnly(true);
                    response.addCookie(cookie);
                    return Msg.success();//账号密码正确
                }
                return Msg.error("密码错误");
            }

        }

        // 创建单元格样式
        XSSFCellStyle style1 = wb.createCellStyle();
        style1.setAlignment(HorizontalAlignment.CENTER); //文字水平居中
        style1.setVerticalAlignment(VerticalAlignment.CENTER);//文字垂直居中
        style1.setBorderBottom(BorderStyle.THIN); //底边框加黑
        style1.setBorderLeft(BorderStyle.THIN);  //左边框加黑
        style1.setBorderRight(BorderStyle.THIN); // 有边框加黑
        style1.setBorderTop(BorderStyle.THIN); //上边框加黑

        XSSFFont font = wb.createFont();
        font.setFontName("宋体");
        font.setBold(true);//粗体显示
        font.setFontHeightInPoints((short) 16);

        style1.setFont(font);

        XSSFCellStyle style = wb.createCellStyle();
        style.setAlignment(HorizontalAlignment.CENTER); //文字水平居中
        style.setVerticalAlignment(VerticalAlignment.CENTER);//文字垂直居中
        style.setBorderBottom(BorderStyle.THIN); //底边框加黑
        style.setBorderLeft(BorderStyle.THIN);  //左边框加黑
        style.setBorderRight(BorderStyle.THIN); // 有边框加黑
        style.setBorderTop(BorderStyle.THIN); //上边框加黑
        XSSFFont font1 = wb.createFont();
        font1.setFontName("宋体");
        font1.setFontHeightInPoints((short) 12);//设置字体大小
        style.setFont(font1);

//        为单元格添加背景样式
        for (int i = 1; i < projects.size() + 2; i++) { //需要6行表格
            Row row = sheet.createRow(i); //创建行
            for (int j = 0; j < 8; j++) {//需要6列
                row.createCell(j).setCellStyle(style);
            }
        }

        //设置头部单元格样式
        style1 = wb.createCellStyle();
        XSSFFont f = wb.createFont();
        f.setFontHeightInPoints((short) 18);//字号
        f.setFontName("仿宋_GB2312");//设置字体
        f.setBold(true);//加粗
        style1.setFont(f);
        style1.setAlignment(HorizontalAlignment.CENTER);//左右居中
        style1.setVerticalAlignment(VerticalAlignment.CENTER);//上下居中
        style1.setBorderBottom(BorderStyle.THIN);//下边框
        style1.setBorderBottom(BorderStyle.THIN);//下边框
        style1.setBorderLeft(BorderStyle.THIN);//左边框

        //填充教学任务
        int index = 3;
        for (int j = 0; j < aa.length; index++, j++) {
            row = sheet.createRow(index);
            cell = row.createCell(1);
            cell.setCellValue(j + 1);
            cell.setCellStyle(style3);
            cell = row.createCell(0);
            cell.setCellStyle(style3);
            region = new CellRangeAddress(index, index, (short) 2, (short) 6);
            sheet.addMergedRegion(region);
            fun8(region, sheet, workBook);
            cell = row.createCell(2);
            cell.setCellValue(aa[j]);
            cell.setCellStyle(style3);
            row.setHeightInPoints(30);
        }

        //获取科研及成果
        String achievementsInScientificResearch = debriefingYear.getAchievementsinscientificresearch();
        aa = achievementsInScientificResearch.split("/");

        row = sheet.createRow(index);
        region = new CellRangeAddress(index, index + aa.length - 1, (short) 0, (short) 0);
        sheet.addMergedRegion(region);
        fun8(region, sheet, workBook);

        //填充科研及成果
        for (int j = 0; j < aa.length; index++, j++) {
            row = sheet.createRow(index);
            cell = row.createCell(1);
            cell.setCellValue(j + 1);
            cell.setCellStyle(style3);
            cell = row.createCell(0);
            cell.setCellValue("科研及成果");
            cell.setCellStyle(style3);
            region = new CellRangeAddress(index, index, (short) 2, (short) 6);
            sheet.addMergedRegion(region);
            fun8(region, sheet, workBook);
            cell = row.createCell(2);
            cell.setCellValue(aa[j]);
            cell.setCellStyle(style3);
            row.setHeightInPoints(30);
        }

        //获取其它方面工作
        String otherWork = debriefingYear.getOtherwork();
        aa = otherWork.split("/");

        region = new CellRangeAddress(index, index + aa.length - 1, (short) 0, (short) 0);
                .head(subjectExcelUtil.head())
                .sheet("一览表")
                // table的时候 传入class 并且设置needHead =false
                .table()
                .head(SubjectExcel.class)
                .needHead(Boolean.FALSE)//是否写入头
                .doWrite(subjectExcelUtil.getSubjectExcelList(id_institute));//写入数据
    }
}

@Service
public class TopicsServiceImpl implements TopicsService {

    @Autowired
    private MyClassMapper classMapper;

    @Autowired
    private StudentMapper studentMapper;

    @Autowired
    private SubjectselectedMapper subjectselectedMapper;

    @Autowired
    private SubjectMapper subjectMapper;

    @Autowired
    private HttpServletRequest request;

    /**
     * 查看班级选报信息
     */
    @Override
    public List<classinfo> classinfo(Long id) {

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐