基于javaweb+mysql的springboot人才管理招聘系统(java+springboot+freemarker+jpa+mysql)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot人才管理招聘系统(java+springboot+freemarker+jpa+mysql)
项目介绍
基于SpringBoot框架开发的求职招聘管理系统。 本项目分三种角色:管理员、招聘人员、求职者。 用户可以以两种身份注册登录,一种是求职者,另一种是招聘者。 求职者可以浏览查询公司信息、职位信息,并且可以填写自己的简历,然后给自己心仪的职位投递简历。招聘者可以填写自己公司的信息,然后进行认证申请, 申请通过后,就可以进行发布职位,接收求职者投递来简历,并且进行审核和通知。 除此之外,该项目还附带后台管理功能,管理员可以登录后台管系统,进行职位类别添加、管理用户信息、通过审核来更改公司、职位的状态等。 项目功能:注册(引入邮箱验证码功能)、登录、修改密码、按条件查询、填写我的简历、填写公司信息、投递简历、发布职位、接收简历等等功能。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 4.数据库:MySql 5.7版本; 5.是否Maven项目:是;
技术栈
SpringBoot + FreeMarker + JPA
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中application-dev.properties配置文件中的数据库配置改为自己的配置; 4. 运行项目,项目运行成功后,在浏览器中输入网址: http://localhost:8082/home/index/index 访问的是网站首页面 http://localhost:8082/admin/system/login 访问的是后台管理页面
/**
* 前端用户登录拦截器
*
*/
@Component
public class UserLoginInterceptor implements HandlerInterceptor{
private Logger log = LoggerFactory.getLogger(UserLoginInterceptor.class);
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler){
String requestURI = request.getRequestURI(); //取得被拦截的链接,比如:requestURI=/home/index/index
HttpSession session = request.getSession();
Object attribute = session.getAttribute(SessionConstant.SESSION_USER_LOGIN_KEY);
if(attribute == null && requestURI.contains("/home/")){
log.info("用户还未登录或者session失效,重定向到登录页面,当前URL=" + requestURI);
//首先判断是否是ajax请求
if(StringUtil.isAjax(request)){
//表示是ajax请求
try {
response.setCharacterEncoding("UTF-8");
//JSON.parseObject,是将Json字符串转化为相应的对象;JSON.toJSONString则是将对象转化为Json字符串。
response.getWriter().write(JSON.toJSONString(CodeMsg.SESSION_EXPIRED));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
//说明是普通的请求,可直接重定向到登录页面
//用户还未登录或者session失效,重定向到登录页面
try {
response.sendRedirect("/home/system/login");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
log.info("该请求符合登录要求,放行" + requestURI);
return true;
}
}
User findByEmail = userService.findByEmail(user.getEmail());
if(findByEmail == null)
return false; //没有重复
if(findByEmail.getId().longValue() == id.longValue())
return false; //没有重复
return true; //有重复
}
//检查有没有重复的username
public boolean checkUsername(User user,Long id)
{
User findByUsername = userService.findByUsername(user.getUsername());
if(findByUsername == null)
return false; //没有重复
if(findByUsername.getId().longValue() == id.longValue())
return false; //没有重复
return true; //有重复
}
}
return Result.success(true);
}
}
/**
* 管理员控制类
*
*/
@RequestMapping("/admin/admin")
@Controller
public class AdminController {
@Autowired
private AdminService adminService;
@Autowired
private OperaterLogService operaterLogService;
if(checkCompanyName(company,0l)){
return Result.error(CodeMsg.COMPANY_NAME_ALREADY_EXIST);
}
company.setUser(session_user);
if(companyService.save(company) == null){
return Result.error(CodeMsg.COMPANY_NAME_AND_VALUE_SAVE_ERROR);
}
}else {
//进行修改操作
//检测公司名称是否重名
if(checkCompanyName(company,findCompany.getId())){
return Result.error(CodeMsg.COMPANY_NAME_ALREADY_EXIST);
}
company.setState("待审核");
BeanUtils.copyProperties(company, findCompany, "id","createTime","updateTime","user","tags","productPhoto","productTitle","productContent","introduction","locale","territory","scale","url","finance","founderName","founderPosition","founderPhoto");
if(companyService.save(findCompany) == null){
return Result.error(CodeMsg.COMPANY_NAME_AND_VALUE_SAVE_ERROR);
}
}
return Result.success(true);
}
/**
* 保存公司标签
* @param company
* @param request
* @return
*/
@RequestMapping(value="/save_company_tags",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> saveCompanyTags(Company company,HttpServletRequest request)
{
if(company == null){
return Result.error(CodeMsg.DATA_ERROR);
}
//检测公司标签长度
if(company.getTags().length() > 30) {
return Result.error(CodeMsg.COMPANY_TAGS_WORD_OVER);
}
User session_user = (User) request.getSession().getAttribute(SessionConstant.SESSION_USER_LOGIN_KEY);
Company findCompany = companyService.findByUserId(session_user.getId());
if(findCompany == null) {
//先让用户填写名称和价值观基本信息
return Result.error(CodeMsg.COMPANY_NAME_AND_VALUE_PRIORITY);
}else {
//进行修改操作
company.setState("待审核");
BeanUtils.copyProperties(company, findCompany, "id","createTime","updateTime","user","name","value","photo","productPhoto","productTitle","productContent","introduction","locale","territory","scale","url","finance","founderName","founderPosition","founderPhoto");
if(companyService.save(findCompany) == null){
return Result.error(CodeMsg.COMPANY_TAGS_SAVE_ERROR);
}
}
/**
* 职位类别控制类
*
*/
@RequestMapping("/admin/position_category")
@Controller
public class PositionCategoryController {
@Autowired
private PositionCategoryService positionCategoryService;
@Autowired
private OperaterLogService operaterLogService;
/**
* 职位类别页面
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public String positionCategory(Model model){
//用户还未登录或者session失效,重定向到登录页面
try {
response.sendRedirect("/admin/system/login");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
log.info("该请求符合登录要求,放行" + requestURI);
return true;
}
}
/**
* 前端用户登录拦截器
*
*/
@Component
public class UserLoginInterceptor implements HandlerInterceptor{
private Logger log = LoggerFactory.getLogger(UserLoginInterceptor.class);
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler){
String requestURI = request.getRequestURI(); //取得被拦截的链接,比如:requestURI=/home/index/index
@RequestMapping(value="/delete",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> delete(Long id,HttpServletRequest request){
if(id == null || id <= 0)
{
return Result.error(CodeMsg.POSITION_CATEGORY_DELETE_ID_EMPTY);
}
List<PositionCategory> findAll = positionCategoryService.findAll();
for(PositionCategory positionCategory : findAll)
{
//如果有子类,不允许删除
if(positionCategory.get_parentId() == id)
{
return Result.error(CodeMsg.POSITION_CATEGORY_PARENT_DELETE_ERROR);
}
}
positionCategoryService.delete(id);
//添加操作日志
OperaterLog operaterLog = new OperaterLog();
Admin admin = (Admin) request.getSession().getAttribute(SessionConstant.SESSION_ADMIN_LOGIN_KEY);
operaterLog.setOperator("【"+admin.getAdminName()+"】:");
operaterLog.setContent("删除了职业类别(ID):【"+id+"】。");
operaterLogService.save(operaterLog);
return Result.success(true);
}
}
positionService.delete(position.getId());
}
//最后删除公司
companyService.delete(id);
}catch(Exception e) {
e.printStackTrace();
return Result.error(CodeMsg.FOREIGN_KEY_RESTRAIN);
}
return Result.success(true);
}
}
/**
* 后台管理控制类
*
*/
@RequestMapping("/admin/system")
@Controller
public class SystemController {
@Autowired
private AdminService adminService ;
@Autowired
BeanUtils.copyProperties(user, findById, "id","createTime","updateTime","content","type","email","password");
findById.setUpdateTime(new Date());
if(userService.save(findById) == null){
return Result.error(CodeMsg.USER_SAVE_ERROR);
}
//更新权限
request.getSession().setAttribute(SessionConstant.SESSION_USER_LOGIN_KEY, userService.find(session_user.getId()));
return Result.success(true);
}
/**
* 保存自我描述信息
* @param content
* @param request
* @return
*/
@RequestMapping(value="/save_self_description",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> saveSelfDescription(String content,HttpServletRequest request)
{
User session_user = (User) request.getSession().getAttribute("user");
session_user.setContent(content);
session_user.setUpdateTime(new Date());
if(userService.save(session_user) == null){
return Result.error(CodeMsg.USER_SAVE_SELF_DESCRIPTION_ERROR);
}
//更新权限
request.getSession().setAttribute(SessionConstant.SESSION_USER_LOGIN_KEY, userService.find(session_user.getId()));
return Result.success(true);
}
//检查有没有重复的username
public boolean checkUsername(User user,Long id)
{
User findByUsername = userService.findByUsername(user.getUsername());
if(findByUsername == null)
return false; //没有重复
if(findByUsername.getId().longValue() == id.longValue())
return false; //没有重复
return true; //有重复
}
}
/**
* 公用的上传类
*
*/
@RequestMapping("/upload")
@Controller
public class UploadController {
@Value("${yjq.upload.photo.sufix}")
private String uploadPhotoSufix;
@Value("${yjq.upload.photo.maxsize}")
private long uploadPhotoMaxSize; //大小1024KB
private String uploadPhotoPath=System.getProperty("user.dir") + "/src/main/resources/upload/";
private Logger log = LoggerFactory.getLogger(UploadController.class);
/**
* 图片统一上传类
* @param photo
* @return
*/
@RequestMapping(value="/upload_photo",method=RequestMethod.POST)
@ResponseBody
public Result<String> uploadPhoto(@RequestParam(name="photo",required=true)MultipartFile photo){
//判断文件类型是否是图片
String originalFilename = photo.getOriginalFilename();
//获取文件后缀
String suffix = originalFilename.substring(originalFilename.lastIndexOf("."),originalFilename.length());
if(!uploadPhotoSufix.contains(suffix.toLowerCase())){
return Result.error(CodeMsg.UPLOAD_PHOTO_SUFFIX_ERROR);
}
//photo.getSize()单位是B
return Result.error(url_way_two); //前往已下线职位页面
}
}else {
//添加
position.setState("wait");
if(positionService.save(position) == null) {
return Result.error(CodeMsg.POSITION_SAVE_ERROR);
}
return Result.error(url_way_one); //前往待处理职位页面
}
}
/**
* 删除职位信息
* @param id
* @param request
* @return
*/
@RequestMapping(value="/delete",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> deletePosition(@RequestParam(name="id",required=true)Long id)
{
try {
List<Resume> findByPositionId = resumeService.findByPositionId(id);
//删除该职位下所有简历
for(Resume resume : findByPositionId)
{
resumeService.delete(resume.getId());
}
positionService.delete(id);
}catch(Exception e) {
e.printStackTrace();
return Result.error(CodeMsg.POSITION_SAVE_ERROR);
}
return Result.success(true);
}
/**
* 更改职位状态信息为下线
* @param id
* @param request
* @return
*/
/**
* 前端用户控制器
*
*/
@RequestMapping("/home/user")
@Controller
public class HomeUserController {
@Autowired
private UserService userService;
/**
* 保存用户信息
* @param user
* @param request
* @return
*/
@RequestMapping(value="/save",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> saveUserForm(User user,HttpServletRequest request)
{
if(user == null){
return Result.error(CodeMsg.DATA_ERROR);
}
if(StringUtil.isEmpty(user.getUsername())) {
return Result.error(CodeMsg.USER_NAME_EMPTY);
}
if(StringUtil.isEmpty(user.getMobile())) {
return Result.error(CodeMsg.USER_MOBILE_EMPTY);
}
if(user.getMobile().length() != 11) {
return Result.error(CodeMsg.USER_MOBILE_NOT_CORRECT);
}
User session_user = (User) request.getSession().getAttribute("user");
User findById = userService.find(session_user.getId());
if(checkUsername(user,findById.getId())){
return Result.error(CodeMsg.USER_NAME_ALREADY_EXIST);
}
BeanUtils.copyProperties(user, findById, "id","createTime","updateTime","content","type","email","password");
findById.setUpdateTime(new Date());
if(userService.save(findById) == null){
return Result.error(CodeMsg.USER_SAVE_ERROR);
}
//更新权限
request.getSession().setAttribute(SessionConstant.SESSION_USER_LOGIN_KEY, userService.find(session_user.getId()));
return Result.success(true);
if(educationBackground == null){
return Result.error(CodeMsg.DATA_ERROR);
}
//检查学校名称是否为空
if(StringUtil.isEmpty(educationBackground.getSchool_name())){
return Result.error(CodeMsg.RESUME_EDUCATION_BACKGROUND_SCHOOL_NAME_EMPTY);
}
//检查专业名称是否为空
if(StringUtil.isEmpty(educationBackground.getMajor())) {
return Result.error(CodeMsg.RESUME_EDUCATION_BACKGROUND_MAJOR_EMPTY);
}
//检查开始年份是否为空
if(educationBackground.getStartYear() == null || "开始年份".equals(educationBackground.getStartYear())) {
return Result.error(CodeMsg.RESUME_EDUCATION_BACKGROUND_START_TIME_EMPTY);
}
//检查结束年份是否为空
if(educationBackground.getEndYear() == null || "结束年份".equals(educationBackground.getEndYear())) {
return Result.error(CodeMsg.RESUME_EDUCATION_BACKGROUND_END_TIME_EMPTY);
}
//检查结束年份是否大于开始年份
if(Integer.valueOf(educationBackground.getStartYear()) > Integer.valueOf(educationBackground.getEndYear())) {
return Result.error(CodeMsg.RESUME_EDUCATION_BACKGROUND_TIME_NOT_CORRECT);
}
User session_user = (User) request.getSession().getAttribute("user");
educationBackground.setUser(session_user);
//检查有没有添加过教育背景
EducationBackground findEducationBackground = educationBackgroundService.findEducationBackgroundByUserId(session_user.getId());
if(findEducationBackground != null){
//进行修改操作
BeanUtils.copyProperties(educationBackground, findEducationBackground, "id","createTime","updateTime");
if(educationBackgroundService.save(findEducationBackground) == null){
return Result.error(CodeMsg.RESUME_EDUCATION_BACKGROUND_ERROR);
}
}else {
//进行添加操作
if(educationBackgroundService.save(educationBackground) == null){
return Result.error(CodeMsg.RESUME_EDUCATION_BACKGROUND_ERROR);
}
}
//更新最后一次修改时间
session_user.setUpdateTime(new Date());
if(userService.save(session_user) == null){
return Result.error(CodeMsg.USER_UPDATE_TIME_ERROR);
}
//把用户权限更新
User new_session_user = userService.find(session_user.getId());
request.getSession().setAttribute(SessionConstant.SESSION_USER_LOGIN_KEY, new_session_user);
return Result.success(true);
}
Company findCompanyByUserId = companyService.findByUserId(user.getId());
if(findCompanyByUserId == null || !"已认证".equals(findCompanyByUserId.getState())) {
model.addAttribute("errorMsg", "您的公司还没认证通过,请填写公司信息或者等待认证通过!3s后为您跳转我的公司页面!");
}
//判断是不是编辑操作
if(id != null) {
//如果是
Position findById = positionService.findById(id);
model.addAttribute("editPosition", findById);
}
model.addAttribute("publish_position", "publish_position"); //top_menu显示
return "home/index/publish_position";
}
/**
* 关于我们页面
* @param model
* @return
*/
@RequestMapping(value="/about",method=RequestMethod.GET)
public String about(Model model){
model.addAttribute("about", "about"); //top_menu显示
return "home/index/about";
}
}
/**
* 拉勾网页面系统类控制器
*
*/
return Result.error(CodeMsg.USER_SAVE_ERROR);
}
//更新权限
request.getSession().setAttribute(SessionConstant.SESSION_USER_LOGIN_KEY, userService.find(session_user.getId()));
return Result.success(true);
}
/**
* 保存自我描述信息
* @param content
* @param request
* @return
*/
@RequestMapping(value="/save_self_description",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> saveSelfDescription(String content,HttpServletRequest request)
{
User session_user = (User) request.getSession().getAttribute("user");
session_user.setContent(content);
session_user.setUpdateTime(new Date());
if(userService.save(session_user) == null){
return Result.error(CodeMsg.USER_SAVE_SELF_DESCRIPTION_ERROR);
}
//更新权限
request.getSession().setAttribute(SessionConstant.SESSION_USER_LOGIN_KEY, userService.find(session_user.getId()));
return Result.success(true);
}
//检查有没有重复的username
public boolean checkUsername(User user,Long id)
{
User findByUsername = userService.findByUsername(user.getUsername());
if(findByUsername == null)
return false; //没有重复
if(findByUsername.getId().longValue() == id.longValue())
return false; //没有重复
return true; //有重复
}
}
if(StringUtil.isEmpty(user.getUsername())) {
return Result.error(CodeMsg.USER_NAME_EMPTY);
}
if(StringUtil.isEmpty(user.getMobile())) {
return Result.error(CodeMsg.USER_MOBILE_EMPTY);
}
if(user.getMobile().length() != 11) {
return Result.error(CodeMsg.USER_MOBILE_NOT_CORRECT);
}
User session_user = (User) request.getSession().getAttribute("user");
User findById = userService.find(session_user.getId());
if(checkUsername(user,findById.getId())){
return Result.error(CodeMsg.USER_NAME_ALREADY_EXIST);
}
BeanUtils.copyProperties(user, findById, "id","createTime","updateTime","content","type","email","password");
findById.setUpdateTime(new Date());
if(userService.save(findById) == null){
return Result.error(CodeMsg.USER_SAVE_ERROR);
}
//更新权限
request.getSession().setAttribute(SessionConstant.SESSION_USER_LOGIN_KEY, userService.find(session_user.getId()));
return Result.success(true);
}
/**
* 保存自我描述信息
* @param content
* @param request
* @return
*/
@RequestMapping(value="/save_self_description",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> saveSelfDescription(String content,HttpServletRequest request)
{
User session_user = (User) request.getSession().getAttribute("user");
session_user.setContent(content);
session_user.setUpdateTime(new Date());
if(userService.save(session_user) == null){
return Result.error(CodeMsg.USER_SAVE_SELF_DESCRIPTION_ERROR);
}
//更新权限
request.getSession().setAttribute(SessionConstant.SESSION_USER_LOGIN_KEY, userService.find(session_user.getId()));
return Result.success(true);
}
//检查有没有重复的username
public boolean checkUsername(User user,Long id)
{
User findByUsername = userService.findByUsername(user.getUsername());
if(findByUsername == null)
return false; //没有重复
if(findByUsername.getId().longValue() == id.longValue())
return false; //没有重复
/**
* 更改密码页面
* @param model
* @return
*/
@RequestMapping(value="/update_password",method=RequestMethod.GET)
public String updatePwd(Model model){
return "home/system/update_password";
}
/**
* 前端用户退出登录
* @param model
* @return
*/
@RequestMapping(value="/logout")
public String loginout(HttpServletRequest request){
request.getSession().setAttribute(SessionConstant.SESSION_USER_LOGIN_KEY , null);
return "redirect:/home/index/index";
}
/**
* 前端登录页面
* @param model
* @return
*/
@RequestMapping(value="/login",method=RequestMethod.GET)
public String login(Model model){
return "home/system/login";
}
/**
* 前端修改密码数据处理
* @param model
* @return
*/
@RequestMapping(value="/update_password",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> updatePwd(String oldPwd,String newPwd,String confirmPwd,HttpServletRequest request)