⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readingaction.java

📁 在线读书交流平台
💻 JAVA
字号:
package com.olr.control.reading;

import java.util.Date;
import java.util.List;

import com.olr.BO.ReadingBO;
import com.olr.beans.Book;
import com.olr.beans.Chapter;
import com.olr.beans.Comment;
import com.olr.beans.User;
import com.olr.control.common.PageAction;
import com.olr.util.Constants;

public  class ReadingAction extends PageAction{
	private ReadingBO readingBO;
	
	private Integer chapterId;
	private Integer bookId;
	private Integer chapterNum;
	
	private Integer commentId;
	private String username;
	private String content;
	private Date commentPostdate;
	
	private int userId;
	private Book book;
	private Chapter chapter;
	private List<Comment> commentList;

	
	public void validate(){
		this.clearErrorsAndMessages();
		String url=this.getRequestPath();
		if(url.indexOf("reading!recomand")!=-1||url.indexOf("reading!addToShelf")!=-1
				||url.indexOf("reading!showChapter")!=-1||url.indexOf("reading!addComment")!=-1)
		{
			if(!this.isLogin()){
				this.addFieldError("requestLogin","请登录");
			
			}
		}
	}
	
	//显示书籍信息以及列出所有章节的链接
	public  String showBook() {
		book=this.getReadingkBO().getBook(bookId);
		
		return "showBook";
	}
	//推荐书籍,进行投票
	public  String recomand() {
		this.getReadingkBO().addRecommend(bookId);
		//this.reflesh();
		return "showBook";
	}
	//添加到用户书架
	public  String addToShelf() {
		
		userId=Integer.parseInt(this.getSession("userId").toString());
		this.getReadingkBO().addToBookshelf(userId, bookId);
		return "showBook";
	}
	
	//显示章节内容以及本章节最新评论
	public  String showChapter() {
		userId=Integer.parseInt(this.getSession("userId").toString());
		if(chapterNum<1){
			this.addFieldError("showChapter", "到头了!");
		}
		if(chapterNum>book.getChapterCount()){
			this.addFieldError("showChapter", "下面没有了,等着作者更新吧!");
		}
		if(!this.getReadingkBO().minusPoint(userId, book.getPrice())){
			this.addFieldError("pointCheck","积分不够");
			return "showBook";
		}
		chapter=this.getReadingkBO().getChapter(chapterNum, bookId);
		chapter.setChapterText(chapter.getChapterText().replaceAll("\r\n","<br/>"));
		commentList=this.getReadingkBO().getTopComments(chapter.getChapterId(), 10);
		return "showChapter";
	}
	//添加评论
	public  String addComment() {
		username=this.getLoginUsername();
		commentPostdate=new Date();
		Comment comment=new Comment();
		comment.setChapterId(chapterId);
		comment.setContent(content);
		comment.setPostdate(commentPostdate);
		comment.setUsername(username);
		this.getReadingkBO().addComment(comment);
		chapter=this.getReadingkBO().getChapter(chapterNum, bookId);
		commentList=this.getReadingkBO().getTopComments(chapterId, 10);
		return "showChapter";
	}
	//显示所有评论
	public  String initComment() {
		this.clearErrorsAndMessages();	
		super.pageSize=Constants.pageSize;
		super.pageNo=Constants.pageNo;
		super.pager=this.getReadingkBO().getCommentPager(chapter.getChapterId(), pageNo, pageSize);
		this.setSession("commentPager", super.pager);
		return "list";
	}

	public  String listComment() {
		this.clearErrorsAndMessages();
		super.pager=this.getReadingkBO().getCommentPager(chapter.getChapterId(), pageNo, pageSize);
		this.setSession("commentPager", super.pager);
		return "list";
	}
	
	public void reflesh(){
		chapter=this.getReadingkBO().getChapter(chapterNum, bookId);
		commentList=this.getReadingkBO().getTopComments(chapterId, 10);
	}

	
	public ReadingBO getReadingkBO() {
		return readingBO;
	}
	public void setReadingBO(ReadingBO readingBO) {
		this.readingBO = readingBO;
	}
	public Integer getChapterId() {
		return chapterId;
	}
	public void setChapterId(Integer chapterId) {
		this.chapterId = chapterId;
	}
	
	public Integer getBookId() {
		return bookId;
	}
	public void setBookId(Integer bookId) {
		this.bookId = bookId;
	}
	public Integer getChapterNum() {
		return chapterNum;
	}
	public void setChapterNum(Integer chapterNum) {
		this.chapterNum = chapterNum;
	}
	
	public Integer getCommentId() {
		return commentId;
	}
	public void setCommentId(Integer commentId) {
		this.commentId = commentId;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public Date getCommentPostdate() {
		return commentPostdate;
	}
	public void setCommentPostdate(Date commentPostdate) {
		this.commentPostdate = commentPostdate;
	}
	public int getUserId() {
		return userId;
	}
	public void setUserId(int userId) {
		this.userId = userId;
	}
	public Book getBook() {
		return book;
	}
	public void setBook(Book book) {
		this.book = book;
	}
	public Chapter getChapter() {
		return chapter;
	}
	public void setChapter(Chapter chapter) {
		this.chapter = chapter;
	}
	public List<Comment> getCommentList() {
		return commentList;
	}
	public void setCommentList(List<Comment> commentList) {
		this.commentList = commentList;
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -