基于javaweb+mysql的springboot游戏资讯信息管理系统(java+springboot+vue+mybatis+maven+mysql)
运行环境
Java≥8、MySQL≥5.7、Node.js≥10
开发工具
后端:eclipse/idea/myeclipse/sts等均可配置运行
前端:WebStorm/VSCode/HBuilderX等均可
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot游戏资讯信息管理系统(java+springboot+vue+mybatis+maven+mysql)
一、项目运行 环境配置:
Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX(Webstorm也行)+ Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)。
项目技术:
Spring + SpringBoot+ mybatis + Maven + Vue 等等组成,B/S模式 + Maven管理等等。
/**
* @Description
*/
@RestController
@RequestMapping("comment")
public class CommentController {
@Resource
private CommentServiceImpl commentService;
@Resource
private UserServiceImpl userService;
@PostMapping("/insertNewComment")
@LoginRequired
public CommentVo insertNewComment(@RequestBody CommentTo commentTO) {
CommentVo commentVo = new CommentVo();
if (commentTO.getGameId() != null && commentTO.getNewsId() != null) {
//评论类型不能同时为评论文章和游戏
commentVo.setStatus(-1);
/**
* @Description
*/
@RestController
@RequestMapping("news")
@Slf4j
public class NewsInfoController {
@Resource
private NewsInfoServiceImpl newsInfoService;
@Resource
private UserCFUtil userCFUtil;
@GetMapping("/getNewestNewInfoList")
@PassToken
public NewsInfoVo getNewsInfoNewestList(int n) {
NewsInfoVo newsInfoVo = new NewsInfoVo();
newsInfoVo.setStatus(1);
//默认获取前n条
newsInfoVo.setNewsInfoList(newsInfoService.getNewsInfoNewestList(n));
return newsInfoVo;
}
@GetMapping("/getNewsInfoById")
@PassToken
public NewsInfoVo getNewsInfoById(long id) {
NewsInfoVo newsInfoVo = new NewsInfoVo();
NewsInfo newsInfo = newsInfoService.findById(id);
if (newsInfo != null) {
NewsType newsType = newsInfoService.findNewsTypeByTypeId(newsInfo.getType());
@GetMapping("/delComment")
@LoginRequired
public ResultVo delComment(Long id){
ResultVo resultVo = new ResultVo();
commentService.deleteById(id);
resultVo.setStatus(1);
return resultVo;
}
@GetMapping("/delGameType")
@LoginRequired
public ResultVo delGameType(Long id){
ResultVo resultVo = new ResultVo();
gameTypeService.deleteById(id);
resultVo.setStatus(1);
return resultVo;
}
@PostMapping("/insertGameType")
@LoginRequired
public ResultVo insertGameType(@RequestBody GameTypeTo gameTypeTo){
ResultVo resultVo = new ResultVo();
GameType gameType = new GameType();
gameType.setName(gameTypeTo.getName());
GameType gt = gameTypeService.saveOrUpdate(gameType);
if (gt != null){
resultVo.setStatus(1);
return resultVo;
}
resultVo.setStatus(-1);
return resultVo;
}
@PostMapping("/editGameType")
@LoginRequired
public ResultVo editGameType(@RequestBody GameTypeTo gameTypeTo){
ResultVo resultVo = new ResultVo();
GameType gameType = new GameType();
gameType.setName(gameTypeTo.getName());
gameType.setId(gameTypeTo.getId());
GameType gt = gameTypeService.saveOrUpdate(gameType);
/**
* @Description
*/
@RestController
@RequestMapping("gameType")
public class GameTypeController {
@Resource
private GameTypeServiceImpl gameTypeService;
@GetMapping("/resortGame")
@LoginRequired
public void resortGame(){
gameTypeService.resortGame();
}
@GetMapping("/getAll")
@PassToken
public GameTypeVo getAll(){
GameTypeVo gameTypeVo = new GameTypeVo();
gameTypeVo.setGameTypeList(gameTypeService.findAll());
gameTypeVo.setStatus(1);
return gameTypeVo;
}
}
if (c != null){
resultVo.setStatus(1);
return resultVo;
}
resultVo.setStatus(-1);
return resultVo;
}
@GetMapping("/delCarousel")
@LoginRequired
public ResultVo delCarousel(Long id){
ResultVo resultVo = new ResultVo();
carouselService.deleteById(id);
resultVo.setStatus(1);
return resultVo;
}
@GetMapping("/delNewsInfo")
@LoginRequired
public ResultVo delNewsInfo(Long id){
ResultVo resultVo = new ResultVo();
newsInfoService.deleteById(id);
resultVo.setStatus(1);
return resultVo;
}
@PostMapping("/insertNewsInfo")
@LoginRequired
public ResultVo insertNewsInfo(@RequestBody NewsInfoTo newsInfoTo){
ResultVo resultVo = new ResultVo();
NewsInfo newsInfo = new NewsInfo();
newsInfo.setLikeCounts(0L);
newsInfo.setContent(newsInfoTo.getContent());
newsInfo.setBanner(newsInfoTo.getBanner());
newsInfo.setImg(newsInfoTo.getImg());
newsInfo.setUpdateTime(new Date());
newsInfo.setTitle(newsInfoTo.getTitle());
newsInfo.setType(newsInfoTo.getType());
newsInfo.setAuthor(newsInfo.getAuthor());
newsInfo.setClickCounts(0L);
NewsInfo n = newsInfoService.saveOrUpdateNewsInfo(newsInfo);
if (n != null){
resultVo.setStatus(1);
return resultVo;
}
}
@GetMapping("/getGameInfoPage")
@LoginRequired
public Page<GameInfo> getGameInfoPage(int index, int size){
Pageable page = PageRequest.of(index, size);
return gameInfoService.findPage(page);
}
@GetMapping("/calculateGamesLike")
@LoginRequired
public List<GameInfo> calculateGamesLike(Long userId){
List<GameInfo> resultList = new ArrayList<>();
List<Long> ids = userCFUtil.calculateGameLike(userId);
if (ids == null) {
return resultList;
}
for (Long id : ids) {
GameInfo g = gameInfoService.getById(id);
resultList.add(g);
}
return resultList;
}
}
@GetMapping("/getSearchInfo")
@PassToken
public List<NameAndIdVo> getSearchInfo(String key){
return newsInfoService.getAllNewsInfoNameAndIdLikeTitle(key);
}
@GetMapping("/searchNewsInfos")
@PassToken
public NewsInfoVo searchNewsInfos(String key){
NewsInfoVo newsInfoVo = new NewsInfoVo();
List<NewsInfo> newsInfos = newsInfoService.getNewsInfosLikeTitle(key);
if (newsInfos != null){
newsInfoVo.setNewsInfoList(newsInfos);
newsInfoVo.setStatus(1);
return newsInfoVo;
}
newsInfoVo.setStatus(-1);
return newsInfoVo;
}
@GetMapping("/getNewsInfoByAuthor")
@LoginRequired
public List<NewsInfo> getNewsInfoByAuthor(String author){
return newsInfoService.getNewsInfosByAuthor(author);
}
@GetMapping("/setEditArticleId")
@LoginRequired
public void setEditArticleId(Long articleId, HttpServletRequest request){
HttpSession session = request.getSession();
session.setAttribute("editArticleId", articleId);
}
@PostMapping("/insertNewNewsInfo")
@LoginRequired
public ResultVo insertNewNewsInfo(@RequestBody NewsInfoTo newsInfoTo){
ResultVo resultVo = new ResultVo();
NewsInfo newsInfo = new NewsInfo();
newsInfo.setClickCounts(0L);
newsInfo.setLikeCounts(0L);
newsInfo.setAuthor(newsInfoTo.getAuthor());
newsInfo.setContent(newsInfoTo.getContent());
newsInfo.setBanner(newsInfoTo.getBanner());
newsInfo.setImg(newsInfoTo.getImg());
newsInfo.setTitle(newsInfoTo.getTitle());
newsInfo.setUpdateTime(new Date());
newsInfo.setType(newsInfoTo.getType());
NewsInfo result = newsInfoService.insertNewNewsInfo(newsInfo);
if (result != null){
resultVo.setStatus(1);
return resultVo;
}
resultVo.setStatus(-1);
});
for (Comment father : commentList) {
CommentVo fatherVO = new CommentVo();
Long userId = father.getUserId();
User user = userService.findUserById(userId);
fatherVO.copyProperty(father, user);
//子vo
List<CommentVo> childrenVo = new ArrayList<>();
//获取所有子评论
List<Comment> childrenList = father.getCommentChildren();
//按热度排序
childrenList.sort(new Comparator<Comment>() {
@Override
public int compare(Comment o1, Comment o2) {
Long likeCounts1 = o1.getLikeCounts();
Long likeCounts2 = o2.getLikeCounts();
if (likeCounts1 < likeCounts2) {
return 1;
} else if (likeCounts1.equals(likeCounts2)) {
return 0;
} else {
return -1;
}
}
});
for (Comment child : childrenList) {
CommentVo childVo = new CommentVo();
Long childUserId = child.getUserId();
User cuser = userService.findUserById(childUserId);
childVo.copyProperty(child, cuser);
childrenVo.add(childVo);
}
fatherVO.setCommentVOChildren(childrenVo);
commentVoList.add(fatherVO);
}
resultVo.setStatus(1);
resultVo.setCommentVOList(commentVoList);
return resultVo;
} else if (commentList != null && orderby == 2) {
//按时间排序
commentList.sort(new Comparator<Comment>() {
@Override
public int compare(Comment o1, Comment o2) {
Date date1 = o1.getTime();
Date date2 = o2.getTime();
return Long.compare(date2.getTime(), date1.getTime());
newsInfoVo.setStatus(1);
return newsInfoVo;
}
newsInfoVo.setStatus(-1);
return newsInfoVo;
}
@GetMapping("/getNewsInfoByAuthor")
@LoginRequired
public List<NewsInfo> getNewsInfoByAuthor(String author){
return newsInfoService.getNewsInfosByAuthor(author);
}
@GetMapping("/setEditArticleId")
@LoginRequired
public void setEditArticleId(Long articleId, HttpServletRequest request){
HttpSession session = request.getSession();
session.setAttribute("editArticleId", articleId);
}
@PostMapping("/insertNewNewsInfo")
@LoginRequired
public ResultVo insertNewNewsInfo(@RequestBody NewsInfoTo newsInfoTo){
ResultVo resultVo = new ResultVo();
NewsInfo newsInfo = new NewsInfo();
newsInfo.setClickCounts(0L);
newsInfo.setLikeCounts(0L);
newsInfo.setAuthor(newsInfoTo.getAuthor());
newsInfo.setContent(newsInfoTo.getContent());
newsInfo.setBanner(newsInfoTo.getBanner());
newsInfo.setImg(newsInfoTo.getImg());
newsInfo.setTitle(newsInfoTo.getTitle());
newsInfo.setUpdateTime(new Date());
newsInfo.setType(newsInfoTo.getType());
NewsInfo result = newsInfoService.insertNewNewsInfo(newsInfo);
if (result != null){
resultVo.setStatus(1);
return resultVo;
}
resultVo.setStatus(-1);
return resultVo;
}
@PostMapping("/editNewsInfo")
@LoginRequired
public ResultVo editNewsInfo(@RequestBody NewsInfoTo newsInfoTo){
ResultVo resultVo = new ResultVo();
NewsInfo newsInfo = newsInfoService.findById(newsInfoTo.getId());
if (newsInfo != null){
//更新数据
newsInfo.setType(newsInfoTo.getType());
newsInfo.setUpdateTime(new Date());
newsInfo.setTitle(newsInfoTo.getTitle());
newsInfo.setImg(newsInfoTo.getImg());
ResultVo resultVo = new ResultVo();
GameType gameType = new GameType();
gameType.setName(gameTypeTo.getName());
gameType.setId(gameTypeTo.getId());
GameType gt = gameTypeService.saveOrUpdate(gameType);
if (gt != null){
resultVo.setStatus(1);
return resultVo;
}
resultVo.setStatus(-1);
return resultVo;
}
@GetMapping("/delNewsType")
@LoginRequired
public ResultVo delNewsType(Long id){
ResultVo resultVo = new ResultVo();
newsInfoService.deleteNewsTypeById(id);
resultVo.setStatus(1);
return resultVo;
}
@PostMapping("/insertNewsInfoType")
@LoginRequired
public ResultVo insertNewsInfoType(@RequestBody NewsInfoTypeTo newsInfoTypeTo){
ResultVo resultVo = new ResultVo();
NewsType newsType = new NewsType();
newsType.setName(newsInfoTypeTo.getName());
NewsType nt = newsInfoService.saveOrUpdateNewsInfoType(newsType);
if (nt != null){
resultVo.setStatus(1);
return resultVo;
}
resultVo.setStatus(-1);
return resultVo;
}
@PostMapping("/editNewsInfoType")
@LoginRequired
public ResultVo editNewsInfoType(@RequestBody NewsInfoTypeTo newsInfoTypeTo){
resultVo.setStatus(1);
return resultVo;
}
@GetMapping("/findPage")
@LoginRequired
public Page<Comment> findPage(int index, int size){
Pageable pageable = PageRequest.of(index, size);
return commentService.findPage(pageable);
}
}
/**
* @Description
*/
@RestController
@RequestMapping("news")
int typeId = newsInfo.getType();
NewsType newsType = newsInfoService.findNewsTypeByTypeId(typeId);
NewsInfoVo infoVo = new NewsInfoVo();
infoVo.copyProperty(newsInfo, newsType);
resultList.add(infoVo);
}
result.setNewsInfoVoList(resultList);
result.setStatus(1);
return result;
}
result.setStatus(-1);
msg.put("msg", "未查询到文章信息");
result.setDataValue(msg);
return result;
}
@GetMapping("/getAllNewsType")
@PassToken
public NewsTypeVo getAllNewsType() {
NewsTypeVo newsTypeVo = new NewsTypeVo();
Map<String, Object> msg = new HashMap<>();
List<NewsType> newsTypes = newsInfoService.findAllNewsTypes();
if (newsTypes != null && newsTypes.size() > 0){
newsTypeVo.setNewsTypeList(newsTypes);
newsTypeVo.setStatus(1);
return newsTypeVo;
}
newsTypeVo.setStatus(-1);
msg.put("msg", "未查询到文章类型");
newsTypeVo.setDataValue(msg);
return newsTypeVo;
}
@GetMapping("/getNewInfosByTypeId")
@PassToken
public NewsInfoVo getNewInfosByTypeId(int typeId) {
NewsInfoVo newsInfoVo = new NewsInfoVo();
List<NewsInfoVo> newsInfoVoList = new ArrayList<>();
List<NewsInfo> newsInfos = newsInfoService.getNewsByTypeId(typeId);
if (newsInfos != null && newsInfos.size() > 0){
for (NewsInfo newsInfo : newsInfos) {
//获取每篇文章的类型信息
NewsType newsType = newsInfoService.findNewsTypeByTypeId(typeId);
NewsInfoVo infoVo = new NewsInfoVo();
infoVo.copyProperty(newsInfo, newsType);
newsInfoVoList.add(infoVo);
}
newsInfoVo.setStatus(1);
newsInfoVo.setNewsInfoVoList(newsInfoVoList);
/**
* @Description
*/
@RestController
@RequestMapping("login")
public class LoginController {
@Resource
private LoginServiceImpl loginService;
@Resource
private UserRepository userRepository;
@Resource
private UserFriendRepository userFriendRepository;
@PostMapping("/userLogin")
@PassToken
public UserTokenVo userLogin(@RequestBody UserLoginTo userLoginTo, HttpServletRequest request) {
UserTokenVo userTokenVo = new UserTokenVo();
HttpSession session = request.getSession();
User u = userRepository.findByUsername(userLoginTo.getUsername());
if (u != null) {
UserTokenVo vo = loginService.userLogin(userLoginTo.getUsername(), userLoginTo.getPassword());
if (vo.getStatus() == 1){
//登录成功
//保存信息到session中
session.setAttribute("username", u.getUsername());
session.setAttribute("userId", u.getId());
session.setAttribute("isAdmin", u.isAdmin());
return vo;
}
}
Map<String, Object> map = new HashMap<>();
map.put("msg", "用户名或密码错误");
userTokenVo.setDataValue(map);
userTokenVo.setStatus(-1);
return userTokenVo;
return resultVo;
}
Long likeCount = comment.getLikeCounts();
Long disLikeCount = comment.getDontLikeCounts();
Boolean isLike = userCommentTO.getIsLike(); //是点赞还是点踩
if (userCommentLike == null) {
//初次点赞或点踩
UserCommentLike commentLike = new UserCommentLike();
commentLike.setUserId(userId);
commentLike.setCommentId(commentId);
if (isLike) {
//点赞
commentLike.setIsLike(true);
commentLike.setIsDislike(false);
UserCommentLike u = commentService.insertUserCommentLike(commentLike);
if (u != null) {
//增加点赞数
commentService.updateLikeCountsById(likeCount + 1, commentId);
} else {
msg.put("msg", "服务出错");
}
} else {
//点踩
commentLike.setIsLike(false);
commentLike.setIsDislike(true);
UserCommentLike u = commentService.insertUserCommentLike(commentLike);
if (u != null) {
//增加点踩数
commentService.updateDislikeCountsById(disLikeCount + 1, commentId);
} else {
msg.put("msg", "服务出错");
}
}
resultVo.setStatus(1);
resultVo.setDataValue(msg);
} else {
//已有记录的情况下,不能重复操作
if (userCommentLike.getIsLike() && isLike) {
//已赞不能重复赞
resultVo.setStatus(-1);
msg.put("msg", "已经点过赞,不能重复点赞");
} else if (userCommentLike.getIsDislike() && !isLike) {
resultVo.setStatus(-1);
msg.put("msg", "已经点过踩,不能重复点踩");
} else {
//更新该用户对该条评论的踩赞信息
int r1 = commentService.updateLikeTrue(isLike, commentId, userId);
int r2 = commentService.updateDislikeTrue(!isLike, commentId, userId);
if (r1 > 0 && r2 > 0) {
@Override
public int compare(Comment o1, Comment o2) {
Date date1 = o1.getTime();
Date date2 = o2.getTime();
return Long.compare(date2.getTime(), date1.getTime());
}
});
for (Comment child : childrenList) {
CommentVo childVo = new CommentVo();
Long childUserId = child.getUserId();
User cuser = userService.findUserById(childUserId);
childVo.copyProperty(child, cuser);
childrenVo.add(childVo);
}
fatherVO.setCommentVOChildren(childrenVo);
commentVoList.add(fatherVO);
}
resultVo.setStatus(1);
resultVo.setCommentVOList(commentVoList);
return resultVo;
}
resultVo.setStatus(-1);
return resultVo;
}
@PostMapping("/getUserComment")
@LoginRequired
public UserCommentLikeVo findByCommentIdAndUserId(@RequestBody UserCommentTo userCommentTO) {
UserCommentLikeVo userCommentLikeVo = new UserCommentLikeVo();
userCommentLikeVo.setStatus(-1);
UserCommentLike userCommentLike = commentService.findByCommentIdAndUserId(userCommentTO.getCommentId(), userCommentTO.getUserId());
if (userCommentLike != null) {
userCommentLikeVo.setStatus(1);
userCommentLikeVo.copyProperty(userCommentLike);
}
return userCommentLikeVo;
}
@PostMapping("/updateLikeTrue")
@LoginRequired
public ResultVo updateLikeTrue(@RequestBody UserCommentTo userCommentTO) {
ResultVo resultVo = new ResultVo();
resultVo.setStatus(-1);
Map<String, Object> msg = new HashMap<>();
Long commentId = userCommentTO.getCommentId();
Long userId = userCommentTO.getUserId();
/**
* @Description
*/
@RestController
@RequestMapping("gameType")
public class GameTypeController {
@Resource
private GameTypeServiceImpl gameTypeService;
@GetMapping("/resortGame")
@LoginRequired
public void resortGame(){
gameTypeService.resortGame();
}
@GetMapping("/getAll")
@PassToken
public GameTypeVo getAll(){
GameTypeVo gameTypeVo = new GameTypeVo();
gameTypeVo.setGameTypeList(gameTypeService.findAll());
gameTypeVo.setStatus(1);
return gameTypeVo;
}
}
/**
* @Description
if (nowUserId.equals(userId)){
Map<String, Object> msg = new HashMap<>();
msg.put("msg", "您不能对自己的账号进行该操作");
resultVo.setDataValue(msg);
resultVo.setStatus(-1);
return resultVo;
}
int result = userService.setAdmin(isAdmin, userId);
if (result > 0){
resultVo.setStatus(1);
return resultVo;
}
resultVo.setStatus(-1);
return resultVo;
}
}
@Resource
private GameTypeServiceImpl gameTypeService;
@Resource
private UserCFUtil userCFUtil;
@RequestMapping("/uploadHeadIconUrl")
@PassToken
public ResultVo uploadHeadIconUrl(@RequestParam("file") MultipartFile url, HttpServletRequest request) {
ResultVo resultVo = new ResultVo();
Map<String, Object> map = new HashMap<>();
MultipartConfigFactory factory = new MultipartConfigFactory();
factory.setMaxFileSize(DataSize.of(1, DataUnit.MEGABYTES));
//最多接收2mb大小的文件
HttpSession session = request.getSession();
//存放到项目的target目录中
//部署到服务器上需要修改地址
String outFilePath = "D:\\gitee\\GameInformationRecommendationSystem\\target\\classes\\static\\userIcon";
if (session.getAttribute("username") == null ||
session.getAttribute("userId") == null) {
map.put("msg", "未登录");
resultVo.setStatus(-1);
} else {
if (!url.isEmpty()) {
try {
String savePath = "http://localhost:8088/userIcon";
String fileName = (String) session.getAttribute("username") + session.getAttribute("userId") + ".png";
File targetFile = new File(outFilePath, fileName);
savePath = savePath + "/" + fileName;
log.info("用户: " + session.getAttribute("username") + ",上传头像路径: " + savePath);
//将图片url存入数据库
userService.uploadHeadIconUrl(savePath, (Long) session.getAttribute("userId"));
if (!targetFile.exists()) {
targetFile.mkdirs();
}
// 转存文件
url.transferTo(targetFile);
map.put("msg", "上传成功");
resultVo.setStatus(1);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("上传头像出错");
}
}
}
resultVo.setDataValue(map);