JavaWeb教师信息管理系统java+mysql+ssm

上周周末断网。。。。。无聊的时候写的demo,SSH的。

SIMS(Student Information Management System,教师信息管理系统) 包括登录、教师信息录入,修改,删除,查询,数据批量导出等等功能。

开发环境:Eclipse ,jdk1.8

框架:SpringMvc+Hibernate(ORM工具)

前台:JSP

数据库:MySQL

众所周知,Spring配置是相当头疼的,后面尽量用Springboot写一下(当然得先学,省去自己配制还是相当方便的)。本来想把项目源码放到Github上面,

但是还要自己配置,就懒得放了。。。

话不多说,先看下目录结构:

java+mysql+ssm教师信息管理系统

整个项目开发周期2周,为学校做的一个独立的系统;兼容在原来学校的教务系统里面

代码已经上传github,下载地址: https://github.com/21503882/teacher

JavaWeb教师信息管理系统java+mysql+ssm_第1张图片

JavaWeb教师信息管理系统java+mysql+ssm_第2张图片

JavaWeb教师信息管理系统java+mysql+ssm_第3张图片

JavaWeb教师信息管理系统java+mysql+ssm_第4张图片

JavaWeb教师信息管理系统java+mysql+ssm_第5张图片

JavaWeb教师信息管理系统java+mysql+ssm_第6张图片

JavaWeb教师信息管理系统java+mysql+ssm_第7张图片

JavaWeb教师信息管理系统java+mysql+ssm_第8张图片

JavaWeb教师信息管理系统java+mysql+ssm_第9张图片

JavaWeb教师信息管理系统java+mysql+ssm_第10张图片

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.io.FileUtils;
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 org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.mchange.v2.async.StrandedTaskReporting;
import com.sun.accessibility.internal.resources.accessibility;

import cn.itcast.ssm.pojo.Audit;
import cn.itcast.ssm.pojo.FileQueryVo;
import cn.itcast.ssm.pojo.FileUpload;
import cn.itcast.ssm.pojo.QueryVo;
import cn.itcast.ssm.pojo.Releases;
import cn.itcast.ssm.pojo.User;
import cn.itcast.ssm.service.AuditService;
import cn.itcast.ssm.service.FileUploadService;
import cn.itcast.ssm.service.ReleasesService;
import cn.itcast.ssm.service.UserService;
import cn.itcast.ssm.util.DateConverter;
import cn.itcast.ssm.util.Page;
import cn.itcast.ssm.util.Result;


@Controller
@RequestMapping("/fileupload")
public class FileUploadController {

    @Resource(name="FileUploadService")
    private FileUploadService fileUploadService;
    @Resource(name="UserService")
    private UserService userService;
    @Resource(name="ReleasesService")
    private ReleasesService releaseService;
     @Autowired
        private AuditService AuditService;
    
    
    @RequestMapping("/load")
    public String load(){
        return "/fileupload/upload";
    }
    /*
     * 上传文件
     */
     @RequestMapping(value="/upload")     
     public String upload(HttpServletRequest request,
              FileUpload fileUpload,
              @RequestParam("file")MultipartFile file
             ) throws Exception {
        
         //时间转换器
         DateConverter dc = new DateConverter();
         if(!file.isEmpty()) {
             
        System.out.println("传入的上传文件用户账号:"+fileUpload.getUserNo());
        User user = userService.getByNo(fileUpload.getUserNo());
        
        fileUpload.setUser_name(user.getName());
        //传入文件name
        fileUpload.setName(file.getOriginalFilename());
        
        System.out.println("传入的上传文件的说明:"+fileUpload.getInstructions());
        
        
        
        //添加上传时间
        String source = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        fileUpload.setUpload(dc.convert(source));
        
        /*
         * 如果文件不为空,写入上传路径
         */
        
             //上传文件路径
            String path = request.getServletContext().getRealPath("/fileupload/");
            //上传文件名
            String picName = UUID.randomUUID().toString().replaceAll("-", "");
            // 获取文件名
            String oriName = file.getOriginalFilename();
            // 获取文件后缀
            String extName = oriName.substring(oriName.lastIndexOf("."));

            String filename = picName+extName;
            //写入上传文件名,文件名
            fileUpload.setFilename(filename);
            
            File filepath = new File(path,filename);
          //判断路径是否存在,如果不存在就创建一个
            if (!filepath.getParentFile().exists()) { 
                filepath.getParentFile().mkdirs();
            }
            //判断文件是否存在,存在删除
//            if(filepath.exists()){
//                filepath.delete();
//                //得到存在文件的id
//                FileUpload fileUpload2 = fileUploadService.getFileUploadByfilename(filename);
//                Integer id =  fileUpload2.getId();
//                fileUploadService.deleteById(id);
//            }
           
          //将上传文件保存到一个目标文件当中
            
                file.transferTo(new File(path + File.separator + filename));
                
                fileUploadService.saveFileUpload(fileUpload);
                //传入用户名和文件名,插入到消息表中改变上传状态
                releaseService.findReleaseByNoAndFileName(fileUpload.getUserNo(), file.getOriginalFilename());
                
        } 
        
//        //添加上传文件信息
//        fileUploadService.saveFileUpload(fileUpload);
       return "redirect:listFile.action";
        
    }
     
     /*
      * 下载文件
      */
     @RequestMapping(value="/download")
     public ResponseEntity download(HttpServletRequest request,
             Integer id
             )throws Exception {
        //时间转换器
         DateConverter dc = new DateConverter();
         FileUpload fileUpload2 = new FileUpload();
            //添加上传时间
            String source = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
            fileUpload2.setDownload(dc.convert(source));
            fileUpload2.setId(id);
         fileUploadService.update(fileUpload2);
         
         
         FileUpload fileUpload = fileUploadService.getFileUploadById(id);
         String filename = fileUpload.getFilename();
        //下载文件路径
        String path = request.getServletContext().getRealPath("/fileupload/");
        File file = new File(path + File.separator + filename);
        HttpHeaders headers = new HttpHeaders();  
      //下载显示的文件名,解决中文名称乱码问题  
        String downloadFielName = new String(filename.getBytes("UTF-8"),"iso-8859-1");
      //通知浏览器以attachment(下载方式)打开图片
        headers.setContentDispositionFormData("attachment", downloadFielName); 
       
        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        return new ResponseEntity(FileUtils.readFileToByteArray(file),    
                headers, HttpStatus.CREATED);  
     }
    
     /*
      * 批量删除
      */
        @RequestMapping("/deleteBatch")
        @ResponseBody
        public Result deleteBatch(String ids) {
            Result result = new Result();
            
            String id1[] = ids.split(",");
            Integer[] id2 = new Integer[id1.length];
            for(int i=0; i                  id2[i] = Integer.parseInt(id1[i]);
            }
            fileUploadService.deleteBatch(id2);
            result.setMsg("OK");
            return result;
        }
      
        
       
        /*
         * 文件列表
         */
        @RequestMapping(value = "/listFile")
        public String listFile(QueryVo vo,Model model,HttpSession session){
            //通过条件  查询分页对象
            Page page = fileUploadService.selectPageByQueryVo(vo);
            
            
        //    System.out.println("传入的账号为:"+vo.getUserNo());
            

            
            //根据session取出账号,查询管理员的账号姓名
            String no = (String) session.getAttribute("no");
            System.out.println("ttttttttttt"+no);
            User user = userService.getByNo(no);
            model.addAttribute("user",user);
            
            model.addAttribute("page", page);
            model.addAttribute("userNo", vo.getUserNo());
            return "/fileupload/listFile";
        }
        /*
         * 查询文件上传详情
         */
        @RequestMapping("/checkList")
        public ModelAndView  checkList(HttpServletRequest request,HttpServletResponse response
                ,FileQueryVo vo){
            ModelAndView mv = new ModelAndView();

            
            String beginDate = vo.getBeginDate();
            String endDate = vo.getEndDate();
            int uploadStateId=1;
            Map map = new HashMap();
            map.put("beginDate", beginDate);
            map.put("endDate", endDate);
            map.put("uploadStateId", uploadStateId);
          
            //判断传递参数是否全部为空
//            if(vo.getEndDate()!=null&&vo.getEndDate()!=null&&
//                    vo.getFileName()!=null&&vo.getInstructions()!=null){
//                //根据时间段,说明,文件名得到结果集
//                 list = fileUploadService.getFileUploadByVo(vo);        
//            }
            List checkList = releaseService.getReleaseBySendState(map);
            
            mv.addObject("checkList", checkList);
            
            mv.setViewName("fileupload/checkupload");
            return mv;
        }
        /*
         * 根据账号查询账号发送的文件
         */
        @RequestMapping("/listByNo")
        public ModelAndView listByNo(HttpServletRequest request ,
                String userNo){
            ModelAndView mv = new ModelAndView();
            System.out.println("取得的用户号为:"+userNo);
            List list = fileUploadService.getFileUploadByUserNo(userNo);
            
            mv.addObject("list",list);
            mv.setViewName("/fileupload/listByUserNo");
            
            return mv;
        }
        
        @RequestMapping("/checkPage")
        public ModelAndView checkPage(HttpServletRequest request,HttpSession session) {
            String id1 = request.getParameter("id");
            int id = Integer.parseInt(id1);
            FileUpload fileUpload = fileUploadService.getFileUploadById(id);

            ModelAndView mv = new ModelAndView("/fileupload/check");
            mv.addObject("fileUpload", fileUpload);
              //获取当前用户的账号
            String no = (String) session.getAttribute("no");
            User user = userService.getByNo(no);
            mv.addObject("user", user);
            
            List audits = AuditService.list();
            mv.addObject("audits", audits);
            
            return mv;
        }
        @RequestMapping("/check")
        public String check(FileUpload fileUpload) {
            
                fileUploadService.update(fileUpload);     
                
            
                
                Integer auditId = fileUpload.getAuditId();
                 
                if(auditId==2){
                    System.out.println(fileUpload.getUser_name());
                    System.out.println(fileUpload.getUserNo());
                    return "redirect:/release/sendMessage2.action?no="+fileUpload.getUserNo()+"&name="+fileUpload.getUser_name();            
                }
            return "/fileupload/listFile";            
        }  
     
}
 

<%-- 
    Document   : main
    Created on : 2015-11-15, 10:15:22
    Author     : Administrator
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>




    href="${pageContext.request.contextPath}/res/css/add.css"
    type="text/css" media="screen" />


    href="${pageContext.request.contextPath}/res/css/bootstrap.min.css">




    


        

            
                method="post" class="form-horizontal templatemo-login-form-2"
                οnsubmit="return checkForm(this);">
                

                    

                        

教师业务档案管理系统


                    

                

                

                    

                        

                            

                                
                                

                                                                             class="form-control" id="username" name="username"
                                        placeholder="账号/电话号" />
                                

                            

                        


                        


                            

                                
                                

                                                                             class="form-control" id="password" name="password"
                                        placeholder="******" />
                                        
                                

                            

                        

                        

                            

                                
                                

                                    
                                

                            


                        

                        


                            

                                                                     >
                            

                        

                        

                            

                                Cannot
                                    login?

                            

                            

                                ${msg}
                            

                        

                    

                

            

        


    



你可能感兴趣的:(JavaWeb教师信息管理系统java+mysql+ssm)