Java毕业设计实战之校园一卡通系统的实现

2022-07-18,,,,

一、项目简述(+需求文档+ppt)

功能:卡管理,卡消费,卡充值,图书借阅,消费,记录,注销等等功能。

二、项目运行

环境配置:

jdk1.8 + tomcat8.5 + mysql + eclispe(intellij idea,eclispe,myeclispe,sts都支持)

项目技术:

jsp + servlet + html+ css + javascript + jquery + ajax 等等

用户管理操作控制层:

/**
 * 用户管理操作
 */
@controller
@requestmapping("/user")
public class usercontroller {
 
    @autowired
    private userservice userservice;
 
    /**
     * 用户添加页面
     * @return
     */
    @getmapping("/add")
    public string create() {
        return "user/add";
    }
 
    /**
     * 用户添加操作
     * @param user
     * @return
     */
    @postmapping("/add")
    @responsebody
    public map<string, object> add(@requestbody user user) {
        if(stringutils.isempty(user.getusername())){
            return mapcontrol.getinstance().error("请填写用户名").getmap();
        }
        if(stringutils.isempty(user.getname())){
            return mapcontrol.getinstance().error("请填写名称").getmap();
        }
        if(stringutils.isempty(user.getuserpwd())){
            return mapcontrol.getinstance().error("请填写密码").getmap();
        }
        int result = userservice.create(user);
        if (result <= 0) {
            return mapcontrol.getinstance().error().getmap();
        }
        return mapcontrol.getinstance().success().getmap();
    }
 
    /**
     * 根据id删除
     * @param id
     * @return
     */
    @postmapping("/delete/{id}")
    @responsebody
    public map<string, object> delete(@pathvariable("id") integer id) {
        int result = userservice.delete(id);
        if (result <= 0) {
            return mapcontrol.getinstance().error().getmap();
        }
        return mapcontrol.getinstance().success().getmap();
    }
 
    //批量删除
    @postmapping("/delete")
    @responsebody
    public map<string, object> delete(string ids) {
        int result = userservice.delete(ids);
        if (result <= 0) {
            return mapcontrol.getinstance().error().getmap();
        }
        return mapcontrol.getinstance().success().getmap();
    }
 
    /**
     * 编辑用户信息操作
     * @param user
     * @return
     */
    @postmapping("/edit")
    @responsebody
    public map<string, object> edit(@requestbody user user) {
        if(stringutils.isempty(user.getusername())){
            return mapcontrol.getinstance().error("请填写用户名").getmap();
        }
        if(stringutils.isempty(user.getname())){
            return mapcontrol.getinstance().error("请填写名称").getmap();
        }
        if(stringutils.isempty(user.getuserpwd())){
            return mapcontrol.getinstance().error("请填写密码").getmap();
        }
        int result = userservice.update(user);
        if (result <= 0) {
            return mapcontrol.getinstance().error().getmap();
        }
        return mapcontrol.getinstance().success().getmap();
    }
 
    /**
     * 根据id查询,跳转修改页面
     * @param id
     * @param modelmap
     * @return
     */
    @getmapping("/edit/{id}")
    public string edit(@pathvariable("id") integer id, modelmap modelmap) {
        user user = userservice.detail(id);
        modelmap.addattribute("user", user);
        return "user/edit";
    }
 
    //查询所有
    @postmapping("/query")
    @responsebody
    public map<string, object> query(@requestbody user user) {
        list<user> list = userservice.query(user);
        integer count = userservice.count(user);
        return mapcontrol.getinstance().success().page(list, count).getmap();
    }
 
    //跳转列表页面
    @getmapping("/list")
    public string list() {
        return "user/list";
    }
 
}

登录控制层:

@controller
public class logincontroller {
 
    @autowired
    private userservice userservice;
    @autowired
    private teacherservice teacherservice;
    @autowired
    private studentservice studentservice;
 
    //跳转登录页面
    @getmapping("/login")
    public string login() {
        return "login";
    }
 
    //登录操作
    @postmapping("/login")
    @responsebody
    public map<string, object> login(string username, string password, string captcha, string type, httpsession session) {
        //判断用户名、密码、用户类型、验证码是否为空
        if (stringutils.isempty(username) || stringutils.isempty(password) || stringutils.isempty(captcha) || stringutils.isempty(type)) {
            return mapcontrol.getinstance().error("用户名或密码不能为空").getmap();
        }
        //获取系统生成的验证码
        string _captcha = (string) session.getattribute("captcha");
        //先判断验证码是否正确
        if (!(captcha.tolowercase()).equals(_captcha.tolowercase())) {
            //验证码错误
            return mapcontrol.getinstance().error("验证码错误").getmap();
        }
 
        //判断用户类型
        if ("1".equals(type)) { //管理员验证登录
            user user = userservice.login(username, md5utils.getmd5(password)); //对密码进行加密处理,因为数据库中存储的是加密后的密码
            if (user != null) {
                session.setattribute("user", user);
                session.setattribute("type", 1);
                return mapcontrol.getinstance().success().add("data", user).getmap();
            } else {
                return mapcontrol.getinstance().error("用户名或密码错误").getmap();
            }
        }
        if ("2".equals(type)) { //老师验证登录
            teacher teacher = teacherservice.login(username, md5utils.getmd5(password));
            if (teacher != null) {
                session.setattribute("user", teacher);
                session.setattribute("type", "2");
                return mapcontrol.getinstance().success().add("data", teacher).getmap();
            } else {
                return mapcontrol.getinstance().error("用户名或密码错误").getmap();
            }
        }
        if ("3".equals(type)) { //学生验证登录
            student student = studentservice.login(username, md5utils.getmd5(password));
            if (student != null) {
                session.setattribute("user", student);
                session.setattribute("type", "3");
                return mapcontrol.getinstance().success().add("data", student).getmap();
            } else {
                return mapcontrol.getinstance().error("用户名或密码错误").getmap();
            }
        }
        return mapcontrol.getinstance().getmap();
    }
 
}

生成验证码:

@controller
@requestmapping("/captcha")
public class captchacontroller {
 
    private char[] codesequence = {'a', '1', 'b', 'c', '2', 'd', '3', 'e', '4', 'f', '5', 'g', '6', 'h', '7', 'i', '8', 'j',
            'k', '9', 'l', '1', 'm', '2', 'n', 'p', '3', 'q', '4', 'r', 's', 't', 'u', 'v', 'w',
            'x', 'y', 'z'};
 
    @requestmapping("/code")
    public void getcode(httpservletresponse response, httpsession session) throws ioexception {
        int width = 80;
        int height = 37;
        random random = new random();
        //设置response头信息
        //禁止缓存
        response.setheader("pragma", "no-cache");
        response.setheader("cache-control", "no-cache");
        response.setdateheader("expires", 0);
 
        //生成缓冲区image类
        bufferedimage image = new bufferedimage(width, height, 1);
        //产生image类的graphics用于绘制操作
        graphics g = image.getgraphics();
        //graphics类的样式
        g.setcolor(this.getcolor(200, 250));
        g.setfont(new font("times new roman", 0, 28));
        g.fillrect(0, 0, width, height);
        //绘制干扰线
        for (int i = 0; i < 40; i++) {
            g.setcolor(this.getcolor(130, 200));
            int x = random.nextint(width);
            int y = random.nextint(height);
            int x1 = random.nextint(12);
            int y1 = random.nextint(12);
            g.drawline(x, y, x + x1, y + y1);
        }
 
        //绘制字符
        string strcode = "";
        for (int i = 0; i < 4; i++) {
            string rand = string.valueof(codesequence[random.nextint(codesequence.length)]);
            strcode = strcode + rand;
            g.setcolor(new color(20 + random.nextint(110), 20 + random.nextint(110), 20 + random.nextint(110)));
            g.drawstring(rand, 13 * i + 6, 28);
        }
        //将字符保存到session中用于前端的验证
        session.setattribute("captcha", strcode.tolowercase());
        g.dispose();
 
        imageio.write(image, "jpeg", response.getoutputstream());
        response.getoutputstream().flush();
    }
 
    public color getcolor(int fc, int bc) {
        random random = new random();
        if (fc > 255)
            fc = 255;
        if (bc > 255)
            bc = 255;
        int r = fc + random.nextint(bc - fc);
        int g = fc + random.nextint(bc - fc);
        int b = fc + random.nextint(bc - fc);
        return new color(r, g, b);
    }
 
}

到此这篇关于java毕业设计实战校园卡通系统的实现的文章就介绍到这了,更多相关java 校园一卡通系统内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

《Java毕业设计实战之校园一卡通系统的实现.doc》

下载本文的Word格式文档,以方便收藏与打印。