溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Java中如何進行校園一卡通系統(tǒng)的實現(xiàn)

發(fā)布時間:2022-01-27 09:09:56 來源:億速云 閱讀:124 作者:kk 欄目:開發(fā)技術(shù)

這篇文章的內(nèi)容主要圍繞Java中如何進行校園一卡通系統(tǒng)的實現(xiàn)進行講述,文章內(nèi)容清晰易懂,條理清晰,非常適合新手學(xué)習(xí),值得大家去閱讀。感興趣的朋友可以跟隨小編一起閱讀吧。希望大家通過這篇文章有所收獲!

一、項目簡述(+需求文檔+PPT)

功能:卡管理,卡消費,卡充值,圖書借閱,消費,記錄,注銷等等功能。

二、項目運行

環(huán)境配置:

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

項目技術(shù):

JSP + Servlet + html+ css + JavaScript + JQuery + Ajax 等等

Java中如何進行校園一卡通系統(tǒng)的實現(xiàn)

Java中如何進行校園一卡通系統(tǒng)的實現(xiàn)

Java中如何進行校園一卡通系統(tǒng)的實現(xiàn)

Java中如何進行校園一卡通系統(tǒng)的實現(xiàn)

Java中如何進行校園一卡通系統(tǒng)的實現(xiàn)

用戶管理操作控制層:

/**
 * 用戶管理操作
 */
@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("請?zhí)顚懹脩裘?quot;).getMap();
        }
        if(StringUtils.isEmpty(user.getName())){
            return MapControl.getInstance().error("請?zhí)顚懨Q").getMap();
        }
        if(StringUtils.isEmpty(user.getUserPwd())){
            return MapControl.getInstance().error("請?zhí)顚懨艽a").getMap();
        }
        int result = userService.create(user);
        if (result <= 0) {
            return MapControl.getInstance().error().getMap();
        }
        return MapControl.getInstance().success().getMap();
    }
 
    /**
     * 根據(jù)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("請?zhí)顚懹脩裘?quot;).getMap();
        }
        if(StringUtils.isEmpty(user.getName())){
            return MapControl.getInstance().error("請?zhí)顚懨Q").getMap();
        }
        if(StringUtils.isEmpty(user.getUserPwd())){
            return MapControl.getInstance().error("請?zhí)顚懨艽a").getMap();
        }
        int result = userService.update(user);
        if (result <= 0) {
            return MapControl.getInstance().error().getMap();
        }
        return MapControl.getInstance().success().getMap();
    }
 
    /**
     * 根據(jù)id查詢,跳轉(zhuǎn)修改頁面
     * @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();
    }
 
    //跳轉(zhuǎn)列表頁面
    @GetMapping("/list")
    public String list() {
        return "user/list";
    }
 
}

登錄控制層:

@Controller
public class LoginController {
 
    @Autowired
    private UserService userService;
    @Autowired
    private TeacherService teacherService;
    @Autowired
    private StudentService studentService;
 
    //跳轉(zhuǎn)登錄頁面
    @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();
        }
        //獲取系統(tǒng)生成的驗證碼
        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)); //對密碼進行加密處理,因為數(shù)據(jù)庫中存儲的是加密后的密碼
            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)) { //學(xué)生驗證登錄
            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();
        //設(shè)置response頭信息
        //禁止緩存
        response.setHeader("Pragma", "No-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);
 
        //生成緩沖區(qū)image類
        BufferedImage image = new BufferedImage(width, height, 1);
        //產(chǎn)生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基本數(shù)據(jù)類型有哪些

Java的基本數(shù)據(jù)類型分為:1、整數(shù)類型,用來表示整數(shù)的數(shù)據(jù)類型。2、浮點類型,用來表示小數(shù)的數(shù)據(jù)類型。3、字符類型,字符類型的關(guān)鍵字是“char”。4、布爾類型,是表示邏輯值的基本數(shù)據(jù)類型。

感謝你的閱讀,相信你對“Java中如何進行校園一卡通系統(tǒng)的實現(xiàn)”這一問題有一定的了解,快去動手實踐吧,如果想了解更多相關(guān)知識點,可以關(guān)注億速云網(wǎng)站!小編會繼續(xù)為大家?guī)砀玫奈恼拢?/p>

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI