Java项目:在线小说阅读系统(前后端分离+java+vue+Springboot+ssm+mysql+maven+redis)

news/2024/7/10 2:40:41 标签: java, mysql, springboot, vue, spring

源码获取:博客首页 "资源" 里下载!

一、项目简述

本系统功能包括: 普通用户端登录注册,小说的分类,日榜,月榜,年榜, 小说的阅读,分章节,小说的评论,收藏,推荐等等,以 及后台小说的维护,上架,编辑等等。

二、项目运行 

环境配置: Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX (Webstorm也 行)+ Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts都支 持)。

项目技术: Springboot + Maven + Mybatis + Vue + Redis, B/S 模式+ Maven等等

商品分类控制器:

@RestController
@RequestMapping("/api/category")
@Api(tags = "共同前缀:/api/category", description = "CategoryController")
@Slf4j
public class CategoryController {

	@Autowired
	CategoryService categoryService;

	@PostMapping
	@ApiOperation("新增Category")
	@PreAuthorize("hasAnyAuthority('ROLE_ADMIN')")
	public ResponseObject post(@RequestBody Category category) {
		log.info("新增Category");
		if (category.getId() != null) {
			throw new ControllerException("id必须为null");
		} else if (category.getRank() == null) {
			throw new ControllerException("rank不可为null");
		} else if (category.getName() == null || category.getName().equals("")) {
			throw new ControllerException("name不可为null,也不可为空字符串");
		} else if (category.getParent_id() == null) {
			throw new ControllerException("parent_id不可为null");
		} else if (categoryService.selectByParent_idName(category.getParent_id(), category.getName()) != null) {
			throw new ControllerException("name不可重复");
		} else {
			return new ResponseObject("200", "操作成功", categoryService.insert(category));
		}
	}

	@PutMapping("/{id:[0-9]+}")
	@ApiOperation("修改Category")
	@PreAuthorize("hasAnyAuthority('ROLE_ADMIN')")
	public ResponseObject putById(@PathVariable Integer id, @RequestBody HashMap<String, String> data) {
		log.info("修改Category");
		Category category = categoryService.selectById(id);
		if (category == null) {
			throw new ControllerException("使用该id的Category不存在");
		} else if (categoryService.selectByParent_idName(category.getParent_id(), data.get("name")) != null) {
			throw new ControllerException("同一个分类下的name不可重复");
		} else {
			category.setName(data.get("name"));
			return new ResponseObject("200", "操作成功", categoryService.update(category));
		}
	}

	@GetMapping
	@ApiOperation("查询Category")
	public ResponseObject getByParent_id(Integer rank, Integer parent_id) {
		log.info("查询Category");
		if (rank != null && parent_id != null) {
			return new ResponseObject("200", "操作成功", categoryService.selectByRankParent_id(rank, parent_id));
		} else if (rank != null && parent_id == null) {
			return new ResponseObject("200", "操作成功", categoryService.selectByRank(rank));
		} else if (rank == null && parent_id != null) {
			return new ResponseObject("200", "操作成功", categoryService.selectByParent_id(parent_id));
		} else {
			throw new ControllerException("rank或者parent_id至少要有一个不为null");
		}
	}

	@GetMapping("/{id:[0-9]+}")
	@ApiOperation("查询Category")
	public ResponseObject getById(@PathVariable Integer id) {
		log.info("查询Category");
		if (id != null) {
			return new ResponseObject("200", "操作成功", categoryService.selectById(id));
		} else {
			throw new ControllerException("id不可为null");
		}
	}

}

用户信息控制器:

@RestController
@RequestMapping("/api/user")
@Api(tags = "共同前缀:/api/user", description = "UserController")
@Slf4j
public class UserController {

	@Autowired
	UserService userService;

	@PostMapping
	@ApiOperation("新增User")
	public ResponseObject post(String username, String password) {
		log.info("新增User");
		if (username == null || username.equals("")) {
			throw new ControllerException("username不可为null,也不可为空字符串");
		} else if (password == null || password.equals("")) {
			throw new ControllerException("password不可为null,也不可为空字符串");
		} else if (userService.selectByUsername(username) != null) {
			throw new ControllerException("该username已被使用");
		} else {
			User user = new User();
			user.setUsername(username);
			user.setPassword(password);
			user.setRole("VIP1");
			user.setNickname(new Date().getTime() + "");
			user.setImage("default_user_image.png");
			user.setEmail("该用户没有填写邮箱");
			user.setPhone("该用户没有填写手机号码");
			user.setProfile("该用户没有填写个人简介");
			return new ResponseObject("200", "操作成功", userService.insert(user));
		}
	}

	@GetMapping("/{id:[0-9]+}")
	@ApiOperation("查询User")
	public ResponseObject getById(@PathVariable Integer id) {
		log.info("查询User");
		return new ResponseObject("200", "操作成功", userService.selectById(id));
	}

	@PutMapping
	@ApiOperation("修改User")
	@PreAuthorize("isAuthenticated()")
	public ResponseObject put(User user) {
		log.info("修改User");
		if (user.getNickname() == null || user.getNickname().equals("")) {
			throw new ControllerException("nickname不可为null,也不可为空字符串");
		} else if (user.getProfile() == null || user.getProfile().equals("")) {
			throw new ControllerException("profile不可为null,也不可为空字符串");
		} else if (user.getPhone() == null || user.getPhone().equals("")) {
			throw new ControllerException("phone不可为null,也不可为空字符串");
		} else if (user.getEmail() == null || user.getEmail().equals("")) {
			throw new ControllerException("email不可为null,也不可为空字符串");
		} else {
			User user2 = userService
					.selectByUsername((String) SecurityContextHolder.getContext().getAuthentication().getPrincipal());
			user2.setNickname(user.getNickname());
			user2.setProfile(user.getProfile());
			user2.setPhone(user.getPhone());
			user2.setEmail(user.getEmail());
			return new ResponseObject("200", "操作成功", userService.update(user2));
		}
	}

}

收藏控制器:

@RestController
@RequestMapping("/api/collection")
@Api(tags = "共同前缀:/api/collection", description = "CollectionController")
@Slf4j
public class CollectionController {
	@Autowired
	CollectionService collectionService;
	@Autowired
	UserService userService;
	@Autowired
	NovelService novelService;

	@PostMapping
	@ApiOperation("新增Collection")
	@PreAuthorize("isAuthenticated()")
	public ResponseObject post(Collection collection) {
		log.info("新增Collection");
		if (collection.getId() != null) {
			throw new ControllerException("id必须为null");
		} else if (collection.getNovel_id() == null) {
			throw new ControllerException("novel_id不可为null");
		} else {
			collection.setUser_id(userService
					.selectByUsername((String) SecurityContextHolder.getContext().getAuthentication().getPrincipal())
					.getId());
			if (collectionService.selectByUser_idNovel_id(collection.getUser_id(), collection.getNovel_id()) != null) {
				throw new ControllerException("该用户已经收藏过该小说了,不可重复收藏");
			} else {
				return new ResponseObject("200", "操作成功", collectionService.insert(collection));
			}
		}
	}

	@GetMapping
	@ApiOperation("查询Collection")
	public ResponseObject get(Integer novel_id, Integer user_id) {
		log.info("查询Collection");
		if (novel_id != null && user_id != null) {
			return new ResponseObject("200", "操作成功", collectionService.selectByUser_idNovel_id(user_id, novel_id));
		} else if (novel_id != null && user_id == null) {
			return new ResponseObject("200", "操作成功", collectionService.selectByNovel_id(novel_id));
		} else if (novel_id == null && user_id != null) {
			return new ResponseObject("200", "操作成功", collectionService.selectByUser_id(user_id));
		} else {
			throw new ControllerException("novel_id与user_id不可同时为null");
		}
	}

	@GetMapping("/novel")
	@ApiOperation("查询Collection的Novel")
	public ResponseObject getNovel(Integer user_id) {
		log.info("查询Collection的Novel");
		if (user_id == null) {
			throw new ControllerException("user_id不可为null");
		} else {
			return new ResponseObject("200", "操作成功", novelService.selectByUser_idOfCollection(user_id));
		}
	}

	@DeleteMapping
	@ApiOperation("删除Collection")
	@PreAuthorize("isAuthenticated()")
	public ResponseObject delete(Integer novel_id, Integer user_id) {
		log.info("删除Collection");
		if (novel_id == null) {
			throw new ControllerException("novel_id不可为null");
		} else if (user_id == null) {
			throw new ControllerException("user_id不可为null");
		} else {
			Collection collection = collectionService.selectByUser_idNovel_id(user_id, novel_id);
			if (collection == null) {
				throw new ControllerException("该用户还未收藏该小说,无法取消收藏");
			} else {
				User user = userService.selectByUsername(
						(String) SecurityContextHolder.getContext().getAuthentication().getPrincipal());
				if (user.getId() == user_id || user.getRole().equals("ADMIN")) {
					collectionService.deleteById(collection.getId());
					return new ResponseObject("200", "操作成功", null);
				} else {
					throw new ControllerException("该用户无权限取消收藏");
				}
			}
		}
	}

	@GetMapping("/count")
	@ApiOperation("查询Collection")
	public ResponseObject getCount(Integer novel_id) {
		log.info("查询Collection");
		if (novel_id == null) {
			throw new ControllerException("novel_id不可为null");
		} else {
			return new ResponseObject("200", "操作成功", collectionService.selectByNovel_id(novel_id).size());
		}
	}
}

源码获取:博客首页 "资源" 里下载!


http://www.niftyadmin.cn/n/1554549.html

相关文章

java 格式化日期 注解_理解和使用@DateTimeFormat和@JsonFormat注解

详细的理解参照https://blog.csdn.net/qq_28483283/article/details/81326365两者使用时,都要注意!自己想要的时间类型是什么样的,如果只是用到日期到天,那么格式就是(pattern”yyyy-MM-dd”),想要时分秒的话,那么就要加上HH:mm:ss,因为前后台都需要传数据,所以需要保持一致,否…

Java项目:仿小米商城系统(前后端分离+java+vue+Springboot+ssm+mysql+maven+redis)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 一、项目简述 本系统功能包括&#xff1a; 基于vue Springboot前后端分离项目精简版仿小米商城 系统&#xff0c;注册登录&#xff0c;首页展示&#xff0c;商品展示&#xff0c;商品购买&#xff0c;下单…

Java项目:个人博客系统(前后端分离+java+vue+Springboot+ssm+mysql+maven+redis)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 一、项目简述 本系统功能包括&#xff1a;文章展示、热门文章、文章分类、标签云用户登录评论、匿名评论用户留言、匿名留言评论管理、文章发布、文章管理文章数据统计等等&#xff0e; 二、项目运行 环境…

Java项目:员工管理系统(前后端分离+java+vue+Springboot+ssm+mysql+maven+redis)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 一、项目简述 本系统功能包括&#xff1a;分为前端翻后端部分&#xff0c;包括用户&#xff0c;区分晋通用户以及誉里员用户&#xff0c;包括首页展示&#xff0c;部门管理&#xff0c;人事管理&#xff0c…

Java 多线程抢占 编程_Java多线程编程

编写具有多线程能力的程序经常会用到的方法有&#xff1a;run(),start(),wait(),notify(),notifyAll(),sleep(),yield(),join()还有一个重要的关键字&#xff1a;synchronized本文将对以上内容进行讲解。一&#xff1a;run()和start()示例1&#xff1a;public class ThreadTest…

Java项目:进销存管理系统(前后端分离+java+vue+Springboot+ssm+mysql+maven+redis)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 一、项目简述 本系统功能包括&#xff1a; 库存管理&#xff0c;入库管理&#xff0c;出库管理&#xff0c;往来管理&#xff0c;基础资料, 系统管理&#xff0c;消息中心&#xff0c;系统监控等等。 二、…

java多元_Java多元运算符-WEB资讯专栏-DMOZ中文网站分类目录-免费收录各类优秀网站的中文网站目录....

虽然可以实现条件判断&#xff0c;但只能获取数字数据&#xff0c;而不能执行功能代码。2、流程控制语句又名&#xff1a;条件控制语句关键字&#xff1a; if 、 else包含以下几种方式&#xff1a;1、普通条件控制语句语法&#xff1a;if(条件判断语句){条件判断语句成立执行的…

Java项目:精美网上音乐平台(前后端分离+java+vue+Springboot+ssm+mysql+maven+redis)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 一、项目简述 本系统功能包括&#xff1a; 音乐播放 用户登录注册 用户信息编辑、头像修改 歌曲、歌单搜索 歌单打分 歌单、歌曲评论 歌单列表、歌手列表分页显示 歌词同步显不 音乐收藏、下载、拖动控制、…