🍊作者:计算机编程-吉哥
🍊简介:专业从事JavaWeb程序开发,微信小程序开发,定制化项目、 源码、代码讲解、文档撰写、ppt制作。做自己喜欢的事,生活就是快乐的。
🍊心愿:点赞 👍 收藏 ⭐评论 📝
🍅 文末获取源码联系👇🏻 精彩专栏推荐订阅 👇🏻 不然下次找不到哟~
Java毕业设计项目~热门选题推荐《1000套》
目录
1.技术选型
2.数据库表结构
3.开发工具
4.功能
4.1【角色】
4.2【前台功能模块】
4.3【后台功能模块】
5.项目演示截图
5.1 首页
5.2 课程信息
5.3 在线答题
5.4 答题内容
5.5 个人中心
5.6 登录
5.7 课程学习管理
5.8 答卷管理
5.9 试题管理
5.10 论坛管理
6.数据库文件设计
7.核心代码
7.1 职业介绍Controller
7.2 职业介绍Service
7.3 职业介绍ServiceImpl
8.参考文档
1.技术选型
springboot、mybatisplus、vue、elementui、html、css、js、mysql、jdk1.8
2.数据库表结构
16张
3.开发工具
idea、navicat、vscode
4.功能
4.1【角色】
管理员、用户
4.2【前台功能模块】
- 登录注册
- 首页
- 在线答疑
- 论坛
- 公告信息
- 课程学习
- 职业介绍
- 个人中心
- 后台管理
4.3【后台功能模块】
- 登录
- 首页
- 个人中心
- 管理员管理
- 用户管理
- 课程学习管理
- 职业介绍管理
- 答卷管理
- 试题管理
- 答题管理
- 基础数据管理
- 论坛管理
- 公告信息管理
- 轮播图信息管理
5.项目演示截图
5.1 首页
5.2 课程信息
5.3 在线答题
5.4 答题内容
5.5 个人中心
5.6 登录
5.7 课程学习管理
5.8 答卷管理
5.9 试题管理
5.10 论坛管理
6.数据库文件设计
CREATE TABLE `config` (`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',`name` varchar(100) DEFAULT NULL COMMENT '配置参数名称',`value` varchar(100) DEFAULT NULL COMMENT '配置参数值',PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='配置文件';CREATE TABLE `dictionary` (`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',`dic_code` varchar(200) DEFAULT NULL COMMENT '字段',`dic_name` varchar(200) DEFAULT NULL COMMENT '字段名',`code_index` int(11) DEFAULT NULL COMMENT '编码',`index_name` varchar(200) DEFAULT NULL COMMENT '编码名字 Search111 ',`super_id` int(11) DEFAULT NULL COMMENT '父字段id',`beizhu` varchar(200) DEFAULT NULL COMMENT '备注',`create_time` timestamp NULL DEFAULT NULL COMMENT '创建时间',PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8 COMMENT='字典';CREATE TABLE `exampaper` (`id` int(20) NOT NULL AUTO_INCREMENT COMMENT '主键',`exampaper_name` varchar(200) NOT NULL COMMENT '试卷名称 Search111',`exampaper_date` int(11) DEFAULT NULL COMMENT '考试时长(分钟)',`exampaper_myscore` int(20) NOT NULL DEFAULT '0' COMMENT '试卷总分数',`kemu_types` int(11) DEFAULT NULL COMMENT '科目 Search111',`exampaper_types` int(11) NOT NULL DEFAULT '0' COMMENT '试卷状态 Search111',`zujuan_types` int(11) DEFAULT NULL COMMENT '组卷方式',`exampaper_delete` int(255) DEFAULT '0' COMMENT '逻辑删除(1代表未删除 2代表已删除)',`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间 show2 photoShow',PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COMMENT='试卷表';CREATE TABLE `exampapertopic` (`id` int(20) NOT NULL AUTO_INCREMENT COMMENT '主键',`exampaper_id` int(20) NOT NULL COMMENT '试卷',`examquestion_id` int(20) NOT NULL COMMENT '试题',`exampapertopic_number` int(20) NOT NULL COMMENT '试题分数',`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=47 DEFAULT CHARSET=utf8 COMMENT='试卷选题';CREATE TABLE `examquestion` (`id` int(20) NOT NULL AUTO_INCREMENT COMMENT '主键',`examquestion_name` varchar(200) NOT NULL COMMENT '试题名称 Search111',`kemu_types` int(11) DEFAULT NULL COMMENT '科目 Search111',`examquestion_options` longtext COMMENT '选项,json字符串',`examquestion_answer` varchar(200) DEFAULT NULL COMMENT '正确答案',`examquestion_analysis` longtext COMMENT '答案解析',`examquestion_types` int(20) DEFAULT '0' COMMENT '试题类型',`examquestion_sequence` int(20) DEFAULT '100' COMMENT '试题排序,值越大排越前面',`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8 COMMENT='试题表';CREATE TABLE `examrecord` (`id` int(20) NOT NULL AUTO_INCREMENT COMMENT '主键',`examrecord_uuid_number` varchar(200) DEFAULT NULL COMMENT '考试编号',`yonghu_id` int(20) NOT NULL COMMENT '考试学生',`exampaper_id` int(20) NOT NULL COMMENT '所属试卷id(外键)',`total_score` int(200) DEFAULT NULL COMMENT '所得总分',`insert_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '考试时间',`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='考试记录表';CREATE TABLE `examredetails` (`id` int(20) NOT NULL AUTO_INCREMENT COMMENT '主键',`examredetails_uuid_number` varchar(200) DEFAULT NULL COMMENT '试卷编号',`yonghu_id` int(20) NOT NULL COMMENT '学生id',`examquestion_id` int(20) NOT NULL COMMENT '试题id(外键)',`examredetails_myanswer` varchar(200) DEFAULT NULL COMMENT '考生答案',`examredetails_myscore` int(20) NOT NULL DEFAULT '0' COMMENT '试题得分',`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8 COMMENT='答题详情表';CREATE TABLE `forum` (`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',`forum_name` varchar(200) DEFAULT NULL COMMENT '帖子标题 Search111 ',`yonghu_id` int(11) DEFAULT NULL COMMENT '用户',`users_id` int(11) DEFAULT NULL COMMENT '管理员',`forum_content` text COMMENT '发布内容',`super_ids` int(11) DEFAULT NULL COMMENT '父id',`forum_state_types` int(11) DEFAULT NULL COMMENT '帖子状态',`insert_time` timestamp NULL DEFAULT NULL COMMENT '发帖时间',`update_time` timestamp NULL DEFAULT NULL COMMENT '修改时间',`create_time` timestamp NULL DEFAULT NULL COMMENT '创建时间 show2',PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8 COMMENT='论坛';CREATE TABLE `news` (`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',`news_name` varchar(200) DEFAULT NULL COMMENT '公告标题 Search111 ',`news_types` int(11) DEFAULT NULL COMMENT '公告类型 Search111 ',`news_photo` varchar(200) DEFAULT NULL COMMENT '公告图片',`insert_time` timestamp NULL DEFAULT NULL COMMENT '添加时间',`news_content` text COMMENT '公告详情',`create_time` timestamp NULL DEFAULT NULL COMMENT '创建时间 show1 show2 nameShow',PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 COMMENT='公告信息';CREATE TABLE `token` (`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',`userid` bigint(20) NOT NULL COMMENT '用户id',`username` varchar(100) NOT NULL COMMENT '用户名',`tablename` varchar(100) DEFAULT NULL COMMENT '表名',`role` varchar(100) DEFAULT NULL COMMENT '角色',`token` varchar(200) NOT NULL COMMENT '密码',`addtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '新增时间',`expiratedtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '过期时间',PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COMMENT='token表';CREATE TABLE `users` (`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',`username` varchar(100) NOT NULL COMMENT '用户名',`password` varchar(100) NOT NULL COMMENT '密码',`role` varchar(100) DEFAULT '管理员' COMMENT '角色',`addtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '新增时间',PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='管理员';CREATE TABLE `xuexishipin` (`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键 ',`xuexishipin_name` varchar(200) DEFAULT NULL COMMENT '课程名称 Search111 ',`xuexishipin_photo` varchar(200) DEFAULT NULL COMMENT '课程封面',`xuexishipin_video` varchar(255) DEFAULT NULL COMMENT '学习视频',`xuexishipin_types` int(11) DEFAULT NULL COMMENT '课程类型 Search111',`zhiyejieshao_types` int(11) DEFAULT NULL COMMENT '职业 Search111',`xuexishipin_content` text COMMENT '课程详情 ',`xuexishipin_delete` int(11) DEFAULT NULL COMMENT '逻辑删除',`insert_time` timestamp NULL DEFAULT NULL COMMENT '添加时间',`create_time` timestamp NULL DEFAULT NULL COMMENT '创建时间 show1 show2 photoShow',PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 COMMENT='课程学习';CREATE TABLE `xuexishipin_collection` (`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',`xuexishipin_id` int(11) DEFAULT NULL COMMENT '课程',`yonghu_id` int(11) DEFAULT NULL COMMENT '用户',`xuexishipin_collection_types` int(11) DEFAULT NULL COMMENT '类型',`insert_time` timestamp NULL DEFAULT NULL COMMENT '收藏时间',`create_time` timestamp NULL DEFAULT NULL COMMENT '创建时间 show3 photoShow',PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8 COMMENT='课程收藏';CREATE TABLE `yonghu` (`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',`username` varchar(200) DEFAULT NULL COMMENT '账户',`password` varchar(200) DEFAULT NULL COMMENT '密码',`yonghu_name` varchar(200) DEFAULT NULL COMMENT '用户姓名 Search111 ',`yonghu_photo` varchar(255) DEFAULT NULL COMMENT '头像',`yonghu_phone` varchar(200) DEFAULT NULL COMMENT '用户手机号',`yonghu_id_number` varchar(200) DEFAULT NULL COMMENT '用户身份证号 ',`sex_types` int(11) DEFAULT NULL COMMENT '性别 Search111 ',`yonghu_email` varchar(200) DEFAULT NULL COMMENT '邮箱',`yonghu_delete` int(11) DEFAULT '1' COMMENT '假删',`create_time` timestamp NULL DEFAULT NULL COMMENT '创建时间',PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='用户';CREATE TABLE `zhiyejieshao` (`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键 ',`zhiyejieshao_name` varchar(200) DEFAULT NULL COMMENT '职业名称 Search111 ',`zhiyejieshao_photo` varchar(200) DEFAULT NULL COMMENT '职业封面',`zhiyejieshao_types` int(11) DEFAULT NULL COMMENT '职业 Search111',`zhiyejieshao_content` text COMMENT '职业详情 ',`zhiyejieshao_delete` int(11) DEFAULT NULL COMMENT '逻辑删除',`insert_time` timestamp NULL DEFAULT NULL COMMENT '添加时间',`create_time` timestamp NULL DEFAULT NULL COMMENT '创建时间 show1 show2 photoShow',PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 COMMENT='职业介绍';CREATE TABLE `zhiyejieshao_collection` (`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',`zhiyejieshao_id` int(11) DEFAULT NULL COMMENT '职业介绍',`yonghu_id` int(11) DEFAULT NULL COMMENT '用户',`zhiyejieshao_collection_types` int(11) DEFAULT NULL COMMENT '类型',`insert_time` timestamp NULL DEFAULT NULL COMMENT '收藏时间',`create_time` timestamp NULL DEFAULT NULL COMMENT '创建时间 show3 photoShow',PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 COMMENT='职业介绍收藏';
7.核心代码
7.1 职业介绍Controller
package com.controller;import java.io.File;
import java.math.BigDecimal;
import java.net.URL;
import java.text.SimpleDateFormat;
import com.alibaba.fastjson.JSONObject;
import java.util.*;
import org.springframework.beans.BeanUtils;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.ContextLoader;
import javax.servlet.ServletContext;
import com.service.TokenService;
import com.utils.*;
import java.lang.reflect.InvocationTargetException;import com.service.DictionaryService;
import org.apache.commons.lang3.StringUtils;
import com.annotation.IgnoreAuth;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.entity.*;
import com.entity.view.*;
import com.service.*;
import com.utils.PageUtils;
import com.utils.R;
import com.alibaba.fastjson.*;/*** 职业介绍* 后端接口* @author 计算机编程-吉哥* @email
*/
@RestController
@Controller
@RequestMapping("/zhiyejieshao")
public class ZhiyejieshaoController {private static final Logger logger = LoggerFactory.getLogger(ZhiyejieshaoController.class);private static final String TABLE_NAME = "zhiyejieshao";@Autowiredprivate ZhiyejieshaoService zhiyejieshaoService;@Autowiredprivate TokenService tokenService;@Autowiredprivate DictionaryService dictionaryService;//字典@Autowiredprivate ExampaperService exampaperService;//试卷表@Autowiredprivate ExampapertopicService exampapertopicService;//试卷选题@Autowiredprivate ExamquestionService examquestionService;//试题表@Autowiredprivate ExamrecordService examrecordService;//答题记录表@Autowiredprivate ExamredetailsService examredetailsService;//答题详情表@Autowiredprivate ForumService forumService;//论坛@Autowiredprivate NewsService newsService;//公告信息@Autowiredprivate XuexishipinService xuexishipinService;//课程学习@Autowiredprivate XuexishipinCollectionService xuexishipinCollectionService;//课程收藏@Autowiredprivate YonghuService yonghuService;//用户@Autowiredprivate ZhiyejieshaoCollectionService zhiyejieshaoCollectionService;//职业介绍收藏@Autowiredprivate UsersService usersService;//管理员/*** 后端列表*/@RequestMapping("/page")public R page(@RequestParam Map<String, Object> params, HttpServletRequest request){logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));String role = String.valueOf(request.getSession().getAttribute("role"));if(false)return R.error(511,"永不会进入");else if("用户".equals(role))params.put("yonghuId",request.getSession().getAttribute("userId"));params.put("zhiyejieshaoDeleteStart",1);params.put("zhiyejieshaoDeleteEnd",1);CommonUtil.checkMap(params);PageUtils page = zhiyejieshaoService.queryPage(params);//字典表数据转换List<ZhiyejieshaoView> list =(List<ZhiyejieshaoView>)page.getList();for(ZhiyejieshaoView c:list){//修改对应字典表字段dictionaryService.dictionaryConvert(c, request);}return R.ok().put("data", page);}/*** 后端详情*/@RequestMapping("/info/{id}")public R info(@PathVariable("id") Long id, HttpServletRequest request){logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);ZhiyejieshaoEntity zhiyejieshao = zhiyejieshaoService.selectById(id);if(zhiyejieshao !=null){//entity转viewZhiyejieshaoView view = new ZhiyejieshaoView();BeanUtils.copyProperties( zhiyejieshao , view );//把实体数据重构到view中//修改对应字典表字段dictionaryService.dictionaryConvert(view, request);return R.ok().put("data", view);}else {return R.error(511,"查不到数据");}}/*** 后端保存*/@RequestMapping("/save")public R save(@RequestBody ZhiyejieshaoEntity zhiyejieshao, HttpServletRequest request){logger.debug("save方法:,,Controller:{},,zhiyejieshao:{}",this.getClass().getName(),zhiyejieshao.toString());String role = String.valueOf(request.getSession().getAttribute("role"));if(false)return R.error(511,"永远不会进入");Wrapper<ZhiyejieshaoEntity> queryWrapper = new EntityWrapper<ZhiyejieshaoEntity>().eq("zhiyejieshao_name", zhiyejieshao.getZhiyejieshaoName()).eq("zhiyejieshao_types", zhiyejieshao.getZhiyejieshaoTypes()).eq("zhiyejieshao_delete", zhiyejieshao.getZhiyejieshaoDelete());logger.info("sql语句:"+queryWrapper.getSqlSegment());ZhiyejieshaoEntity zhiyejieshaoEntity = zhiyejieshaoService.selectOne(queryWrapper);if(zhiyejieshaoEntity==null){zhiyejieshao.setZhiyejieshaoDelete(1);zhiyejieshao.setInsertTime(new Date());zhiyejieshao.setCreateTime(new Date());zhiyejieshaoService.insert(zhiyejieshao);return R.ok();}else {return R.error(511,"表中有相同数据");}}/*** 后端修改*/@RequestMapping("/update")public R update(@RequestBody ZhiyejieshaoEntity zhiyejieshao, HttpServletRequest request) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, InstantiationException {logger.debug("update方法:,,Controller:{},,zhiyejieshao:{}",this.getClass().getName(),zhiyejieshao.toString());ZhiyejieshaoEntity oldZhiyejieshaoEntity = zhiyejieshaoService.selectById(zhiyejieshao.getId());//查询原先数据String role = String.valueOf(request.getSession().getAttribute("role"));if("".equals(zhiyejieshao.getZhiyejieshaoPhoto()) || "null".equals(zhiyejieshao.getZhiyejieshaoPhoto())){zhiyejieshao.setZhiyejieshaoPhoto(null);}zhiyejieshaoService.updateById(zhiyejieshao);//根据id更新return R.ok();}/*** 删除*/@RequestMapping("/delete")public R delete(@RequestBody Integer[] ids, HttpServletRequest request){logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());List<ZhiyejieshaoEntity> oldZhiyejieshaoList =zhiyejieshaoService.selectBatchIds(Arrays.asList(ids));//要删除的数据ArrayList<ZhiyejieshaoEntity> list = new ArrayList<>();for(Integer id:ids){ZhiyejieshaoEntity zhiyejieshaoEntity = new ZhiyejieshaoEntity();zhiyejieshaoEntity.setId(id);zhiyejieshaoEntity.setZhiyejieshaoDelete(2);list.add(zhiyejieshaoEntity);}if(list != null && list.size() >0){zhiyejieshaoService.updateBatchById(list);}return R.ok();}/*** 批量上传*/@RequestMapping("/batchInsert")public R save( String fileName, HttpServletRequest request){logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);Integer yonghuId = Integer.valueOf(String.valueOf(request.getSession().getAttribute("userId")));SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");try {List<ZhiyejieshaoEntity> zhiyejieshaoList = new ArrayList<>();//上传的东西Map<String, List<String>> seachFields= new HashMap<>();//要查询的字段Date date = new Date();int lastIndexOf = fileName.lastIndexOf(".");if(lastIndexOf == -1){return R.error(511,"该文件没有后缀");}else{String suffix = fileName.substring(lastIndexOf);if(!".xls".equals(suffix)){return R.error(511,"只支持后缀为xls的excel文件");}else{URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径File file = new File(resource.getFile());if(!file.exists()){return R.error(511,"找不到上传文件,请联系管理员");}else{List<List<String>> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件dataList.remove(0);//删除第一行,因为第一行是提示for(List<String> data:dataList){//循环ZhiyejieshaoEntity zhiyejieshaoEntity = new ZhiyejieshaoEntity();//把要查询是否重复的字段放入map中}//查询是否重复zhiyejieshaoService.insertBatch(zhiyejieshaoList);return R.ok();}}}}catch (Exception e){e.printStackTrace();return R.error(511,"批量插入数据异常,请联系管理员");}}/*** 个性推荐*/@IgnoreAuth@RequestMapping("/gexingtuijian")public R gexingtuijian(@RequestParam Map<String, Object> params, HttpServletRequest request){logger.debug("gexingtuijian方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));CommonUtil.checkMap(params);List<ZhiyejieshaoView> returnZhiyejieshaoViewList = new ArrayList<>();//查看收藏Map<String, Object> params1 = new HashMap<>(params);params1.put("sort","id");params1.put("yonghuId",request.getSession().getAttribute("userId"));PageUtils pageUtils = zhiyejieshaoCollectionService.queryPage(params1);List<ZhiyejieshaoCollectionView> collectionViewsList =(List<ZhiyejieshaoCollectionView>)pageUtils.getList();Map<Integer,Integer> typeMap=new HashMap<>();//购买的类型listfor(ZhiyejieshaoCollectionView collectionView:collectionViewsList){Integer zhiyejieshaoTypes = collectionView.getZhiyejieshaoTypes();if(typeMap.containsKey(zhiyejieshaoTypes)){typeMap.put(zhiyejieshaoTypes,typeMap.get(zhiyejieshaoTypes)+1);}else{typeMap.put(zhiyejieshaoTypes,1);}}List<Integer> typeList = new ArrayList<>();//排序后的有序的类型 按最多到最少typeMap.entrySet().stream().sorted((o1, o2) -> o2.getValue() - o1.getValue()).forEach(e -> typeList.add(e.getKey()));//排序Integer limit = Integer.valueOf(String.valueOf(params.get("limit")));for(Integer type:typeList){Map<String, Object> params2 = new HashMap<>(params);params2.put("zhiyejieshaoTypes",type);PageUtils pageUtils1 = zhiyejieshaoService.queryPage(params2);List<ZhiyejieshaoView> zhiyejieshaoViewList =(List<ZhiyejieshaoView>)pageUtils1.getList();returnZhiyejieshaoViewList.addAll(zhiyejieshaoViewList);if(returnZhiyejieshaoViewList.size()>= limit) break;//返回的推荐数量大于要的数量 跳出循环}//正常查询出来商品,用于补全推荐缺少的数据PageUtils page = zhiyejieshaoService.queryPage(params);if(returnZhiyejieshaoViewList.size()<limit){//返回数量还是小于要求数量int toAddNum = limit - returnZhiyejieshaoViewList.size();//要添加的数量List<ZhiyejieshaoView> zhiyejieshaoViewList =(List<ZhiyejieshaoView>)page.getList();for(ZhiyejieshaoView zhiyejieshaoView:zhiyejieshaoViewList){Boolean addFlag = true;for(ZhiyejieshaoView returnZhiyejieshaoView:returnZhiyejieshaoViewList){if(returnZhiyejieshaoView.getId().intValue() ==zhiyejieshaoView.getId().intValue()) addFlag=false;//返回的数据中已存在此商品}if(addFlag){toAddNum=toAddNum-1;returnZhiyejieshaoViewList.add(zhiyejieshaoView);if(toAddNum==0) break;//够数量了}}}else {returnZhiyejieshaoViewList = returnZhiyejieshaoViewList.subList(0, limit);}for(ZhiyejieshaoView c:returnZhiyejieshaoViewList)dictionaryService.dictionaryConvert(c, request);page.setList(returnZhiyejieshaoViewList);return R.ok().put("data", page);}/*** 前端列表*/@IgnoreAuth@RequestMapping("/list")public R list(@RequestParam Map<String, Object> params, HttpServletRequest request){logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));CommonUtil.checkMap(params);PageUtils page = zhiyejieshaoService.queryPage(params);//字典表数据转换List<ZhiyejieshaoView> list =(List<ZhiyejieshaoView>)page.getList();for(ZhiyejieshaoView c:list)dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段return R.ok().put("data", page);}/*** 前端详情*/@RequestMapping("/detail/{id}")public R detail(@PathVariable("id") Long id, HttpServletRequest request){logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id);ZhiyejieshaoEntity zhiyejieshao = zhiyejieshaoService.selectById(id);if(zhiyejieshao !=null){//entity转viewZhiyejieshaoView view = new ZhiyejieshaoView();BeanUtils.copyProperties( zhiyejieshao , view );//把实体数据重构到view中//修改对应字典表字段dictionaryService.dictionaryConvert(view, request);return R.ok().put("data", view);}else {return R.error(511,"查不到数据");}}/*** 前端保存*/@RequestMapping("/add")public R add(@RequestBody ZhiyejieshaoEntity zhiyejieshao, HttpServletRequest request){logger.debug("add方法:,,Controller:{},,zhiyejieshao:{}",this.getClass().getName(),zhiyejieshao.toString());Wrapper<ZhiyejieshaoEntity> queryWrapper = new EntityWrapper<ZhiyejieshaoEntity>().eq("zhiyejieshao_name", zhiyejieshao.getZhiyejieshaoName()).eq("zhiyejieshao_types", zhiyejieshao.getZhiyejieshaoTypes()).eq("zhiyejieshao_delete", zhiyejieshao.getZhiyejieshaoDelete())
// .notIn("zhiyejieshao_types", new Integer[]{102});logger.info("sql语句:"+queryWrapper.getSqlSegment());ZhiyejieshaoEntity zhiyejieshaoEntity = zhiyejieshaoService.selectOne(queryWrapper);if(zhiyejieshaoEntity==null){zhiyejieshao.setZhiyejieshaoDelete(1);zhiyejieshao.setInsertTime(new Date());zhiyejieshao.setCreateTime(new Date());zhiyejieshaoService.insert(zhiyejieshao);return R.ok();}else {return R.error(511,"表中有相同数据");}}}
7.2 职业介绍Service
package com.service;import com.baomidou.mybatisplus.service.IService;
import com.utils.PageUtils;
import com.entity.ZhiyejieshaoEntity;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.lang.Nullable;
import java.util.List;/*** 职业介绍 服务类*/
public interface ZhiyejieshaoService extends IService<ZhiyejieshaoEntity> {/*** @param params 查询参数* @return 带分页的查询出来的数据*/PageUtils queryPage(Map<String, Object> params);}
7.3 职业介绍ServiceImpl
package com.service.impl;import com.utils.StringUtil;
import com.service.DictionaryService;
import com.utils.ClazzDiff;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.lang.reflect.Field;
import java.util.*;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;
import com.utils.PageUtils;
import com.utils.Query;
import org.springframework.web.context.ContextLoader;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import com.dao.ZhiyejieshaoDao;
import com.entity.ZhiyejieshaoEntity;
import com.service.ZhiyejieshaoService;
import com.entity.view.ZhiyejieshaoView;/*** 职业介绍 服务实现类*/
@Service("zhiyejieshaoService")
@Transactional
public class ZhiyejieshaoServiceImpl extends ServiceImpl<ZhiyejieshaoDao, ZhiyejieshaoEntity> implements ZhiyejieshaoService {@Overridepublic PageUtils queryPage(Map<String,Object> params) {Page<ZhiyejieshaoView> page =new Query<ZhiyejieshaoView>(params).getPage();page.setRecords(baseMapper.selectListView(page,params));return new PageUtils(page);}}
8.参考文档
你可能还有感兴趣的项目👇🏻👇🏻👇🏻
更多项目推荐:计算机毕业设计项目
如果大家有任何疑虑,请在下方咨询或评论