java

关注公众号 jb51net

关闭
首页 > 软件编程 > java > Java 小说在线阅读系统

Java 实战项目之小说在线阅读系统的实现流程

作者:qq_1334611189

读万卷书不如行万里路,只学书上的理论是远远不够的,只有在实战中才能获得能力的提升,本篇文章手把手带你用java+SSM+jsp+mysql+maven实现前台阅读后台管理的小说在线阅读系统,大家可以在过程中查缺补漏,提升水平

一、项目简述

功能包括(管理员和游客角色):

1:用户及主要操作功能 游客可以浏览网站的主页,但是需要注册为会员后部分小 说才能对网络小说进免费行阅读或阅读。用户可以收藏书 架,留言评论,上次阅读,阅读历史,章节选择等等功 能。

2:管理模块 网络小说管理模块包括不同网络小说类别的添加,删除以 及网络小说的上传,删除管理。可以包括武侠小书,都市 言情,穿越小书等各个类等等功能。

二、项目运行

环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)

项目技术: JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax等等。

读者操作业务控制层:

@Controller
public class ReaderController {
    @Autowired
    private ReaderService readerService;
 
 
    @RequestMapping("/duzhe")
    public String duzhe(){
        return "loginreader";
    }
 
    @RequestMapping("/book/getByType?bookType=1")
    public String xiangqing(){
        return "front/personal";
    }
 
 
 
    /**
     * 登陆操作
     * @return
     */
    @RequestMapping("/loginreader")
    @ResponseBody
 
        public ResultData login1(Reader reader,HttpServletRequest request){
            // 登陆操作
            ResultData resultData = readerService.login1(reader);
            // 判断登陆成功,将用户数据保存到 session中
            // 如何获取session对象?
            if(resultData.getCode() == 200){
                HttpSession session = request.getSession();
                session.setAttribute("reader",resultData.getData());
            }
 
            return resultData;
        }
 
 
   @RequestMapping("/loginOut")
   @ResponseBody
 
       public String loginOut(HttpServletRequest request){
	   // 只需要去将保存到session的数据干掉即可
       request.getSession().setAttribute("reader",null);
 
       // 重定向和转发的区别?
       // 重定向: 1. 客户端行为 2. 两次请求 3. 不能携带前一次请求的数据
       // 转发: 1. 服务器端行为 2. 一次请求 3. 能够携带前一次请求的数据
       return "redirect:/loginPage";
       }
 
//    @RequestMapping("/login")
//    @ResponseBody// 该方法返回的是json字符串
//    public ResultData login(Admin admin,HttpServletRequest request){
//        // 登陆操作
//        ResultData resultData = adminService.login(admin);
//        // 判断登陆成功,将用户数据保存到 session中
//        // 如何获取session对象?
//        if(resultData.getCode() == 200){
//            HttpSession session = request.getSession();
//            session.setAttribute("admin",resultData.getData());
//        }
//
//        return resultData;
//    }
//
    //读者列表
    @RequestMapping("/reader/list")
    public String list(Model model,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "5") Integer pageSize){
 
 
        PageInfo<Reader> pageInfo = readerService.list(page,pageSize);
 
 
 
        model.addAttribute("list",pageInfo.getList());
        model.addAttribute("pageInfo",pageInfo);
 
        return "reader/reader-list";
    }
 
    //搜索读者显示列表
    @RequestMapping("/reader/search")
    public String searchList(Model model,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "5") Integer pageSize,
                             String keyword){
 
        PageInfo<Reader> pageInfo = readerService.searchList(page, pageSize, keyword);
        model.addAttribute("list",pageInfo.getList());
        model.addAttribute("pageInfo",pageInfo);
 
        return "reader/reader-list";
    }
 
    //读者删除列表
    @RequestMapping("/reader/deleteList")
    public String deleteList(Model model,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "5") Integer pageSize){
 
        PageInfo<Reader> pageInfo = readerService.DeleteList(page,pageSize);
        model.addAttribute("list",pageInfo.getList());
        model.addAttribute("pageInfo",pageInfo);
        return "reader/reader-del";
    }
 
    //添加读者
    @RequestMapping("/reader/addPage")
    public String addPage(){
        return "front/register";
    }
 
 
//    添加读者的方法
    @RequestMapping("/reader/add")
    @ResponseBody
    public ResultData add(Reader reader){
        return readerService.add(reader);
    }
 
    /**
     * 编辑读者状态信息
     * @param readerId : 当前读者Id
     * @param readerStatus: 读者当前状态
     * @return
     */
    @RequestMapping("/reader/editStatus")
    @ResponseBody
    public ResultData editStatus(Integer readerId, Integer readerStatus){
        return readerService.updateStatus(readerId, readerStatus);
    }
 
    /**
     * 编辑读者
     * @param
     * @param
     * @return
     */
    @RequestMapping("/reader/editPage")
    public String editPage(Model model, Integer readerId){
        Reader dbreadder = readerService.findById(readerId);
        model.addAttribute("reader",dbreadder);
        return "reader/reader-edit";
    }
 
    /**
     * 更新读者基本信息的方法
     * @param reader
     * @return
     */
    @RequestMapping("/reader/edit")
    @ResponseBody
    public ResultData edit(Reader reader){
        return readerService.edit(reader);
    }
 
    /**
     * 批量删除
     * @param ids
     * @return
     */
    @RequestMapping("/reader/deleteAll")
    @ResponseBody
    public ResultData deleteAll(@RequestParam(name = "ids") String ids){
//        将ids转换成数组
        String[] idArr=ids.split(",");
        return readerService.batchDelete(idArr);
    };
 
    /**
     * 批量恢复
     * @param ids
     * @return
     */
    @RequestMapping("/reader/huifuAll")
    @ResponseBody
    public ResultData huifuDelete(@RequestParam(name = "ids") String ids){
//        将ids转换成数组
        String[] idArr=ids.split(",");
        return readerService.huifuDelete(idArr);
    };
 
    @RequestMapping("/reader/delete")
    @ResponseBody
    public ResultData deleteReader(Integer readerId, Integer readerStatus){
        return readerService.deletereader(readerId,readerStatus);
    }
 
 
 
    @RequestMapping("/reader/toCenter")
    public String toCenter(HttpSession session, Model model){
//         Reader reader = (Reader)session.getAttribute("reader");
//        if(reader==null){
//            return  "login";
//        }
        Reader reader = readerService.findById(1 );
        model.addAttribute("reader",reader);
        return "front/center";
    }
 
 
 
}

留言信息控制层:

@Controller
public class MessageController {
    @Autowired
    private MessageService messageService;
 
    @Autowired
    private BookService bookService;
 
    @RequestMapping("/message/list")
    public String list(Model model,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "5") Integer pageSize){
 
        PageInfo<Message> pageInfo=messageService.list(page,pageSize);
 
 
//将数据转发到页面
        model.addAttribute("list",pageInfo.getList());
        model.addAttribute("pageInfo",pageInfo);
 
 
        return "message/message-list";
    }
    @RequestMapping("/message/addMessage")
    public  String addMessage(){
        return  "message/message-add";
    }
 
 
 
//    搜索留言显示列表
    @RequestMapping("/message/search")
    public String searchList(Model model,@RequestParam(defaultValue = "1") Integer page,
                             @RequestParam(defaultValue = "5") Integer pageSize,
                             String keyword){
        PageInfo<Message> pageInfo=messageService.searchList(page,pageSize,keyword);
        model.addAttribute("list",pageInfo.getList());
        model.addAttribute("pageInfo",pageInfo);
 
        return "message/message-list";
    }
//    添加留言
    @RequestMapping(value = "/message/add",method = RequestMethod.POST)
    public String  add(Message message, HttpSession session,Model model){
        /*Reader reader  = (Reader)session.getAttribute("reader");
        message.setReaderId(reader.getReaderId());*/
        message.setReaderId(2);
        ResultData resultData = messageService.add(message);
 
        Book book = bookService.findById(message.getBookId());
        List<Message> messageList = messageService.findByBookId(message.getBookId());
 
        model.addAttribute("book",book);
        model.addAttribute("messageList",messageList);
        return "novel";
    }
 
 
//    留言编辑页面
    @RequestMapping("/message/editPage")
    public String editPage(Model model,Integer id){
//        从数据库查询到的数据
        Message dbMessage = messageService.findById(id);
 
        model.addAttribute("message",dbMessage);
        return "message/message-edit";
    }
 
//    更新留言信息的方法
    @RequestMapping("/message/edit")
    @ResponseBody
    public ResultData edit(Message message){
 
        return messageService.edit(message);
 
    }
 
 
//    批量删除
    @RequestMapping("/message/deleteAll")
    @ResponseBody
    public ResultData deleteAll(@RequestParam(name = "ids") String ids){
//        将ids转换成数组
        String[] idArr=ids.split(",");
        return messageService.mesDelete(idArr);
    }
}

图书列表控制层:

@Controller
public class BookOrderController {
    @Autowired
    private BookOrderService bookOrderService;
    @Autowired
    private BookService bookService;
 
 
    @RequestMapping("/bookorder/bookorderlist")
    public String bookorderlist(Model model,
                                @RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "3") Integer pageSize) {
        PageInfo<BookOrder> pageInfo = bookOrderService.list(page, pageSize);
 
//将数据转发到页面
        model.addAttribute("list", pageInfo.getList());
        model.addAttribute("pageInfo", pageInfo);
        return "bookorder/bookorder-list";
    }
 
    @RequestMapping("/bookorder/orderSearch")
    public String searchList(Model model,
                                @RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "3") Integer pageSize,
                             String keyword) {
        PageInfo<BookOrder> pageInfo = bookOrderService.searchList(page,pageSize,keyword);
 
//将数据转发到页面
        model.addAttribute("list", pageInfo.getList());
        model.addAttribute("pageInfo", pageInfo);
        return "bookorder/bookorder-list";
    }
 
    @RequestMapping("/bookorder/bookorderadd")
    public String bookorderadd() {
        return "bookorder/bookorder-add";
 
    }
 
 
 
    @RequestMapping(value = "/bookorder/add",method = RequestMethod.POST)
    @ResponseBody
    public ResultData add(BookOrder bookOrder, HttpSession session) {
        Reader reader = (Reader)session.getAttribute("reader");
        if(reader==null){
            return  new ResultData(2001,"用户未登陆",null);
        }
        int readerId = reader.getReaderId();
        bookOrder.setUserId(1);
        bookOrder.setDiscountId(1);
        bookOrder.setOrderDate(new Timestamp(System.currentTimeMillis()));
        bookOrder.setOrderStatus(1);
        bookOrder.setPayStatus(1);
        ResultData resultData = bookOrderService.add(bookOrder);
 
        return resultData;
    }
 
    @RequestMapping("/bookorder/editStatus")
    @ResponseBody
    public ResultData editStatus(Integer id, Integer status) {
        return bookOrderService.updateStatus(id,status);
 
    }
    @RequestMapping("/bookorder/deleteAll")
    @ResponseBody
    public ResultData deleteAll(@RequestParam(name = "ids") String ids){
        // 将ids转换成数组
        String[] idArr = ids.split(",");
 
        return bookOrderService.batchDelete(idArr);
    }
 
    @RequestMapping("/bookorder/delete")
    @ResponseBody
    public  ResultData delete(Integer orderid,Integer orderStatus){
        return  bookOrderService.delete(orderid,orderStatus);
    }
 
 
    @RequestMapping("/bookOrder/toOrder")
    public  String delete(Integer bookId,Model model){
        Book book = bookService.findById(bookId);
        model.addAttribute("book",book);
        return  "front/order";
    }
 
 
    @RequestMapping("/bookOrder/toOrderCenter")
    public  String toOrderCenter(HttpSession session,Model model){
         /*Reader reader = (Reader)session.getAttribute("reader");
        if(reader==null){
            return  new ResultData(2001,"用户未登陆",null);
        }
        int readerId = reader.getReaderId();*/
         int readerId = 1;
 
        List<BookOrder> bookOrderList = bookOrderService.getAll(readerId);
        model.addAttribute("bookOrderList",bookOrderList);
        return  "front/orderCenter";
    }
 
 
}

历史浏览控制层:

@Controller
public class HistoryController {
    @Autowired
    private HistoryService historyService;
 
    //列表
    @RequestMapping("/history/list")
    public String list(Model model,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "3") Integer pageSize) {
        PageInfo<History> pageInfo=historyService.list(page,pageSize);
        model.addAttribute("list",pageInfo.getList());
        model.addAttribute("pageInfo",pageInfo);
 
        return "history/history-list";
    }
    //添加
    @RequestMapping("/history/addPage")
    public String addPage(){
        return "history/history-add";
    }
 
 
    //    添加
    @RequestMapping("/history/add")
    @ResponseBody
    public ResultData add(History history){
        return historyService.add(history);
    }
 
    //    search
    @RequestMapping("/history/search")
    public String searchList(Model model,
                             @RequestParam(defaultValue = "1") Integer page,
                             @RequestParam(defaultValue = "3") Integer pageSize,
                             String keyword) {
        PageInfo<History> pageInfo=historyService.searchList(page,pageSize,keyword);
 
        model.addAttribute("list",pageInfo.getList());
        model.addAttribute("pageInfo",pageInfo);
        return  "history/history-list";
    }
 
//      批量删除
    @RequestMapping("/history/deleteAll")
    @ResponseBody
    public ResultData deleteAll(@RequestParam(name="ids") String ids){
        //将ids转为数组
        String[] idArr = ids.split(",");
        //将字符串数组转为int数组
        return historyService.batchDelete(idArr);
 
    }
 
}

到此这篇关于Java 实战项目之小说在线阅读系统的实现流程的文章就介绍到这了,更多相关Java 小说在线阅读系统内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:
阅读全文