Java实战之实现在线小说阅读系统

环境配置

Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)

项目技术

Layui+Springboot+ SpringMVC + HTML + FTP+ JavaScript + JQuery + Ajax + maven等等。

效果图

Java实战之实现在线小说阅读系统_第1张图片

Java实战之实现在线小说阅读系统_第2张图片

Java实战之实现在线小说阅读系统_第3张图片

Java实战之实现在线小说阅读系统_第4张图片

Java实战之实现在线小说阅读系统_第5张图片

读者用户控制器

@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 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 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 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 BookController {
 
    @Autowired
    private BookService bookService;
 
//    @Autowired
//    private BookService bookService;
    //小说列表
    @RequestMapping("/book/list")
    public String list(Model model,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "3") Integer pageSize) {
        PageInfo pageInfo=bookService.list(page,pageSize);
 
 
        model.addAttribute("list",pageInfo.getList());
        model.addAttribute("pageInfo",pageInfo);
        return "book/book-list";
    }
 
    //小说添加
    @RequestMapping("/book/addPage")
    public String addPage() {
        return "book/book-add";
    }
//
//    //    添加小说
    @RequestMapping("/book/add")
    @ResponseBody
    public ResultData add(Book book) {
       return bookService.add(book);
    }
 
//    编辑小说状态
    @RequestMapping("/book/editCondition")
    @ResponseBody
    public ResultData editCondition(Integer bookId, Integer condition){
        return bookService.updateStatus(bookId,condition);
    }
 
//    编辑页面
    @RequestMapping("/book/editPage")
    public String editPage(Model model, Integer bookId){
        Book dbBook = bookService.findById(bookId);
        model.addAttribute("book",dbBook);
 
        return "book/book-edit";
    }
//更新基本信息
    @RequestMapping("/book/edit")
    @ResponseBody
    public ResultData edit(Book book){
        return  bookService.edit(book);
    }
 
 
//    批量删除
    @RequestMapping("/book/deleteAll")
    @ResponseBody
    public ResultData deleteAll(@RequestParam(name="ids") String ids){
        //将ids转为数组
        String[] idArr = ids.split(",");
        //将字符串数组转为int数组
        return bookService.batchDelete(idArr);
 
    }
 
    //    search
    @RequestMapping("/book/search")
    public String searchList(Model model,
                             @RequestParam(defaultValue = "1") Integer page,
                             @RequestParam(defaultValue = "3") Integer pageSize,
                             String keyword) {
        PageInfo pageInfo=bookService.searchList(page,pageSize,keyword);
 
        model.addAttribute("list",pageInfo.getList());
        model.addAttribute("pageInfo",pageInfo);
        return  "book/book-list";
    }
 
    @RequestMapping("/book/search1")
    public String searchList1(Model model,
                             @RequestParam(defaultValue = "1") Integer page,
                             @RequestParam(defaultValue = "3") Integer pageSize,
                             String keyword1) {
        PageInfo pageInfo=bookService.searchList1(page,pageSize,keyword1);
 
        model.addAttribute("list",pageInfo.getList());
        model.addAttribute("pageInfo",pageInfo);
        return  "book/book-list";
    }
 
 
    @RequestMapping(value = "/book/getByType",method = RequestMethod.GET)
    public String getByType(Integer bookType, Model model, HttpSession session){
        List bookList = bookService.findByType(bookType);
        List randList = bookService.findRandList();
        //将字符串数组转为int数组
        session.setAttribute("bookList",bookList);
        session.setAttribute("randList",randList);
        return "/front/personal";
    }
 
    @RequestMapping(value = "/book/getByName",method = RequestMethod.POST)
    public String getByName(String likeName, Model model, HttpSession session) throws UnsupportedEncodingException {
       // String likeName1 = new String(likeName.getBytes("ISO-8859-1"),"utf-8");
        List bookList = bookService.findByLikeName(likeName);
        List randList = bookService.findRandList();
        //将字符串数组转为int数组
        session.setAttribute("bookList",bookList);
        session.setAttribute("randList",randList);
        return "/front/personal";
    }
 
}

图书订单管理控制层

@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 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 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 bookOrderList = bookOrderService.getAll(readerId);
        model.addAttribute("bookOrderList",bookOrderList);
        return  "front/orderCenter";
    }
 
 
}

角色管理控制层

@Controller
public class AuthorController {
    @Autowired
    private AuthorService authorService;
 
 
    @RequestMapping("/zuozhe")
    public String duzhe(){
        return "loginauthor";
    }
 
 
    @RequestMapping("/zuoping")
    public String zuoping(){
        return "index11";
    }
 
    /**
     * 登陆操作
     * @return
     */
    @RequestMapping("/loginauthor")
    @ResponseBody
    public ResultData login2(Author author){
        ResultData resultData=authorService.login2(author);
        return resultData;
    }
 
 
 
    //作者列表
    @RequestMapping("/author/list")
    public String list(Model model,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "5") Integer pageSize){
 
 
        PageInfo pageInfo = authorService.list(page,pageSize);
 
 
 
        model.addAttribute("list",pageInfo.getList());
        model.addAttribute("pageInfo",pageInfo);
 
        return "author/author-list";
    }
 
    //搜索作者显示列表
    @RequestMapping("/author/search")
    public String searchList(Model model,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "5") Integer pageSize,
                             String keyword){
 
        PageInfo pageInfo = authorService.searchList(page, pageSize, keyword);
        model.addAttribute("list",pageInfo.getList());
        model.addAttribute("pageInfo",pageInfo);
 
        return "author/author-list";
    }
 
    //作者删除列表
    @RequestMapping("/author/deleteList")
    public String deleteList(Model model,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "5") Integer pageSize){
 
        PageInfo pageInfo = authorService.DeleteList(page,pageSize);
        model.addAttribute("list",pageInfo.getList());
        model.addAttribute("pageInfo",pageInfo);
        return "author/author-del";
    }
 
    //添加作者
    @RequestMapping("/author/addPage")
    public String addPage(){
        return "author/author-add";
    }
 
 
 
//    添加作者的方法
    @RequestMapping("/author/add")
    @ResponseBody
    public ResultData add(Author author){
        return authorService.add(author);
    }
 
    /**
     * 编辑作者状态信息
     * @param authorId : 当前作者Id
     * @param authorStatus: 作者当前状态
     * @return
     */
    @RequestMapping("/author/editStatus")
    @ResponseBody
    public ResultData editStatus(Integer authorId, Integer authorStatus){
        return authorService.updateStatus(authorId, authorStatus);
    }
 
    /**
     * 编辑作者
     * @param
     * @param
     * @return
     */
    @RequestMapping("/author/editPage")
    public String editPage(Model model, Integer authorId){
        Author dbreadder = authorService.findById(authorId);
        model.addAttribute("author",dbreadder);
        return "author/author-edit";
    }
 
    /**
     * 更新作者基本信息的方法
     * @param author
     * @return
     */
    @RequestMapping("/author/edit")
    @ResponseBody
    public ResultData edit(Author author){
        return authorService.edit(author);
    }
 
    /**
     * 批量删除
     * @param ids
     * @return
     */
    @RequestMapping("/author/deleteAll")
    @ResponseBody
    public ResultData deleteAll(@RequestParam(name = "ids") String ids){
//        将ids转换成数组
        String[] idArr=ids.split(",");
        return authorService.batchDelete(idArr);
    };
 
    /**
     * 批量恢复
     * @param ids
     * @return
     */
    @RequestMapping("/author/huifuAll")
    @ResponseBody
    public ResultData huifuDelete(@RequestParam(name = "ids") String ids){
//        将ids转换成数组
        String[] idArr=ids.split(",");
        return authorService.huifuDelete(idArr);
    };
 
    @RequestMapping("/author/delete")
    @ResponseBody
    public ResultData deleteAuthor(Integer authorId, Integer authorStatus){
        return authorService.deleteauthor(authorId,authorStatus);
    }
 
 
 
}

历史控制层

@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 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 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的资料请关注脚本之家其它相关文章!

你可能感兴趣的:(Java实战之实现在线小说阅读系统)