基于 Python 的高校学生职业推荐系统的设计与实现
开发环境
开发语言:Python 框架:django Python版本:python3.7.7 数据库:mysql 5.7(一定要5.7版本)
数据库工具:Navicat11 开发软件:PyCharm 浏览器:谷歌浏览器后台路径地址:localhost:8080/项目名称/admin/dist/index.html
前台路径地址:localhost:8080/项目名称/front/dist/index.html (无前台不需要输入)管理员账号:admin 管理员密码:admin
开发技术简介
PYTHON语言简介
Python是由荷兰数学和计算机研究学会的吉多•范罗苏姆于20世纪90年代设计的一款高级语言。Python优雅的语法和动态类型,以及解释型语言的本质,使它成为许多领域脚本编写和快速开发应用的首选语言。Python相比与其他高级语言,开发代码量较小,代码风格简洁优雅,拥有丰富的第三方库。Python的代码风格导致其可读性好,便于维护人员阅读维护,程序更加健壮。Python能够轻松地调用其他语言编写的模块,因此也被成为“胶水语言”。
Python的应用场合非常广泛,在科研领域中,可以用Python训练人工智能模型,也可以对实验数据进行数据分析。在生活中,Python提供了很多优秀的、开源的Web开发框架,例如Django、Flask、Pyramid、Tornado等。知乎、豆瓣网、Youtube等知名应用都是由Python为基础进行开发的。相比于其他框架,Django有着更加丰富的插件,作为企业级框架也很好上手,适合本次开发。此系统是开发一个Web应用,采用Django框架,将在下一节进行具体介绍。本次开发选用的是Python3.6.4版本。
MySql数据库
MySql数据库具有轻便、稳定等特点,在系统的工程中对相关的数据操作,很好的保障数据的稳定,极大程度上减低了系统开发的时间。
MySql数据库支持多线程工作,能充分利用系统的资源,更具有效率且数据库连接也有对于的不同模式接口;MySql存储小、运行稳定并且对使用的要求不高。
利用MySql建立系统数据库,利于对系统的数据处理早期的整合,可以更好的发展后数据的扩展实际操作[3]。 Mysql数据库的特点如下:
(1)Mysql是相比于Oracle更轻量、更简洁便于使用,在服务部署方面相对复杂度低,更利于毕设系统的开发。
(2)支持多种操作系统包括AIX、FreeBSD、HP-UX、Linux和Mac OS、Novell‘s
Netware、OpenBSD系统、OS/2卷、Solaris、Windows等。
(3)查询速度快。算法优化了查询语句,可靠地提高了搜索速度。 (4)Mysql可以使用Sql语言进行调用,学习成本较低。
(5)Mysql可支持互联网站数据共享也支持数据安全设置,防止数据泄露。
(6)高度非过程化。在访问数据库时,没有必要一步一步向计算机发送指令去完成任务,只需要用MySQL语句描述并且命令就可以了,数据库会自动完成全部工作。
DJANGO框架
Django被官方称之为“完美主义者框架”,只需要很少的代码就能更快的完成一个优秀的Web应用[4]。Django采用了MTV框架模式,此模式根据MVC进行改进形成了更适于Django的设计模式。M为模型(Model)、T为模板(Template)、V为视图(View)。下面介绍部分Django的核心与优点:
(1)对象关系映射(ORM,Object-Relation-Mapping):ORM的方法论有着三个核心原则: ①
简单:以最基本的形式构建数据。 ② 传达性:数据库结构被任何人都能理解的语言文档化。 ③ 精确性:基于数据模型创建正确标准化的结构。
用于Python之中即是以Python类形式定义数据模型,类中的每一个属性对应着数据库中的一列。引入ORM后,无需编写原生SQL语句,使用基于面向对象的思想去编写类、对象、调用方法等,ORM会将其映射成SQL语句通过pymysql执行。
(2)路由配置(URLConf):Django的URL设置更加灵活优雅,看似复杂难懂,但使用的都是简单的正则表达式,你可以随心所欲的创造优美的、简洁的、专业
的地址。
(3)模板(Template):模板可以理解为承载数据的工具,为了将数据从视图中分离出来,通过各种各样的标签来进行数据的传输。Django的模板融入了面向对象中继承的思想,提高了复用减少冗余代码。
(4)视图(View):视图就是views.py中的函数,也就是逻辑代码,为了将URL和视图关联起来,用到了上述的URLConfs,URLConfs将URL模式映射到视图中,每个视图有两件事是必须要做的:返回一个包含被请求页面的HttpResponse对象,或者抛出一个异常。
(5)后台管理系统(Django-Admin):Django提供的一个基于Web的管理工具。
Django-Admin来自django.contrib也就是Django的标准库,默认被配置好,只需要激活启用即可,它的优势在于可以快速对数据库的各个表进行增删改查,一行代码即可管理一张数据库表,相比于手动后台1个模型一般需要4个urls,4个视图函数和4个模板,可以说Django完成了一个程序编写的大部分重复工作,并且对于图书管理这种以管理工作为重系统来说,极度契合。
(6)应用(Application):当项目规模过大时,难免会产生目录过长,文件过多的问题,Django理念中的App可以将项目相对独立的进行开发,插拔的工作方式和独立性让开发者废弃的App即使删除也不会影响整体,是一种不可多得的理念。
因为本次使用的Python版本为3.6.4,低版本的Django不支持Python3,故此次使用的Django版本为3.2.12。
Hadoop介绍
Hadoop实现了一个分布式文件系统(Hadoop Distributed File
System),简称HDFS。HDFS有高容错性的特点,并且设计用来部署在低廉的(low-cost)硬件上;而且它提供高吞吐量(high
throughput)来访问应用程序的数据,适合那些有着超大数据集(large data
set)的应用程序。HDFS放宽了(relax)POSIX的要求,可以以流的形式访问(streaming access)文件系统中的数据。
Hadoop的框架最核心的设计就是:HDFS和MapReduce。HDFS为海量的数据提供了存储,而MapReduce则为海量的数据提供了计算。主要有以下优点:
(1)高可靠性。Hadoop按位存储和处理数据的能力值得人们信赖。
(2)高扩展性。Hadoop是在可用的计算机集簇间分配数据并完成计算任务的,这些集簇可以方便地扩展到数以千计的节点中。
(3)高效性。Hadoop能够在节点之间动态地移动数据,并保证各个节点的动态平衡,因此处理速度非常快。高容错性。Hadoop能够自动保存数据的多个副本,并且能够自动将失败的任务重新分配。
(4)低成本。与一体机、商用数据仓库以及QlikView、Yonghong
Z-Suite等数据集市相比,hadoop是开源的,项目的软件成本因此会大大降低。
Scrapy介绍
Scrapy是一个抓取网站数据和提取结构化数据的框架,它可以应用在广泛的应用中:Scrapy通常用于一系列应用,包括数据挖掘、信息处理或存储历史数据。使用Scrapy框架实现一个爬虫程序通常非常简单,抓取给定网站的内容或图像。
虽然Scrapy是为屏幕抓取(或者更准确地说是网页抓取)而设计的,但它也可以用于访问api以提取数据。
B/S架构
Browser/Server简称(B/S),即:浏览器/服务器架构模式;属于WEB发展后的所出现的一种网络构造,而WEB又是主要的浏览器应用商品软件。B/S架构模式不仅将系统的重新开发、维修及利用等简单化,更将其重点放到了服务器上。它使客户端得到了统一,在服务器上汇集了系统功能的最核心部分。
B/S架构模式,在服务器接收到浏览器发出请求后将进行对应的回应。Internet上文本、图片、动画等信息主要由Web服务器产生,而用户主要是通过浏览器访问这些信息。在Web上下载程序时遇到某些和数据库相关的指令,可以将这些指令转接到数据库服务器来进行解释和执行。
系统功能效果




核心代码
package com.controller;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.annotation.IgnoreAuth;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.entity.ConfigEntity;
import com.entity.EIException;
import com.service.ConfigService;
import com.utils.R;
/**
* 上传文件映射表
*/
@RestController
@RequestMapping("file")
@SuppressWarnings({"unchecked","rawtypes"})
public class FileController{
@Autowired
private ConfigService configService;
/**
* 上传文件
*/
@RequestMapping("/upload")
@IgnoreAuth
public R upload(@RequestParam("file") MultipartFile file,String type) throws Exception {
if (file.isEmpty()) {
throw new EIException("上传文件不能为空");
}
String fileExt = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")+1);
File path = new File(ResourceUtils.getURL("classpath:static").getPath());
if(!path.exists()) {
path = new File("");
}
File upload = new File(path.getAbsolutePath(),"/upload/");
if(!upload.exists()) {
upload.mkdirs();
}
String fileName = new Date().getTime()+"."+fileExt;
File dest = new File(upload.getAbsolutePath()+"/"+fileName);
file.transferTo(dest);
/**
* 如果使用idea或者eclipse重启项目,发现之前上传的图片或者文件丢失,将下面一行代码注释打开
* 请将以下的"D:\\springbootq33sd\\src\\main\\resources\\static\\upload"替换成你本地项目的upload路径,
* 并且项目路径不能存在中文、空格等特殊字符
*/
// FileUtils.copyFile(dest, new File("D:\\springbootq33sd\\src\\main\\resources\\static\\upload"+"/"+fileName)); /**修改了路径以后请将该行最前面的//注释去掉**/
if(StringUtils.isNotBlank(type) && type.equals("1")) {
ConfigEntity configEntity = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "faceFile"));
if(configEntity==null) {
configEntity = new ConfigEntity();
configEntity.setName("faceFile");
configEntity.setValue(fileName);
} else {
configEntity.setValue(fileName);
}
configService.insertOrUpdate(configEntity);
}
return R.ok().put("file", fileName);
}
/**
* 下载文件
*/
@IgnoreAuth
@RequestMapping("/download")
public ResponseEntity<byte[]> download(@RequestParam String fileName) {
try {
File path = new File(ResourceUtils.getURL("classpath:static").getPath());
if(!path.exists()) {
path = new File("");
}
File upload = new File(path.getAbsolutePath(),"/upload/");
if(!upload.exists()) {
upload.mkdirs();
}
File file = new File(upload.getAbsolutePath()+"/"+fileName);
if(file.exists()){
/*if(!fileService.canRead(file, SessionManager.getSessionUser())){
getResponse().sendError(403);
}*/
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
headers.setContentDispositionFormData("attachment", fileName);
return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),headers, HttpStatus.CREATED);
}
} catch (IOException e) {
e.printStackTrace();
}
return new ResponseEntity<byte[]>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
package com.controller;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import com.utils.ValidatorUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.annotation.IgnoreAuth;
import com.entity.ForumEntity;
import com.entity.view.ForumView;
import com.service.ForumService;
import com.service.TokenService;
import com.utils.PageUtils;
import com.utils.R;
import com.utils.MD5Util;
import com.utils.MPUtil;
import com.utils.CommonUtil;
import java.io.IOException;
/**
* 交流论坛
* 后端接口
* @author
* @email
* @date 2023-03-05 11:20:58
*/
@RestController
@RequestMapping("/forum")
public class ForumController {
@Autowired
private ForumService forumService;
/**
* 后端列表
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,ForumEntity forum,
HttpServletRequest request){
if(!request.getSession().getAttribute("role").toString().equals("管理员")) {
forum.setUserid((Long)request.getSession().getAttribute("userId"));
}
EntityWrapper<ForumEntity> ew = new EntityWrapper<ForumEntity>();
PageUtils page = forumService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, forum), params), params));
return R.ok().put("data", page);
}
/**
* 前端列表
*/
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,ForumEntity forum,
HttpServletRequest request){
if(!request.getSession().getAttribute("role").toString().equals("管理员")) {
forum.setUserid((Long)request.getSession().getAttribute("userId"));
}
EntityWrapper<ForumEntity> ew = new EntityWrapper<ForumEntity>();
PageUtils page = forumService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, forum), params), params));
return R.ok().put("data", page);
}
/**
* 列表
*/
@IgnoreAuth
@RequestMapping("/flist")
public R flist(@RequestParam Map<String, Object> params,ForumEntity forum, HttpServletRequest request){
EntityWrapper<ForumEntity> ew = new EntityWrapper<ForumEntity>();
PageUtils page = forumService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, forum), params), params));
return R.ok().put("data", page);
}
/**
* 查询
*/
@RequestMapping("/query")
public R query(ForumEntity forum){
EntityWrapper< ForumEntity> ew = new EntityWrapper< ForumEntity>();
ew.allEq(MPUtil.allEQMapPre( forum, "forum"));
ForumView forumView = forumService.selectView(ew);
return R.ok("查询交流论坛成功").put("data", forumView);
}
/**
* 后端详情
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
ForumEntity forum = forumService.selectById(id);
return R.ok().put("data", forum);
}
/**
* 前端详情
*/
@IgnoreAuth
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id){
ForumEntity forum = forumService.selectById(id);
return R.ok().put("data", forum);
}
/**
* 论坛详情
*/
@IgnoreAuth
@RequestMapping("/list/{id}")
public R list(@PathVariable("id") String id){
ForumEntity forum = forumService.selectById(id);
getChilds(forum);
return R.ok().put("data", forum);
}
private ForumEntity getChilds(ForumEntity forum) {
List<ForumEntity> childs = new ArrayList<ForumEntity>();
childs = forumService.selectList(new EntityWrapper<ForumEntity>().eq("parentid", forum.getId()));
if(childs == null || childs.size()==0) {
return null;
}
forum.setChilds(childs);
for(ForumEntity forumEntity : childs) {
getChilds(forumEntity);
}
return forum;
}
/**
* 后端保存
*/
@RequestMapping("/save")
public R save(@RequestBody ForumEntity forum, HttpServletRequest request){
forum.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(forum);
forum.setUserid((Long)request.getSession().getAttribute("userId"));
forumService.insert(forum);
return R.ok();
}
/**
* 前端保存
*/
@RequestMapping("/add")
public R add(@RequestBody ForumEntity forum, HttpServletRequest request){
forum.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(forum);
forum.setUserid((Long)request.getSession().getAttribute("userId"));
forumService.insert(forum);
return R.ok();
}
/**
* 修改
*/
@RequestMapping("/update")
@Transactional
public R update(@RequestBody ForumEntity forum, HttpServletRequest request){
//ValidatorUtils.validateEntity(forum);
forumService.updateById(forum);//全部更新
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
forumService.deleteBatchIds(Arrays.asList(ids));
return R.ok();
}
/**
* 提醒接口
*/
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
map.put("column", columnName);
map.put("type", type);
if(type.equals("2")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
Date remindStartDate = null;
Date remindEndDate = null;
if(map.get("remindstart")!=null) {
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindStart);
remindStartDate = c.getTime();
map.put("remindstart", sdf.format(remindStartDate));
}
if(map.get("remindend")!=null) {
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindEnd);
remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate));
}
}
Wrapper<ForumEntity> wrapper = new EntityWrapper<ForumEntity>();
if(map.get("remindstart")!=null) {
wrapper.ge(columnName, map.get("remindstart"));
}
if(map.get("remindend")!=null) {
wrapper.le(columnName, map.get("remindend"));
}
int count = forumService.selectCount(wrapper);
return R.ok().put("count", count);
}
}
系统功能测试
本系统首先在本地服务器上进行了安装和测试,之后鉴于对系统的结构和处理方法的充分熟悉和对系统特性的充分了解,对系统进行了白盒测试和黑盒试验。
在发展软件系统的整个过程中,人们必须面临错综复杂性的实际问题,所以,在软件系统生存周期的各个过程中都必然地会形成错误。应用软件检测目的在于:出现出错并运行某个程序的步骤,而应用软件检测的最重要目的便是找到其中尚未发生的出错。
为了制定出合理的测试计划,根据以下原则开始了测量;任何测试都要追溯到客户需要;当确定了客户使用模型后就要着手制定测试计划,并在编码以前就对整个软件测试工作做出规划和制定;御用Pareto原理,主要对占出了百分之八十九以上的最易于出错的约百分之二十的模板实施了检测,并从小规模开始逐步实施大量检测,范围一般从主要检测单编程模板再到完全集成的模板;同时精心设计了检测方法,尽可能地全面覆盖所有程序逻辑并使其满足要求的能力。
结论
本系统相对于我查阅到的其他高校学生职业推荐系统具有如下优点:其功能全面、易于日后程序更新、数据库管理容易、界面友好、操作方便、效率高、安全性好。
本系统在技术层面具有如下优点:第一,用java实现动态页面,使软件系统具备了很好的可维护性和可复用性。其次,在本系统的编写流程中使用的是Spring Boot框架,该框架将更有效的把显示功能与逻辑分开,使得模块更易于管理,尤其适用于大型项目的编写。第三,后台使用的MySQL数据库系统,MySQL的数据库系统引擎主要集中在了对XML标准的支持,同时具备可扩充、容易应用和安全性高的优点。
综上所述,通过这次从零开始的毕业设计是一次全新的开始,也期待圆满结束。我也希望这次的设计能通过我后期的自主学习把它趋向于完美,成为我的自主创作经验。
更多推荐

所有评论(0)