Java實戰(zhàn)之兼職平臺系統(tǒng)的實現(xiàn)
一、項目運行
環(huán)境配置:
Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
項目技術(shù):
HTML +Springboot+ SpringMVC + MyBatis + ThymeLeaf + JavaScript + JQuery + Ajax + maven等等.
二、效果圖







三、核心代碼
登錄控制層
/**
* @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)) {//企業(yè)用戶名存在
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)) {//學(xué)生用戶名存在
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);
}
}到此這篇關(guān)于Java實戰(zhàn)之兼職平臺系統(tǒng)的實現(xiàn)的文章就介紹到這了,更多相關(guān)Java兼職平臺系統(tǒng)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
tk-mybatis整合springBoot使用兩個數(shù)據(jù)源的方法
單純的使用mybaits進行多數(shù)據(jù)配置網(wǎng)上資料很多,但是關(guān)于tk-mybaits多數(shù)據(jù)源配置沒有相關(guān)材料,本文就詳細的介紹一下如何使用,感興趣的可以了解一下2021-12-12
通過jxl.jar 讀取、導(dǎo)出excel的實例代碼
通過jxl.jar 讀取、導(dǎo)出excel的實例代碼,需要的朋友可以參考一下2013-03-03
關(guān)于mybatis-plus邏輯刪除自動填充更新時間的問題
mybatis-plus是對mybatis的增強,mybatis-plus更像是面向?qū)ο缶幊蹋瑪?shù)據(jù)庫基本CRUD的操作可以不用手動編寫SQL語句,大大提高了開發(fā)的效率,這篇文章主要介紹了mybatis-plus邏輯刪除自動填充更新時間問題,需要的朋友可以參考下2022-07-07

