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

📄 editaction.java

📁 本书由浅入深、循序渐进地介绍了MVC的体系结构和如何构建一个基于MVC的Web框架
💻 JAVA
字号:
package com.myContent.action;

import java.sql.SQLException;
import java.util.List;

import org.apache.log4j.Logger;

import com.myContent.service.EditContent;
import com.myContent.service.Login;
import com.myContent.service.Regedit;
import com.myContent.service.SetContentType;
import com.myContent.service.impl.EditContentImpl;
import com.myContent.service.impl.LoginImpl;
import com.myContent.service.impl.RegeditImpl;
import com.myContent.service.impl.SetContentTypeImpl;
import com.myContent.vo.Content;
import com.myContent.vo.ContentType;
import com.myContent.vo.User;
import com.gd.mvc.action.impl.GdAction;
import com.gd.mvc.exception.VODataValidate;
import com.gd.mvc.util.GdDate;

public class EditAction extends GdAction{
	static Logger logger = Logger.getLogger(EditAction.class.getName());
	private Content content = null;

	public void doBegin() throws VODataValidate, Exception{
		//获取页面中的值
		content = (Content)infoIn.getVO();
		content.setDateTime(GdDate.getCurrentDateAndTime());
		
		infoOut.put("msg", "请输入内容的相关属性");
		String username = infoIn.getParameter("username");
		if ("".equals(username) || username == null) {
			infoOut.put("forwardJsp", "login");
		}
		infoOut.put("username", username);
		String userId = infoIn.getParameter("userId");
		content.setUserId(userId);
		infoOut.put("userId", userId);
	}
	public void doEnd() throws Exception{
		this.getAllContent();
		this.getAllType();
		infoOut.put("content", content);
	}
	
	/**该方法用来实现获取所有的内容
	*/
	public void getAllContent() throws Exception{
		try {			
			EditContent editContent = new EditContentImpl();
			//获取所有的内容	
			List contentList = editContent.getAllContent();
			infoOut.put("contentList", contentList);
		} catch(Exception e) {
        	logger.error(e);
		} finally {
		}
  	}
	/**该方法用来实现获取所有的内容类别
	*/
	public void getAllType() throws Exception{
		try {			
			SetContentType setContentType = new SetContentTypeImpl();
			//获取所有的内容类别	
			List contentTypeList = setContentType.getAllContentType();
			infoOut.put("contentTypeList", contentTypeList);
		} catch(Exception e) {
        	logger.error(e);
		} finally {
		}
  	}
	
	/**该方法用来实现新增内容
	*/
	public void doInsert() throws Exception{
		try {			
			EditContent editContent = new EditContentImpl();
//			新增内容
			int counts = editContent.saveContent(content);
			//判断是否新增成功
			if (counts != 0) {
				infoOut.put("msg", "新增成功");
			} else {
				infoOut.put("msg", "新增失败");
			}
		} catch(Exception e) {
        	logger.error(e);
		} finally {
		}
  	}
	/**该方法用来实现修改内容类别
	*/
	public void doUpdate() throws Exception{
		try {			
			EditContent editContent = new EditContentImpl();
//			修改内容	
			int counts = editContent.updateContent(content);
			//判断是否修改成功
			if (counts != 0) {
				infoOut.put("msg", "修改成功");
			} else {
				infoOut.put("msg", "修改失败");
			}
		} catch(Exception e) {
        	logger.error(e);
		} finally {
		}
  	}
	/**该方法用来实现删除内容
	*/
	public void doDelete() throws Exception{
		try {			
			EditContent editContent = new EditContentImpl();
//			删除内容	
			int counts = 0;
			List list = (List)infoIn.getVOs("chk");
			for (int i = 0; list != null && list.size() > i; i++) {
				Content contentTemp = (Content)list.get(i);
				counts += editContent.deleteContent(contentTemp);
			}
			
			//判断是否删除成功
			if (counts != 0) {
				infoOut.put("msg", "删除成功");
			} else {
				infoOut.put("msg", "删除失败");
			}
		} catch(Exception e) {
        	logger.error(e);
		} finally {
		}
  	}
}

⌨️ 快捷键说明

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