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

📄 forumaddcontroller.java

📁 目前系统具有功能如下: 用户注册 修改信息 自定义图像 用户升级 锁定用户 用户发帖 论坛好友 论坛版主 用户列表 建立用户组 用户等级定义 在线用户查看 论坛财富分配 用
💻 JAVA
字号:
package com.yhbbs.admin.web.forum;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.validation.Errors;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import com.yhbbs.admin.web.forum.form.ForumAddForm;
import com.yhbbs.forum.biz.ForumBiz;
import com.yhbbs.forum.itface.Forum;
import com.yhbbs.utils.ReqUtils;
/**
 * <p>Title:增加论坛Controller</p>
 * <li>	论坛增加和修改
 * <br><b>WebSite: www.yyhweb.com</b>
 * <br><b>CopyRight: yyhweb[由由华网]</b>
 * @author stephen
 * @version YHBBS-2.0
 */
public class ForumAddController extends SimpleFormController{
	// 构造函数设置其属性
	public ForumAddController(){
		this.setSessionForm(true);
		this.setValidateOnBinding(false);
		this.setCommandName("forumForm");
		this.setFormView("forumadd");
	}
	// 初始化数据
	protected Map referenceData(HttpServletRequest request, Object obj, Errors error) throws Exception {
		Map<String, Integer> model = new HashMap<String, Integer>();
		int forumId = ReqUtils.getInt(request, "fId");
		if(forumId<=0){
			int classId = ReqUtils.getInt(request, "cId");
			model.put("classid", classId);
			return model;
		}
		return null;
	}
	// 取得表单
	protected Object formBackingObject(HttpServletRequest request) throws Exception {
		int forumId = ReqUtils.getInt(request, "fId");
		if(forumId>0){
			Forum forum = ForumBiz.getForum(forumId);
			return new ForumAddForm(forum);
		}else
			return new ForumAddForm();
	}
	//	数据邦定和表单验证
	protected void onBindAndValidate(HttpServletRequest request,Object command,BindException errors){
		ForumAddForm forumForm = (ForumAddForm)command;
		Forum forum = forumForm.getForum();
		if(forum.getId()<=0){
			int classId = ReqUtils.getInt(request, "classId");
			forum.setClassid(classId);
			forum.setParentid(0);
		}
		
	}
	// 表单提交
	protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command,BindException errors){
		Map<String, String> model = new HashMap<String, String>();
		boolean flag = true;
		ForumAddForm forumForm = (ForumAddForm)command;
		Forum forum = forumForm.getForum();
		int id = forum.getId();
		if(id<=0)
			flag = ForumBiz.addForum(forum);
		else
			flag = ForumBiz.editForum(forum);
		if(flag){
			if(id<=0)
				model.put("okinfo", "增加论坛");
			else
				model.put("okinfo", "修改论坛");
			model.put("forward", "<a href='../admin/ForumMag.do'>论坛管理</a>");
			return new ModelAndView("success",model);
		}else{
			model.put("errinfo", "论坛");
			model.put("forward", "<a href='../admin/ForumAdd.do'>增加论坛</a>");
			return new ModelAndView("failure",model);
		}
	}
}

⌨️ 快捷键说明

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