基于javaweb+mysql的springboot招聘系统项目(java+springboot+jsp+maven+mysql)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot招聘系统项目(java+springboot+jsp+maven+mysql)
项目介绍
SpringBoot招聘项目。主要功能说明: 管理员登录,简历管理,问答管理,职位管理,用户管理,职位申请进度更新,查看简历等功能。
用户角色包含以下功能:用户首页,登录注册,职位查看,职位详情,投递简历,查看我的申请,管理个人简历,附件简历管理等功能。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.是否Maven项目: 是;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目
6.数据库:MySql 5.7版本;
技术栈
-
后端:SpringBoot
-
前端:HTML+CSS+JavaScript+jsp
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,下载所需jar包; 3. 将项目中datasource.properties配置文件中的数据库配置改为自己的配置 4. 配置tomcat,然后运行项目,在浏览器中输入http://localhost:8080/ 登录 管理员账号/密码:admin/123456 用户账号/密码: matou/123456
@Controller
public class MainController {
private static final Logger logger = LoggerFactory.getLogger(MainController.class);
@Autowired
private UserService userService;
@GetMapping("/login1")
public String login(){
return "login";
}
@GetMapping("/")
public String index1(){
return "index";
}
@GetMapping("/index1")
public String index(){
return "index";
}
@PostMapping("/loginCheck")
public String loginCheck(String username, String password, HttpSession session, Model model,String verifyInput){
//检验验证码
String originalVerify = (String)session.getAttribute(RandomValidateCodeUtil.RANDOMCODEKEY);
if(!StringUtils.equals(originalVerify,verifyInput)){
model.addAttribute("verifyCode","false");
return "login";
}
UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(username,password);
usernamePasswordToken.setRememberMe(true);
Subject subject = SecurityUtils.getSubject();
try {
subject.login(usernamePasswordToken);
randomString = drowString(g, randomString, i);
}
logger.info(randomString);
//将生成的随机字符串保存到session中
session.removeAttribute(RANDOMCODEKEY);
session.setAttribute(RANDOMCODEKEY, randomString);
g.dispose();
try {
// 将内存中的图片通过流动形式输出到客户端
ImageIO.write(image, "JPEG", response.getOutputStream());
} catch (Exception e) {
logger.error("将内存中的图片通过流动形式输出到客户端失败>>>> ", e);
}
}
/**
* 绘制字符串
*/
private String drowString(Graphics g, String randomString, int i) {
g.setFont(getFont());
g.setColor(new Color(random.nextInt(101), random.nextInt(111), random
.nextInt(121)));
String rand = String.valueOf(getRandomString(random.nextInt(randString
.length())));
randomString += rand;
g.translate(random.nextInt(3), random.nextInt(3));
g.drawString(rand, 13 * i, 16);
return randomString;
}
/**
* 绘制干扰线
*/
private void drowLine(Graphics g) {
int x = random.nextInt(width);
int y = random.nextInt(height);
int xl = random.nextInt(13);
int yl = random.nextInt(15);
g.drawLine(x, y, x + xl, y + yl);
}
/**
* 获取随机的字符
*/
public String getRandomString(int num) {
return String.valueOf(randString.charAt(num));
/**
*/
@Controller
@RequestMapping("/department")
public class DepartmentController {
@Autowired
private DepartmentMapper departmentMapper;
@Autowired
private DepartmentService departmentService;
// 展现简历
@RequiresRoles("admin")
@PostMapping("/add")
@ResponseBody
public ServerResponse add(DepartmentDTO dto) {
try {
dto.setCreateTime(new Date());
departmentMapper.insertSelective(dto);
} catch (Exception e) {
return ServerResponse.buildErrorMsg("添加部门失败!");
}
return ServerResponse.buildSuccessMsg("添加部门成功!");
}
// 展现题库
@RequiresRoles("admin")
@DeleteMapping("/delete/{id}")
@ResponseBody
public ServerResponse delete(@PathVariable("id") String id,HttpSession session) {
String username =(String) session.getAttribute("username");
if (StringUtils.isEmpty(username)){
return ServerResponse.buildErrorMsg("请登录");
}
try {
departmentMapper.deleteByPrimaryKey(id);
} catch (Exception e) {
return ServerResponse.buildErrorMsg("删除失败!");
}
return ServerResponse.buildSuccessMsg("删除成功!");
}
@RequiresRoles("admin")
/**
*/
@Controller
@RequestMapping("/school")
public class SchoolController {
private static final int flag = 2;
@Autowired
private PositionService positionService;
@Autowired
private UserService userService;
//-----------------------校园------------
@GetMapping
public String showSchool(Model model,HttpServletRequest request,
@RequestParam(value = "pageIndex",defaultValue = "1",required = false)int pageIndex,
@RequestParam(value = "pageSize",defaultValue = "5",required = false)int pageSize){
ServerResponse serverResponse = positionService.findBySchool(pageIndex,pageSize);
PageInfo pageInfo =(PageInfo) serverResponse.getData();
model.addAttribute("positions",pageInfo);
return "www/school";
}
//关键字搜索
//@GetMapping("/findByKeyWord")
//@ResponseBody
public ServerResponse findByKeyWord(@RequestParam(value = "keyWord")String keyWord,
@RequestParam(value = "pageIndex",defaultValue = "1",required = false)int pageIndex,
@RequestParam(value = "pageSize",defaultValue = "5",required = false)int pageSize){
ServerResponse serverResponse = positionService.findByKeyWord(keyWord,pageIndex,pageSize,flag);
return ServerResponse.buildSuccessData(serverResponse.getData());
if (values[j].equalsIgnoreCase(badStrs[i])){
values[j] = "forbid";
}
}
}
StringBuilder sb = new StringBuilder();
for (int i = 0;i<values.length;i++){
if (i == values.length-1){
sb.append(values[i]);
} else {
sb.append(values[i]+" ");
}
}
value = sb.toString();
return value;
}
}
/**
*/
@Controller
@RequestMapping("/department")
public class DepartmentController {
@Autowired
private DepartmentMapper departmentMapper;
@Autowired
private DepartmentService departmentService;
// 展现简历
@RequiresRoles("admin")
@PostMapping("/add")
@ResponseBody
public ServerResponse add(DepartmentDTO dto) {
public String getSocial(@RequestParam(value = "keyWord") String keyWord,
@RequestParam(value = "flag") Integer flag,
@RequestParam(value = "pageIndex",defaultValue = "1",required = false)int pageIndex,
@RequestParam(value = "pageSize",defaultValue = "5",required = false)int pageSize,
Model model) throws ErrorException {
if (StringUtils.isBlank(keyWord) || flag == null){
throw new ErrorException("参数不能为空");
}
ServerResponse serverResponse = findByKeyWord(flag,keyWord,pageIndex,pageSize);
PageInfo pageInfo = (PageInfo)serverResponse.getData();
model.addAttribute("positions",pageInfo);
if (flag == 1){
return "www/position";
}
return "www/school";
}
private ServerResponse findByKeyWord(int flag,String keyWord,int pageIndex,int pageSize){
return positionService.findByKeyWord(keyWord,pageIndex,pageSize,flag);
}
}
/**
*/
@Controller
@RequestMapping("/edu")
public class EducationController {
@Autowired
private EducationService educationService;
@Autowired
private UserService userService;
@PostMapping("/addOrUpdate")
@ResponseBody
public ServerResponse addOrUpdate(Education education, HttpSession session){
@RequestParam(value = "pageNum",defaultValue = "5",required = false)int pageNum,
HttpSession session){
String username = (String) session.getAttribute("username");
if (StringUtils.isEmpty(username)){
return ServerResponse.buildErrorMsg("请登录");
}
User user = userService.findByUsername(username);
ServerResponse serverResponse = collectionService.show(user.getId(),pageIndex,pageNum);
/* PageInfo pageInfo = (PageInfo)serverResponse.getData();
model.addAttribute("collection",pageInfo);*/
return serverResponse;
}
@DeleteMapping("/delete")
@ResponseBody
public ServerResponse delete(int id,HttpSession session){
String username = (String) session.getAttribute("username");
if (StringUtils.isEmpty(username)){
return ServerResponse.buildErrorMsg("请登录");
}
return collectionService.cancelCollection(id);
}
}
@Controller
@RequestMapping("/apply")
public class ApplyController {
@Autowired
private PositionService positionService;
@Autowired
private UserService userService;
}
User user = userService.findByUsername(username);
return positionService.apply(user.getId(),pId,resumeId);
}
//收藏职位
@PostMapping("/collect")
@ResponseBody
public ServerResponse collect(HttpSession session,int pId){
String username =(String) session.getAttribute("username");
if (StringUtils.isEmpty(username)){
return ServerResponse.buildErrorMsg("请登录");
}
User user = userService.findByUsername(username);
return positionService.collect(user.getId(),pId,flag);
}
/*----------------------------职位管理-------------------------------------*/
@RequiresRoles("admin")
@GetMapping("/manager")
public String show(Model model){
ServerResponse serverResponse = positionService.findAll(1,5);
model.addAttribute("position",serverResponse.getData());
return "manage/position";
}
@RequiresRoles("admin")
@GetMapping("/manager/findByPage")
@ResponseBody
public ServerResponse findByPage(@RequestParam(value = "condition",required = false)String condition,
@RequestParam(value = "pageIndex",defaultValue = "1",required = false)int pageIndex,
@RequestParam(value = "pageSize",defaultValue = "5",required = false)int pageSize){
if (StringUtils.isEmpty(condition)){
condition = null;
}
//0代表无限制
return positionService.findByKeyWord(condition,pageIndex,pageSize,0);
}
//管理员的权限
@RequiresRoles("admin")
@PostMapping("/admin/add")
@ResponseBody
public ServerResponse add(Positions positions,HttpSession session){
String username =(String) session.getAttribute("username");
if (StringUtils.isEmpty(username)){
return ServerResponse.buildErrorMsg("请登录");
}
/**
*/
@Controller
@RequestMapping("/school")
public class SchoolController {
private static final int flag = 2;
@Autowired
private PositionService positionService;
@Autowired
private UserService userService;
//-----------------------校园------------
@GetMapping
public String showSchool(Model model,HttpServletRequest request,
@RequestParam(value = "pageIndex",defaultValue = "1",required = false)int pageIndex,
@RequestParam(value = "pageSize",defaultValue = "5",required = false)int pageSize){
ServerResponse serverResponse = positionService.findBySchool(pageIndex,pageSize);
PageInfo pageInfo =(PageInfo) serverResponse.getData();
model.addAttribute("positions",pageInfo);
return "www/school";
}
//关键字搜索
//@GetMapping("/findByKeyWord")
//@ResponseBody
public ServerResponse findByKeyWord(@RequestParam(value = "keyWord")String keyWord,
@RequestParam(value = "pageIndex",defaultValue = "1",required = false)int pageIndex,
@RequestParam(value = "pageSize",defaultValue = "5",required = false)int pageSize){
ServerResponse serverResponse = positionService.findByKeyWord(keyWord,pageIndex,pageSize,flag);
return ServerResponse.buildSuccessData(serverResponse.getData());
}
@GetMapping("/getDetail")
public String getDetail(@RequestParam("pName")String pName,
Model model){
ServerResponse serverResponse = positionService.getDeatils(pName,flag);
model.addAttribute("detail",serverResponse.getData());
serverResponse = positionService.findByRandom(flag);
model.addAttribute("positions",serverResponse.getData());
return "www/detail";
}
@PostMapping("/registerCheck")
@ResponseBody
public ServerResponse register(User user){
//密码加密
Md5Hash md5Hash = new Md5Hash(user.getPassword().toString(),"",1);
user.setPassword(md5Hash.toString());
return userService.register(user);
}
//检验答案
@PostMapping("/checkAnswer")
@ResponseBody
public ServerResponse checkAnswer(String username, String answer1,
String answer2, HttpSession httpSession){
ServerResponse serverResponse = userService.checkAnswer(username,answer1,answer2);
if (serverResponse.isSuccess()){
//存储一个token,根据username
httpSession.setAttribute(username, UUID.randomUUID());
}
return serverResponse;
}
//更改密码
@PostMapping("/changePassword")
@ResponseBody
public ServerResponse changePassword(String username,
String newPassword,HttpSession session){
Object UUID = session.getAttribute(username);
if (UUID == null){
return ServerResponse.buildErrorMsg("请先验证密保");
}
return userService.changePassword(username,newPassword);
}
@GetMapping("/logout")
public String logout(HttpSession session){
session.removeAttribute("username");
Subject subject = SecurityUtils.getSubject();
subject.logout();
return "login";
}
/**
* 生成验证码
*/
@GetMapping(value = "/login/getVerify")
public void getVerify(HttpServletRequest request, HttpServletResponse response) {
try {
response.setContentType("image/jpeg");
//设置响应头信息,告诉浏览器不要缓存此内容
response.setHeader("Pragma", "No-cache");
/**
* 社会招聘
*/
@Controller
@RequestMapping("/position")
public class PositionController {
private static final int flag = 1;
@Autowired
private PositionService positionService;
@Autowired
private UserService userService;
//展现页面
@GetMapping
public String show(Model model, HttpServletRequest request,
@RequestParam(value = "pageIndex",defaultValue = "1",required = false)int pageIndex,
@RequestParam(value = "pageSize",defaultValue = "5",required = false)int pageSize){
ServerResponse serverResponse = positionService.findAllBySocial(pageIndex,pageSize);
PageInfo pageInfo =(PageInfo) serverResponse.getData();
model.addAttribute("positions",pageInfo);
return "www/position";
}
@GetMapping("/getDetail")
public String getDetail(@RequestParam("pName")String pName,
Model model){
ServerResponse serverResponse = positionService.getDeatils(pName,flag);
model.addAttribute("detail",serverResponse.getData());
serverResponse = positionService.findByRandom(flag);
model.addAttribute("positions",serverResponse.getData());
return "www/detail";
}
@GetMapping("/findByCondiction")
@ResponseBody
public ServerResponse findByCondiction(@RequestParam(value = "condition",required = false,defaultValue = "") String condition,
@RequestParam(value = "keyWord",required = false,defaultValue = "")String keyWord,
@RequestParam(value = "pageIndex",defaultValue = "1",required = false)int pageIndex,
@RequestParam(value = "pageSize",defaultValue = "5",required = false)int pageSize,
HttpServletRequest request) {
/**
*/
@Controller
@RequestMapping("/questType")
public class QuestTypeController {
@Autowired
private QuestTypeMapper questTypeMapper;
@Autowired
private QuestTypeService questTypeService;
// 展现简历
@RequiresRoles("admin")
@PostMapping("/add")
@ResponseBody
public ServerResponse add(QuestTypeDTO dto) {
try {
dto.setCreateTime(new Date());
questTypeMapper.insertSelective(dto);
} catch (Exception e) {
return ServerResponse.buildErrorMsg("添加问卷类别失败!");
}
return ServerResponse.buildSuccessMsg("添加问卷类别成功!");
}
int l = s.length();
int ch = -1;
int b, sumb = 0;
for (int i = 0, more = -1; i < l; i++) {
/* Get next byte b from URL segment s */
switch (ch = s.charAt(i)) {
case '%':
ch = s.charAt(++i);
int hb = (Character.isDigit((char) ch) ? ch - '0'
: 10 + Character.toLowerCase((char) ch) - 'a') & 0xF;
ch = s.charAt(++i);
int lb = (Character.isDigit((char) ch) ? ch - '0'
: 10 + Character.toLowerCase((char) ch) - 'a') & 0xF;
b = (hb << 4) | lb;
break;
case '+':
b = ' ';
break;
default:
b = ch;
}
/* Decode byte b as UTF-8, sumb collects incomplete chars */
if ((b & 0xc0) == 0x80) { // 10xxxxxx (continuation byte)
sumb = (sumb << 6) | (b & 0x3f); // Add 6 bits to sumb
if (--more == 0)
sbuf.append((char) sumb); // Add char to sbuf
} else if ((b & 0x80) == 0x00) { // 0xxxxxxx (yields 7 bits)
sbuf.append((char) b); // Store in sbuf
} else if ((b & 0xe0) == 0xc0) { // 110xxxxx (yields 5 bits)
sumb = b & 0x1f;
more = 1; // Expect 1 more byte
} else if ((b & 0xf0) == 0xe0) { // 1110xxxx (yields 4 bits)
sumb = b & 0x0f;
more = 2; // Expect 2 more bytes
} else if ((b & 0xf8) == 0xf0) { // 11110xxx (yields 3 bits)
sumb = b & 0x07;
more = 3; // Expect 3 more bytes
} else if ((b & 0xfc) == 0xf8) { // 111110xx (yields 2 bits)
sumb = b & 0x03;
more = 4; // Expect 4 more bytes
} else /*if ((b & 0xfe) == 0xfc)*/ { // 1111110x (yields 1 bit)
sumb = b & 0x01;
more = 5; // Expect 5 more bytes
}
/* We don't test if the UTF-8 encoding is well-formed */
}
return sbuf.toString();
}
/**
* 查询个人信息
*
* @param session
* @return
*/
@GetMapping
@ResponseBody
public ServerResponse get(HttpSession session) {
String username = (String) session.getAttribute("username");
if (StringUtils.isEmpty(username)) {
return ServerResponse.buildErrorMsg("请登录");
}
User user = userService.findByUsername(username);
return informationService.findByUserId(user.getId());
}
public static String decode(String s) {
StringBuffer sbuf = new StringBuffer();
int l = s.length();
int ch = -1;
int b, sumb = 0;
for (int i = 0, more = -1; i < l; i++) {
/* Get next byte b from URL segment s */
switch (ch = s.charAt(i)) {
case '%':
ch = s.charAt(++i);
int hb = (Character.isDigit((char) ch) ? ch - '0'
: 10 + Character.toLowerCase((char) ch) - 'a') & 0xF;
ch = s.charAt(++i);
int lb = (Character.isDigit((char) ch) ? ch - '0'
: 10 + Character.toLowerCase((char) ch) - 'a') & 0xF;
b = (hb << 4) | lb;
break;
case '+':
b = ' ';
break;
default:
b = ch;
}
/* Decode byte b as UTF-8, sumb collects incomplete chars */
if ((b & 0xc0) == 0x80) { // 10xxxxxx (continuation byte)
sumb = (sumb << 6) | (b & 0x3f); // Add 6 bits to sumb
if (--more == 0)
@RequestParam(value = "pageIndex", defaultValue = "1", required = false) int pageIndex,
@RequestParam(value = "pageSize", defaultValue = "5", required = false) int pageSize){
return resumeService.query(position,pageIndex,pageSize);
}
//删除简历
@RequiresRoles("admin")
@DeleteMapping("/manager/delete/{id}")
@ResponseBody
public ServerResponse delete(@PathVariable int id){
return resumeService.delete(id);
}
}
public class RandomValidateCodeUtil {
public static final String RANDOMCODEKEY= "RANDOMVALIDATECODEKEY";//放到session中的key
private String randString = "0123456789";//随机产生只有数字的字符串 private String
//private String randString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";//随机产生只有字母的字符串
//private String randString = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";//随机产生数字与字母组合的字符串
private int width = 95;// 图片宽
private int height = 25;// 图片高
private int lineSize = 40;// 干扰线数量
private int stringNum = 4;// 随机产生字符数量
private static final Logger logger = LoggerFactory.getLogger(RandomValidateCodeUtil.class);
private Random random = new Random();
if (value == null) {
return null;
}
return cleanXSS(value);
}
/**
* 覆盖getHeader方法,将参数名和参数值都做xss过滤。
* 如果需要获得原始的值,则通过super.getHeaders(name)来获取
* getHeaderNames 也可能需要覆盖
*/
public String getHeader(String name) {
String value = super.getHeader(name);
if (value == null)
return null;
return cleanXSS(value);
}
private String cleanXSS(String value) {
//You'll need to remove the spaces from the html entities below
value = value.replaceAll("<", "& lt;").replaceAll(">", "& gt;");
value = value.replaceAll("\\(", "& #40;").replaceAll("\\)", "& #41;");
value = value.replaceAll("'", "& #39;");
value = value.replaceAll("eval\\((.*)\\)", "");
value = value.replaceAll("[\\\"\\\'][\\s]*javascript:(.*)[\\\"\\\']", "\"\"");
value = value.replaceAll("script", "");
value = value.replaceAll("[*]","["+"*]");
value = value.replaceAll("[+]","["+"+]");
value = value.replaceAll("[?]","["+"?]");
// replace sql 这里可以自由发挥
String[] values = value.split(" ");
String badStr = "'|and|exec|execute|insert|select|delete|update|count|drop|%|chr|mid|master|truncate|" +
"char|declare|sitename|net user|xp_cmdshell|;|or|-|+|,|like'|and|exec|execute|insert|create|drop|" +
"table|from|grant|use|group_concat|column_name|" +
"information_schema.columns|table_schema|union|where|select|delete|update|order|by|count|" +
"chr|mid|master|truncate|char|declare|or|;|-|--|,|like|//|/|%|#";
String[] badStrs = badStr.split("\\|");
for (int i = 0;i<badStrs.length;i++){
for (int j = 0;j<values.length;j++){
if (values[j].equalsIgnoreCase(badStrs[i])){
values[j] = "forbid";
}
}
}
StringBuilder sb = new StringBuilder();
for (int i = 0;i<values.length;i++){
if (i == values.length-1){
sb.append(values[i]);
if (values[j].equalsIgnoreCase(badStrs[i])){
values[j] = "forbid";
}
}
}
StringBuilder sb = new StringBuilder();
for (int i = 0;i<values.length;i++){
if (i == values.length-1){
sb.append(values[i]);
} else {
sb.append(values[i]+" ");
}
}
value = sb.toString();
return value;
}
}
/**
*/
@Controller
@RequestMapping("/department")
public class DepartmentController {