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

📄 booklistaction.java

📁 用STRUTS ,HIBERNATE, SPRING 三种框架整合做的实战项目
💻 JAVA
字号:
package com.ghy.action;

import java.util.List;

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

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

import com.ghy.data.book.Page;
import com.ghy.data.book.SearchForm;
import com.ghy.service.book.BookServiceIfc;
import com.ghy.util.Pagination;

public class bookListAction extends BaseAction {

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		HttpSession session = request.getSession();
		BookServiceIfc bookServiceIfc = getBookServiceIfc();
		// 查找所有书类
		List cateList = bookServiceIfc.findCategory("all");
		if (session.getAttribute("category") == null)
			session.setAttribute("category", cateList);
		Page page = null;
		List bookList = null;
		// 控制查找全部书籍或者相关书籍
		String cateId = "all";
		// 控制分页跳转
		String action = request.getParameter("action");
		if (session.getAttribute("searchForm") == null)// 不按关键字查找
		{
			if (request.getParameter("cateId") != null)
				cateId = request.getParameter("cateId");
			// 改变page的状态
			page = new Pagination().pagination(cateId, action, bookServiceIfc,
					session);
			bookList = bookServiceIfc.findBookByCategoryId(cateId, page
					.getCurrentPage() - 1);
		} else// 按照关键字查找
		{
			SearchForm searchForm = (SearchForm) session
					.getAttribute("searchForm");
			page = new Pagination().paginationByKey(action, searchForm
					.getSearchText(), searchForm.getSearchList(),
					bookServiceIfc, session);
			bookList = bookServiceIfc.findBookByKey(searchForm.getSearchText(),
					searchForm.getSearchList(), page.getCurrentPage() - 1);
		}
		// 更新session中的键值对,并转发
		session.setAttribute("page", page);
		session.setAttribute("book", bookList);
		return mapping.findForward("bookList");
	}
}

⌨️ 快捷键说明

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