Java 實戰項目之小說在線閱讀系統的實現流程

一、項目簡述

功能包括(管理員和遊客角色):

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 小說在線閱讀系統內容請搜索WalkonNet以前的文章或繼續瀏覽下面的相關文章希望大傢以後多多支持WalkonNet!

推薦閱讀: