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

📄 noteaction.java

📁 用struts+hibernate+spring+mysql写的留言板程序
💻 JAVA
字号:
package com.zzx.struts.action;

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

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.zzx.struts.dao.NoteDao;
import com.zzx.struts.form.NoteForm;
import com.zzx.struts.vo.Note;

public class NoteAction extends DispatchAction {
	private NoteDao noteDao;
	
	public ActionForward insert(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		NoteForm noteForm = (NoteForm) form;
		Note note = new Note();
		note.setTitle(noteForm.getTitle());
		note.setAuthor(noteForm.getAuthor());
		note.setContent(noteForm.getContent());
		// 3、调用DAO完成数据库的插入操作
		boolean flag = false;
		try {
			this.noteDao.insert(note);
			flag = true;
		} catch (Exception e) {
		}
		request.setAttribute("flag", new Boolean(flag));
		return mapping.findForward("add");
	}
	
	public ActionForward delete(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		NoteForm noteForm = (NoteForm) form;
		int id = 0;
		try {
			id = Integer.parseInt(noteForm.getId());
		} catch (Exception e) {
		}
		boolean flag = false;
		try {
			this.noteDao.delete(id);
			flag = true;
		} catch (Exception e) {
		}
		request.setAttribute("flag", new Boolean(flag));
		return mapping.findForward("delete");
	}
	
	public ActionForward update(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		NoteForm noteForm = (NoteForm) form;
		int id = 0;
		try {
			id = Integer.parseInt(noteForm.getId());
		} catch (Exception e) {
		}
		Note note = new Note();
		note.setId(id);
		note.setTitle(noteForm.getTitle());
		note.setAuthor(noteForm.getAuthor());
		note.setContent(noteForm.getContent());
		boolean flag = false;
		try {
			this.noteDao.update(note);
			flag = true;
		} catch (Exception e) {
		}
		request.setAttribute("flag", new Boolean(flag));
		return mapping.findForward("updatedo");
	}

	public ActionForward selectid(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		NoteForm noteForm = (NoteForm) form;
		int id = 0;
		try {
			id = Integer.parseInt(noteForm.getId());
		} catch (Exception e) {
		}
		try {
			request.setAttribute("note", this.noteDao
					.queryById(id));
		} catch (Exception e) {
		}
		return mapping.findForward("update");
	}

	public ActionForward selectall(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {

		try {
			request.setAttribute("all", this.noteDao
					.queryAll());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return mapping.findForward("list");
	}

	

	public ActionForward selectlike(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		NoteForm noteForm = (NoteForm) form;
		String keyword = request.getParameter("keyword");
		try {
			request.setAttribute("all", this.noteDao.queryLike(keyword));
		} catch (Exception e) {
		}
		return mapping.findForward("list");
	}

	public NoteDao getNoteDao() {
		return noteDao;
	}

	public void setNoteDao(NoteDao noteDao) {
		this.noteDao = noteDao;
	}
}

⌨️ 快捷键说明

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