您好,登錄后才能下訂單哦!
這篇文章給大家介紹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如何實現小說在線閱讀系統就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。