大家好!我是岛上程序猿,感谢您阅读本文,欢迎一键三连哦。
💞当前专栏:Java毕业设计
精彩专栏推荐👇🏻👇🏻👇🏻
开发环境
开发语言:Java
框架:springboot
JDK版本:JDK1.8
服务器:tomcat7
数据库:mysql 5.7
数据库工具:Navicat12
开发软件:eclipse/myeclipse/idea
Maven包:Maven3.3.9
浏览器:谷歌浏览器
演示视频
springboot003线上阅读系统1演示
源码下载地址:
https://download.csdn.net/download/m0_46388260/88003187
论文目录
【如需全文请按文末获取联系】
目录
一、项目简介
我们使用Microsoft公司的JSP开发工具,使用MSSQL制作系统的数据库,结合JSP技术,做一个具有页面样式设计站内新闻,用户注册,在线留言,书籍查询,关于本站,用户登录,按类别查询,查看书籍简介,阅读书籍正文,插入书签用户添加/查看/修改自己书库,是小型的网上阅读平台。
二、系统设计
2.1软件功能模块设计
根据网站的开发,系统分以下三个模块,即管理模块、留言交流区
新闻浏览模块、书籍查询,可以将系统分解成几个功能模块来分别设计,功能模块之间关系如图:
2.2数据库设计
管理员:(帐号、密码)
实体图如下:
注册用户:(用户名、学号、姓名、性别、年龄、邮件地址、密码)
实体图如下:
站内新闻:(标题,内容,添加时间等)
实体图如下:
三、系统项目部分截图
3.1首页
首页界面划分清晰,功能明确。
页面左上角是本站的名称“网上阅读平台”,没有夸张难认的LOGO,明晰清楚。在其右侧是网站的功能导航栏,分别有“首页”、“站内新闻”、“用户注册”及“在线留言”。功能界定明确,没有错综复杂的关系。 “在线留言”是系统提供给读者进行读者间的交流及读者与系统管理员进行互动的平台。
页面左下角,分别是用户信息(未登陆时显示登陆界面,登陆后显示用户信息,用户注册界面的入口设置在此处)、系统公告及相关友情链接。
在此右侧,则是新书推荐及最新书籍的列表介绍界面。
3.2管理员登陆
在“用户名”和“密码”两个输入框中输入正确的信息后,方可安全登录网站后台。而为了安全考虑,不设注册,管理员帐号是在数据库内部设置的。
四、部分核心代码
4.1 用户部分
package com.zyy.book.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zyy.book.component.UserInterceptor;
import com.zyy.book.entity.*;
import com.zyy.book.exception.MyException;
import com.zyy.book.output.MyMsg;
import com.zyy.book.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.DigestUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Calendar;
import java.util.Date;
/**
* <p>
* 前端控制器
* </p>
*
* @author zyy
* @since 2021-02-23
*/
@RestController
@RequestMapping("/user")
public class UserController {
@Autowired
private IUserService userService;
@Autowired
private IOrderService orderService;
@Autowired
private IRechargeService rechargeService;
@Autowired
private IBookService bookService;
@Autowired
private IBookChapterService bookChapterService;
@RequestMapping(method = RequestMethod.GET, path = "/logout")
public void logout(HttpServletRequest request, HttpServletResponse response) throws IOException {
HttpSession session = request.getSession();
session.removeAttribute(UserInterceptor.USER_SESSION_KEY);
response.sendRedirect("/");
}
@RequestMapping(method = RequestMethod.GET, path = "/login")
public ModelAndView login() {
return new ModelAndView("home/user/login");
}
@RequestMapping(method = RequestMethod.POST, path = "/login")
public MyMsg loginPost(@RequestParam String username,
@RequestParam String password,
HttpServletRequest request) throws MyException {
QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
userQueryWrapper.eq("username", username);
User user = userService.getOne(userQueryWrapper);
if (user == null) {
throw new MyException("用户或密码不正确");
}
if (!user.getPassword().equals(DigestUtils.md5DigestAsHex(password.getBytes()))) {
throw new MyException("用户或密码不正确");
}
HttpSession session = request.getSession();
session.setAttribute(UserInterceptor.USER_SESSION_KEY, user);
/*更新时间*/
user.setUpdatedAt(LocalDateTime.now());
userService.saveOrUpdate(user);
return new MyMsg(MyMsg.SUCCESS, "登陆成功");
}
@RequestMapping(method = RequestMethod.GET, path = "/reg")
public ModelAndView reg() {
return new ModelAndView("home/user/reg");
}
@RequestMapping(method = RequestMethod.POST, path = "/reg")
public MyMsg regPost(@RequestBody User user) throws MyException {
if (!StringUtils.hasText(user.getUsername()) || !StringUtils.hasText(user.getPassword())) {
throw new MyException("用户名或密码不能为空");
}
QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
userQueryWrapper.eq("username", user.getUsername());
int count = userService.count(userQueryWrapper);
if (count > 0) {
throw new MyException("用户名已存在");
}
if (user.getPhone().length() != 11) {
throw new MyException("手机号码长度为11位");
}
user.setPassword(DigestUtils.md5DigestAsHex(user.getPassword().getBytes()));
user.setBalance(new BigDecimal(0));
boolean save = userService.save(user);
if (!save) {
throw new MyException("注册失败");
}
return new MyMsg(MyMsg.SUCCESS, "", user);
}
@RequestMapping(method = RequestMethod.GET, path = "/index")
public ModelAndView index() {
return new ModelAndView("home/user/index");
}
@RequestMapping(method = RequestMethod.POST, path = "/vip")
public MyMsg vip(HttpServletRequest request) throws MyException {
HttpSession session = request.getSession();
User user1 = (User) session.getAttribute(UserInterceptor.USER_SESSION_KEY);
User user = userService.getById(user1.getId());
if (user.getVipExpirationAt() != null && user.getVipExpirationAt().isAfter(LocalDateTime.now())) {
throw new MyException("会员未过期");
}
if (user.getBalance().compareTo(new BigDecimal(100)) < 0) {
throw new MyException("开通VIP余额不足 ¥" + User.VIP_PRICE);
}
user.setBalance(user.getBalance().subtract(new BigDecimal(User.VIP_PRICE)));
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.add(Calendar.YEAR, 1);
LocalDateTime localDateTime = LocalDateTime.ofInstant(calendar.toInstant(), ZoneOffset.systemDefault());
user.setVipExpirationAt(localDateTime);
userService.saveOrUpdate(user);
return new MyMsg(MyMsg.SUCCESS, "开通成功", user);
}
@RequestMapping(method = RequestMethod.GET, path = "/info")
public ModelAndView info(HttpServletRequest request) {
HttpSession session = request.getSession();
User user1 = (User) session.getAttribute(UserInterceptor.USER_SESSION_KEY);
User user = userService.getById(user1.getId());
return new ModelAndView("home/user/info", "user", user);
}
@RequestMapping(method = RequestMethod.POST, path = "/info")
public MyMsg infoPost(@RequestParam String gender,
@RequestParam String birthday,
@RequestParam String phone,
HttpServletRequest request) throws MyException, ParseException {
if (phone == null || phone.length() != 11) {
throw new MyException("手机号必须为11位");
}
HttpSession session = request.getSession();
User user1 = (User) session.getAttribute(UserInterceptor.USER_SESSION_KEY);
User user = userService.getById(user1.getId());
user.setGender(gender);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
user.setBirthday(simpleDateFormat.parse(birthday));
user.setPhone(phone);
userService.saveOrUpdate(user);
return new MyMsg(MyMsg.SUCCESS, "操作成功");
}
@RequestMapping(method = RequestMethod.GET, path = "/recharge")
public ModelAndView recharge(HttpServletRequest request) {
HttpSession session = request.getSession();
User user1 = (User) session.getAttribute(UserInterceptor.USER_SESSION_KEY);
User user = userService.getById(user1.getId());
ModelAndView view = new ModelAndView();
view.setViewName("home/user/recharge");
view.addObject("user", user);
view.addObject("vipPrice", User.VIP_PRICE);
return view;
}
@RequestMapping(method = RequestMethod.POST, path = "/recharge")
public MyMsg recharge(@RequestParam BigDecimal balance, HttpServletRequest request) throws MyException {
if (balance.compareTo(BigDecimal.ZERO) < 0) {
throw new MyException("金额必须大于0");
}
HttpSession session = request.getSession();
User user1 = (User) session.getAttribute(UserInterceptor.USER_SESSION_KEY);
User user = userService.getById(user1.getId());
if (user.getBalance() == null) {
user.setBalance(new BigDecimal(0));
}
BigDecimal newBalance = user.getBalance().add(balance);
user.setBalance(newBalance);
userService.saveOrUpdate(user);
/*log*/
Recharge recharge = new Recharge();
recharge.setAmount(balance);
recharge.setUserId(user.getId());
rechargeService.saveOrUpdate(recharge);
return new MyMsg(MyMsg.SUCCESS, "充值成功");
}
@RequestMapping(method = RequestMethod.GET, path = "/password")
public ModelAndView password() {
return new ModelAndView("home/user/password");
}
@RequestMapping(method = RequestMethod.POST, path = "/password")
public MyMsg passwordPost(@RequestParam String oldPassword,
@RequestParam String newPassword,
HttpServletRequest request) throws MyException {
if (!StringUtils.hasText(oldPassword) || !StringUtils.hasText(newPassword)) {
throw new MyException("密码不能为空");
}
HttpSession session = request.getSession();
User user1 = (User) session.getAttribute(UserInterceptor.USER_SESSION_KEY);
User user = userService.getById(user1.getId());
if (!user.getPassword().equals(DigestUtils.md5DigestAsHex(oldPassword.getBytes()))) {
throw new MyException("旧密码不正确");
}
user.setPassword(DigestUtils.md5DigestAsHex(newPassword.getBytes()));
userService.saveOrUpdate(user);
return new MyMsg(MyMsg.SUCCESS, "");
}
@RequestMapping(method = RequestMethod.GET, path = "/readRecord")
public ModelAndView readRecord() {
return new ModelAndView("home/user/readRecord");
}
@RequestMapping(method = RequestMethod.GET, path = "/read/bookChapter/{id}")
public ModelAndView read(@PathVariable String id, HttpServletRequest request) throws MyException {
HttpSession session = request.getSession();
User user1 = (User) session.getAttribute(UserInterceptor.USER_SESSION_KEY);
User user = userService.getById(user1.getId());
ModelAndView view = new ModelAndView();
view.setViewName("home/read/read");
BookChapter bookChapter = bookChapterService.getById(id);
if (bookChapter == null) {
throw new MyException("书籍不存在");
}
view.addObject("bookChapter", bookChapter);
Book book = bookService.getById(bookChapter.getBookId());
if (book == null) {
throw new MyException("书籍不存在");
}
view.addObject("book", book);
/*书藉非免费0, 非第一章节*/
if (book.getPrice() != null && book.getPrice().compareTo(BigDecimal.ZERO) > 0 && bookChapter.getIndex() != 1) {
QueryWrapper<Order> orderQueryWrapper = new QueryWrapper<>();
orderQueryWrapper.eq("user_id", user1.getId());
orderQueryWrapper.eq("book_id", book.getId());
int count = orderService.count(orderQueryWrapper);
/*未购买*/
if (count < 1) {
/*不是VIP或VIP到期*/
if (user.getVipExpirationAt() == null || user.getVipExpirationAt().isBefore(LocalDateTime.now())) {
throw new MyException("未购买,请到书籍详情下购买");
}
}
}
return view;
}
@RequestMapping(method = RequestMethod.POST, path = "/buy")
public MyMsg buy(@RequestParam Integer bookId, HttpServletRequest request) throws MyException {
Book book1 = bookService.getById(bookId);
if (book1 == null) {
throw new MyException("书籍不存在");
}
HttpSession session = request.getSession();
User user1 = (User) session.getAttribute(UserInterceptor.USER_SESSION_KEY);
QueryWrapper<Order> orderQueryWrapper = new QueryWrapper<>();
orderQueryWrapper.eq("user_id", user1.getId());
orderQueryWrapper.eq("book_id", bookId);
int count = orderService.count(orderQueryWrapper);
if (count > 0) {
throw new MyException("不能重复购买");
}
User user = userService.getById(user1.getId());
Book book = bookService.getById(bookId);
if (user.getBalance().compareTo(book.getPrice()) < 0) {
throw new MyException("余额不足");
}
user.setBalance(user.getBalance().subtract(book.getPrice()));
userService.saveOrUpdate(user);
Order order = new Order();
order.setUserId(user1.getId());
order.setBookId(bookId);
order.setAmount(book.getPrice());
orderService.saveOrUpdate(order);
return new MyMsg(MyMsg.SUCCESS, "购买成功", true);
}
@RequestMapping(method = RequestMethod.GET, path = "/isBuy/{bookId}")
public MyMsg isBuy(@PathVariable String bookId, HttpServletRequest request) {
HttpSession session = request.getSession();
User user1 = (User) session.getAttribute(UserInterceptor.USER_SESSION_KEY);
QueryWrapper<Order> orderQueryWrapper = new QueryWrapper<>();
orderQueryWrapper.eq("user_id", user1.getId());
orderQueryWrapper.eq("book_id", bookId);
int count = orderService.count(orderQueryWrapper);
boolean isBuy = false;
if (count > 0) {
isBuy = true;
}
return new MyMsg(MyMsg.SUCCESS, "", isBuy);
}
}
获取源码或论文
如需对应的论文或源码,也可以下方微信联系我