一个简单的请假系统

本项目是一个简单的spring项目,使用了spring+mybatis,实现数据的增,删,查,和poi的基本使用,导出数据库中的请假信息到excel中等一些基本的功能。有很多不足之处欢迎大家指出,后面慢慢学习会慢慢优化一些地方……

<!DOCTYPE html>
<html>
<head>
    <title>Bootstrap 实例</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdn.bootcss.com/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
    <div class="jumbotron">
        <h1 align="center">个人信息统计系统</h1>
        <p align="center">在这里提交你的信息</p>
    </div>

    <div class="row" align="center">
        <input type="text" class="form-control" style="height:40px;width:450px" placeholder="请假人姓名">
        <div class="panel panel-info" style="width: 450px">
            <div class="panel-heading">
                <h3 class="panel-title" align="center">请假原因</h3>
            </div>
            <textarea class="form-control" rows="5" style="resize: none;height: 100%;width: 100%"></textarea>
        </div>

        <div>
            <button type="button" class="btn btn-success">提交</button>
        </div>
    </div>
</div>

</body>
</html>

package com.leave.controller;

import com.leave.po.Leave;
import com.leave.service.LeaveService;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


/**
 * @ClassName LeaveController
 * @Description
 * @Author martind
 * @Date 2018/8/25 16:05
 **/
@Controller
@RequestMapping(value = "leave")
public class LeaveController {

    @Autowired
    private LeaveService leaveService;
    @RequestMapping(value = "/leavePage")
    public String leaveSystem(){
        return "leave";
    }

    /**
     * 提交表单到该页面,进行数据库的插入操作
     *
     * @m_temp 是一个临时的功能,提交表单后会跳转到一个查询结果的界面,列出所有查询结果
     *
     * @param leave
     * @param model
     * @return
     * @throws IOException
     */
    @RequestMapping(value = "leave")
    public String addLeave(Leave leave, Model model) throws IOException {
        leaveService.addLeave(leave);
        /*List<Leave> leaveList = leaveService.queryAll();
        model.addAttribute("queryAll",leaveList);
        leaveService.leaveOutPut(leaveList,"请假人名单.xlsx");*/

        return "success";
    }


    /**
     * 删除数据库操作
     * 在该操作中先保存数据到*.xlsx中
     *
     * @return 删除成功界面
     * @throws IOException
     */
    @RequestMapping(value = "delete")
    public String deleteLeave() throws IOException {
        List<Leave> leavesList = leaveService.queryAll();
        leaveService.leaveOutPut(leavesList,"deleteBefore.xlsx");
        leaveService.deleteLeave();
        return "deleteSuccess";
    }
    //下载服务器中生成的excel文件
    @RequestMapping("/downLeave")
    public ResponseEntity<byte[]> download() throws IOException {
        leaveService.leaveOutPut(leaveService.queryAll(),"LeaveName.xlsx");
        File file = new File("LeaveName.xlsx");
        byte[] body = null;
        InputStream is = new FileInputStream(file);
        body = new byte[is.available()];
        is.read(body);
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Disposition", "attchement;filename=" + file.getName());
        HttpStatus statusCode = HttpStatus.OK;
        ResponseEntity<byte[]> entity = new ResponseEntity<>(body, headers, statusCode);
        return entity;
    }
//用户管理界面,用于导出数据或者清空数据库
    @RequestMapping("/admin")
    public String adminPage(Model model) throws IOException {
        List<Leave> leaveList = leaveService.queryAll();
        model.addAttribute("leaveList",leaveList);
        return "adminPage";
    }

}

  • 插入数据界面
    插入界面

  • 插入成功界面
    插入成功

  • 管理员管理界面,要手动地址,地址为下图地址输入框中地址,在这里管理员可以下载数据为excel和清空数据库,清空数据库之前会先导出数据备份。

管理界面

  • 导出的数据
    在这里插入图片描述
    最后附上我的代码地址
  • 3
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值