📄 forumjsp.java
字号:
TopicView tv = null;
ReplyView rv = null;
int topicId = ParamUtils.getIntAuto(request,"topicId");
int rid = ParamUtils.getIntAuto(request,"replyId");
String act = ParamUtils.getStringParameter(request,"act","");
if((rid>0&&topicId==0)
||(rid>0&&(act.equals("addreply")||act.equals("trashreply")||act.equals("editreply")))
){ //取回复
ReplyModel model = this.getReplyService().findReplyAndContentById(rid);
if(!Validator.isEmpty(model)){
rv = new ReplyView();
BeanUtils.copyProperties(rv,model.getReContentModel());
BeanUtils.copyProperties(rv,model);
UserView uv = new UserView();
BeanUtils.copyProperties(uv,this.getUserService().findById(rv.getUserId()));
rv.setUser(uv);
request.setAttribute("topicId",rv.getTopicId());
request.setAttribute(UserSetUtils.getThreadStyleName(request),"1");
if(!request.getRequestURI().equals("/club/post.jsp")){
UserSetUtils.update(request,response,UserSetUtils.THREAD_STYLE,"1");
}
if(act.equals("editreply")){
if(rv.getIsDeleted()){
HttpServletUtils.redirect(response,"404.html");
return null;
}
TopicPostForm form = (TopicPostForm)request.getAttribute("TopicPostForm");
if(!Validator.isEmpty(form)){
BeanUtils.copyProperties(rv,form);
}
else{
form = new TopicPostForm();
BeanUtils.copyProperties(form,rv);
}
request.setAttribute("TopicPostForm",form);
/*
form = this.getTopicPostForm();
request.setAttribute("TopicPostForm",form);
*/
}
}else{
HttpServletUtils.redirect(response,"404.html");
return null;
}
}
else if(!act.equals("addtopic")){//取主题
TopicModel model = this.getTopicService().findTopicAndContentById(topicId);
if(!Validator.isEmpty(model)){
if(act.equals("")){
model.setViews(model.getViews()+1);
try {
this.getTopicService().updateViews(model.getTopicId());
} catch (ClubException e) {
logger.error(e.toString());
} //更新浏览次数
logger.debug("update views: " + model.getViews());
}
tv = new TopicView();
BeanUtils.copyProperties(tv,model.getContentModel());
BeanUtils.copyProperties(tv,model);
UserView uv = new UserView();
BeanUtils.copyProperties(uv,this.getUserService().findById(tv.getUserId()));
tv.setUser(uv);
request.setAttribute("topicId",tv.getTopicId());
if(act.equals("edittopic")){
if(tv.getIsDeleted()){
HttpServletUtils.redirect(response,"404.html");
return null;
}
TopicPostForm form = (TopicPostForm)request.getAttribute("TopicPostForm");
if(!Validator.isEmpty(form)){
BeanUtils.copyProperties(tv,form);
}
else{
form = new TopicPostForm();
BeanUtils.copyProperties(form,tv);
}
request.setAttribute("TopicPostForm",form);
/*
form = this.getTopicPostForm();
request.setAttribute("TopicPostForm",form);
*/
}
}else{
logger.debug("not find TopicModel topicId:"+topicId);
HttpServletUtils.redirect(response,"404.html");
return null;
}
}
if(rv!=null){
title = rv.getTitle();
return rv;
}
else if(tv!=null){
title = tv.getTitle();
return tv;
}else{
return null;
}
}
public List<TopicView> searchTopic(int page, int rows){
if(Validator.isEmpty(title)){
return null;
}
List<TopicModel> list = this.getTopicService().searchTopic(title, page, rows);
if(!Validator.isEmpty(list)){
return BeanUtils.<TopicModel,TopicView>copyList(list,BeanLocator.TOPICVIEW);
}else{
return null;
}
}
public TopicView findTopicById(){
int topicId = ParamUtils.getIntAuto(request,"topicId");
//logger.debug("request.getAttribute(\"topicId\"):"+request.getAttribute("topicId"));
TopicModel model = this.getTopicService().findById(topicId);
TopicView view = null;
if(!Validator.isEmpty(model)){
view = new TopicView();
BeanUtils.copyProperties(view,model);
}
return view;
}
public List<ReplyView> findReplyAndContent(int topicId){
TopicParameter param = new TopicParameter();
param.setOrderBy((byte)0);
param.setForumId(forumId);
param.setTopicId(topicId);
param.setPage(page);
if(!Validator.isEmpty(this.getForumService().findById(forumId))){
param.setRows(this.getForumService().findById(forumId).getReplyListNumber());
}else{
int rows = ParamUtils.getIntParameter(request,"rows");
if(rows>100){
rows = 100;
}
param.setRows(rows);
}
List<ReplyModel> mlist = this.getReplyService().findReplyAndContent(param);
List<ReplyView> list = BeanUtils.<ReplyModel,ReplyView>copyList(mlist,BeanLocator.REPLYVIEW);
if(!Validator.isEmpty(list)){
for(int i=0; i<list.size(); i++){
ReplyView v = list.get(i);
BeanUtils.copyProperties(v,mlist.get(i).getReContentModel());
v.setStorey(this.getSotrey(param.getRows()));
list.set(i,v);
}
}
long total = this.getReplyService().countByParameter(param);
this.setLastpage(OutPrint.getLastpage(total,param.getRows()));
StringBuffer url = new StringBuffer();
url.append("thread.jsp?forumId=");
url.append(forumId);
url.append("&fpage=");
url.append(fpage);
url.append("&topicId=");
url.append(topicId);
url.append("&page=");
this.setPagination(OutPrint.pagination(page, param.getRows(), total, url.toString(),5));
return list;
}
public List<ReplyView> findReplyAndContent(){
int topicId = ParamUtils.getIntAuto(request,"topicId");
/*
if(topicId==-1){
topicId = TypeChange.objToInt(ParamUtils.getAttribute(request,"topicId"));
logger.debug("getAttribute(\"topicId\"):"+request.getAttribute("topicId"));
}
*/
return this.findReplyAndContent(topicId);
}
public List<ReplyView> findReplyByTopicId(int rows){
//int topicId = ParamUtils.getIntAuto(request,"topicId");
return this.findReplyByTopicId(ParamUtils.getIntAuto(request,"topicId"),rows);
}
public List<ReplyView> findReplyByTopicId(int topicId, int rows){
return this.findReplyByTopicId(topicId,page,rows);
}
public List<ReplyView> findReplyByTopicId(int topicId, int page, int rows){
TopicParameter param = new TopicParameter();
param.setTopicId(topicId);
param.setPage(new Integer(page));
param.setRows(new Integer(rows));
List<ReplyModel> mlist = this.getReplyService().findReplyByTopicId(param);
//List<ReplyView> list = BeanUtils.copyList(mlist,BeanLocator.REPLYVIEW);
return BeanUtils.copyList(mlist,BeanLocator.REPLYVIEW);
}
public List<UserView> findUsersFromFavorite(){
FavoriteParameter param = new FavoriteParameter();
param.setForumId(forumId);
List<UserModel> mlist = this.getFavoriteForumService().findUser(param);
param.setRows(200);
return BeanUtils.<UserModel,UserView>copyList(mlist,BeanLocator.USERVIEW);
}
public long countUsersFromFavorite(){
FavoriteParameter param = new FavoriteParameter();
param.setForumId(forumId);
return this.getFavoriteForumService().countByParameter(param);
}
public String getForumStyle() {
return forumStyle;
}
public String getThreadStyle() {
return threadStyle;
}
public String getPagination() {
return pagination;
}
public void setPagination(String pagination) {
this.pagination = pagination;
}
private TopicService getTopicService() {
return ServiceWrapper.<TopicService>getSingletonInstance(ServiceLocator.TOPIC);
}
private ForumService getForumService() {
return ServiceWrapper.<ForumService>getSingletonInstance(ServiceLocator.FORUM);
}
private ForumTemplate getForumTemplate() {
if(Validator.isEmpty(forumTemplate)){
forumTemplate = new ForumResults();
}
return forumTemplate;
}
public int getForumId() {
return forumId;
}
public void setForumId(int forumId) {
this.forumId = forumId;
}
public GroupOfForumJsp getGroupOfForumJsp() {
if(Validator.isEmpty(groupOfForumJsp)){
groupOfForumJsp = new GroupOfForumJsp(request,response);
}
return groupOfForumJsp;
}
private ReplyService getReplyService() {
return ServiceWrapper.<ReplyService>getSingletonInstance(ServiceLocator.REPLY);
}
private UserService getUserService() {
return ServiceWrapper.<UserService>getSingletonInstance(ServiceLocator.USER);
}
private CountService getCountService() {
return ServiceWrapper.<CountService>getSingletonInstance(ServiceLocator.COUNT);
}
private FavoriteForumService getFavoriteForumService() {
return ServiceWrapper.<FavoriteForumService>getSingletonInstance(ServiceLocator.FAVORITEFORUM);
}
public ForumLabelService getForumLabelService()
{
return ServiceWrapper.<ForumLabelService>getSingletonInstance(ServiceLocator.FORUMLABEL);
}
public int getFpage() {
return fpage;
}
public void setFpage(int fpage) {
this.fpage = fpage;
}
public int getTopicId() {
return ParamUtils.getIntAuto(request,"topicId");
}
public int getLastpage() {
return lastpage;
}
public void setLastpage(int lastpage) {
this.lastpage = lastpage;
}
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
public BasicInfoService getBasicInfoService() {
return ServiceWrapper.<BasicInfoService>getSingletonInstance(ServiceLocator.BASICINFO);
}
public static void main(String args[]){
/*
ReplyModel m = new ReplyModel();
ReplyView v = new ReplyView();
m.setIsDeleted(true);
BeanUtils.copyProperties(v,m);
System.out.println(v.getIsDeleted());
*/
/*
com.yeqiangwei.club.dao.hibernate.ConnectionManager.init();
ForumJsp j = new ForumJsp(null,null);
ModelsOfForumView m = j.getModelsOfForumView(28);
System.out.println(m.getForumView().getForumName());
System.out.println("================================");
List list = m.getForumViews();
for(int i=0; i<list.size(); i++){
com.yeqiangwei.club.view.model.ForumView fm = (com.yeqiangwei.club.view.model.ForumView) list.get(i);
System.out.println(fm.getForumName());
}
*/
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -