Java兼职平台系统如何实现

发布时间:2022-03-17 08:56:37 作者:iii
来源:亿速云 阅读:155

本篇内容介绍了“Java兼职平台系统如何实现”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

一、项目运行

环境配置:

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

项目技术:

HTML +Springboot+ SpringMVC + MyBatis + ThymeLeaf + JavaScript + JQuery + Ajax + maven等等.

二、效果图

Java兼职平台系统如何实现

Java兼职平台系统如何实现

Java兼职平台系统如何实现

Java兼职平台系统如何实现

Java兼职平台系统如何实现

Java兼职平台系统如何实现

Java兼职平台系统如何实现

三、核心代码

登录控制层

 
 /**
 * @Author yy
 * @Description 登录
 * @Date 2022.2.17
 */
 
 
public class LoginController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        JSONObject jsonObject = new JSONObject();
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        resp.setCharacterEncoding("UTF-8");
 
        HttpSession session = req.getSession();
        if (StringUtils.isBlank(username) || StringUtils.isBlank(password)) {
            jsonObject.put("code", 2000);
            jsonObject.put("flag", "fail");
            jsonObject.put("user", null);
            jsonObject.put("msg", "usernameOrPasswordIsBank");//用户名密码不能为空
            resp.getWriter().print(jsonObject);
            return;
        }
        password = MyMD5Util.encrypt(password);
        System.out.println(password);
        BusinessUserVO businessUserVO = new BusinessUserVO();
        businessUserVO.setUsername(username);
        businessUserVO.setPassword(password);
        StudentUserVO studentUserVO = new StudentUserVO();
        studentUserVO.setUsername(username);
        studentUserVO.setPassword(password);
 
        String flag1 = null;
        String flag2 = null;
        try {
            flag1 = BusinessUserDao.selectUsername(businessUserVO);
            if ("ok".equals(flag1)) {//企业用户名存在
                BusinessUserDTO businessUserDTO = BusinessUserDao.select(businessUserVO);
                if (businessUserDTO != null) {
                    jsonObject.put("code", 2000);
                    jsonObject.put("flag", "success");//登录成功
                    jsonObject.put("user", businessUserDTO);
                    jsonObject.put("msg", "login_success");
                    session.setAttribute("businessUser",businessUserDTO);
                    resp.getWriter().print(jsonObject);
                    return;
                } else {
                    jsonObject.put("code", 2000);
                    jsonObject.put("flag", "fail");//登录失败
                    jsonObject.put("user", null);
                    jsonObject.put("msg", "passwordError");//密码错误
                    resp.getWriter().print(jsonObject);
                    return;
                }
            }
            flag2 = StudentUserDao.selectUsername(studentUserVO);
            if ("ok".equals(flag2)) {//学生用户名存在
                StudentUser studentUser = StudentUserDao.select(studentUserVO);
                if (studentUser != null) {
                    jsonObject.put("code", 2000);
                    jsonObject.put("flag", "success");//登录成功
                    jsonObject.put("user", studentUser);
                    jsonObject.put("msg", "login_success");
                    session.setAttribute("studentUser",studentUser);
                    resp.getWriter().print(jsonObject);
                    return;
                } else {
                    jsonObject.put("code", 2000);
                    jsonObject.put("flag", "fail");//登录失败
                    jsonObject.put("user", null);
                    jsonObject.put("msg", "passwordError");//密码错误
                    resp.getWriter().print(jsonObject);
                    return;
                }
 
            }
            //用户名不存在,前往注册
            jsonObject.put("code", 2000);
            jsonObject.put("flag", "fail");//登录失败
            jsonObject.put("user", null);
            jsonObject.put("msg", "usernameIsNotExist");//密码错误
            resp.getWriter().print(jsonObject);
            return;
 
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return;
 
    }
 
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        doGet(req, resp);
    }
}

管理员登录控制层

 public class AdminLoginController extends HttpServlet {
    @SneakyThrows
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        password = MyMD5Util.encrypt(password);
        JSONObject jsonObject = new JSONObject();
        HttpSession session = req.getSession();
        Admin admin = new Admin(username, password);
        Admin adminFromDB = AdminDao.findByUsernamePassword(admin);
        if (adminFromDB!=null){
            jsonObject.put("code",2000);
            jsonObject.put("msg","login_success");
            jsonObject.put("admin",adminFromDB.getUsername());
            jsonObject.put("flag","success");
            resp.getWriter().print(jsonObject);
            session.setAttribute("admin",adminFromDB);
            return;
        }else {
            jsonObject.put("code",2000);
            jsonObject.put("msg","no admin");
            jsonObject.put("admin",null);
            jsonObject.put("flag","fail");
            resp.getWriter().print(jsonObject);
            return;
        }
 
    }
 
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}

提交个人简介控制层

 public class SubmitResumeController extends HttpServlet {
    @SneakyThrows
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        JSONObject jsonObject = new JSONObject();
        DiskFileItemFactory factory = new DiskFileItemFactory();
        ServletFileUpload upload = new ServletFileUpload(factory);
        req.setCharacterEncoding("UTF-8");
        upload.setHeaderEncoding("UTF-8");
        List<FileItem> items = upload.parseRequest(req);
        StringBuffer sb = new StringBuffer();
        String resumeFile = null;
        for (FileItem item : items) {
            String name = item.getFieldName();
            InputStream inputStream = item.getInputStream();
            if (!name.equals("resumeFile")){
                String string = item.getString();
                string = new String(string.getBytes("ISO8859_1"), StandardCharsets.UTF_8);
                sb.append(string+"&&");
            }else {
                String[] split = sb.toString().split("&&");
                String studentName = split[0];
                String studentUsername = split[1];
                String recruitInfoId = split[2];
                String path=req.getServletContext().getRealPath("/");
                String fieldName = studentName+"_"+studentUsername+"_"+recruitInfoId+"_"+item.getName();
                String filePath = path+fieldName;
                resumeFile = fieldName;
                File file = new File(filePath);
                BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
                FileOutputStream fileOutputStream = new FileOutputStream(file);
                int line;
                while ((line = bufferedInputStream.read())!=-1){
                    fileOutputStream.write(line);
                }
                fileOutputStream.flush();
                fileOutputStream.close();
                bufferedInputStream.close();
            }
        }
        String[] split = sb.toString().split("&&");
        String studentName = split[0];
        String studentUsername = split[1];
        String recruitInfoId = split[2];
        String applyPosition = split[3];
        String phoneNum = split[4];
        String email = split[5];
        Resume resume = new Resume(studentUsername, Integer.parseInt(recruitInfoId), studentName, applyPosition, phoneNum, email, resumeFile);
        int insert = ResumeDao.insert(resume);
        if (insert == 1){
            jsonObject.put("code",2000);
            jsonObject.put("msg","add success");
            jsonObject.put("flag","success");
            jsonObject.put("data",resume);
            resp.getWriter().print(jsonObject);
            return;
        }else {
            jsonObject.put("code",2000);
            jsonObject.put("msg","add fail");
            jsonObject.put("flag","fail");
            jsonObject.put("data",null);
            resp.getWriter().print(jsonObject);
        }
 
 
    }
 
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}

“Java兼职平台系统如何实现”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

推荐阅读:
  1. 自学python能干什么兼职
  2. java实现跨平台的方法

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

java

上一篇:springcloud feign服务间调用date类型转换错误怎么解决

下一篇:go xorm生成mysql的结构体实例分析

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》