基于JavaSpringMvc+mybatis实现学生信息管理系统_基于mybatis的学生管理系统论文

package com.system.controller;

import com.system.exception.CustomException;
import com.system.po.Userlogin;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * Created by 李杨勇.
 */
@Controller
public class LoginController {

    //登录跳转
    @RequestMapping(value = "/login", method = {RequestMethod.GET})
    public String loginUI() throws Exception {
        return "../../login";
    }

    //登录表单处理
    @RequestMapping(value = "/login", method = {RequestMethod.POST})
    public String login(Userlogin userlogin) throws Exception {

        //Shiro实现登录
        UsernamePasswordToken token = new UsernamePasswordToken(userlogin.getUsername(),
                userlogin.getPassword());
        Subject subject = SecurityUtils.getSubject();

        //如果获取不到用户名就是登录失败,但登录失败的话,会直接抛出异常
        subject.login(token);
        if (subject.hasRole("admin")&userlogin.getRole()==0) {
                return "redirect:/admin/showStudent";
        } else if (subject.hasRole("teacher")&userlogin.getRole()==1) {
                return "redirect:/teacher/showCourse";
        } else if (subject.hasRole("student")&userlogin.getRole()==2) {
                return "redirect:/student/showCourse";
        }else throw new CustomException("请选择正确的身份登陆");


    }

}

文件上传

package com.system.controller;

import com.system.po.FileVO;
import com.system.service.FileService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
import java.util.UUID;

/**
 * 文件上传下载
 */
@Controller
@RequestMapping("/file")
public class FileController {


    @Resource(name = "fileServiceImpl")
    private FileService fileService;

    @RequestMapping("/upload")
    public String  fileUpload(@RequestParam MultipartFile file, FileVO filevo, HttpServletRequest request) throws IOException {
        //上传路径保存设置
        // 把文件写到磁盘
        String fileName = file.getOriginalFilename();
        String[] str = fileName.split("\\.");
        String uuid = UUID.randomUUID().toString().replaceAll("-","");
        String headPath = "E://upload/" + uuid+ "."+str[str.length-1];
        File dest = new File(headPath);
        file.transferTo(dest);
        filevo.setFileID(uuid);
        filevo.setFilePath(headPath);
        filevo.setUserID(null);
        try {
            fileService.save(filevo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "redirect:/admin/showFile";
    }


    @RequestMapping("/downFile")
    public void down(HttpServletRequest request, HttpServletResponse response,String fileID) throws Exception{
        FileVO fileVO = fileService.findById(fileID);
        String fileName = fileVO.getFilePath();
        String[] str = fileName.split("\\.");
        InputStream bis 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值