📄 bookinfoaction.java
字号:
package com.xaccp.aj3q8073.action;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUpload;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.RequestContext;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.fileupload.servlet.ServletRequestContext;
import com.xaccp.aj3q8073.controller.Action;
import com.xaccp.aj3q8073.controller.ActionForward;
import com.xaccp.aj3q8073.dao.BookInfoDao;
import com.xaccp.aj3q8073.dao.ContentsManagerDao;
import com.xaccp.aj3q8073.vo.BookInfoVo;
import com.xaccp.aj3q8073.vo.BookShelfVo;
import com.xaccp.aj3q8073.vo.TomCatVO;
/**
* 图书信息管理
* @author Administrator
*
*/
public class BookInfoAction implements Action {
ContentsManagerDao dao=new ContentsManagerDao();
BookInfoDao bd=new BookInfoDao();
/**
* 查找一级目录
*/
public ActionForward execute(HttpServletRequest request, HttpServletResponse response) throws Exception {
List list= dao.findOneBookshelf();
request.setAttribute("oneBookContent", list);
return new ActionForward("/background/merchandiseInformationList.jsp");
}
/**
* 查找所有的二级目录和所有没有上架的图书
*
* @return
*/
public ActionForward findTwoContent(HttpServletRequest request, HttpServletResponse response) throws Exception {
//查找所有二级目录
List list= bd.findTwoContent();
//查找所有没有未上架的图书
List st= bd.findAllNotUp();
request.setAttribute("upTwo", list);
request.setAttribute("notUp", st);
return new ActionForward("/background/bookSloon.jsp");
}
/**
* 根据shelfId查找未上架的图书
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward findNotBook(HttpServletRequest request, HttpServletResponse response) throws Exception {
String shelfId=request.getParameter("shelfId");
//根据shelfId查找货架名称
BookShelfVo bv= dao.findShelfName(Integer.parseInt(shelfId));
BookShelfVo vo=new BookShelfVo();
// BookInfoVo vo=new BookInfoVo();
vo.setShelfId(Integer.parseInt(shelfId));
vo.setShelfName(bv.getShelfName());
request.setAttribute("shelf", vo);
List list2= bd.findTwoContent();
request.setAttribute("upTwo", list2);
List list= bd.findNotUpByShelfId(Integer.parseInt(shelfId));
request.setAttribute("notUp", list);
return new ActionForward("/background/bookSloon.jsp");
}
/**
* 图书上架
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward editUp(HttpServletRequest request, HttpServletResponse response) throws Exception {
String shelfId=request.getParameter("shelfId");
String bookId=request.getParameter("bookId");
int i=bd.editState(Integer.parseInt(shelfId),Integer.parseInt(bookId));
if(i>0){
String twoShelfId=request.getParameter("twoShelfId");//二级书目录
//根据shelfId查找货架名称
if(twoShelfId==""){
List list= bd.findTwoContent();
//查找所有没有未上架的图书
List st= bd.findAllNotUp();
request.setAttribute("upTwo", list);
request.setAttribute("notUp", st);
return new ActionForward("/background/bookSloon.jsp");
}
BookShelfVo bv= dao.findShelfName(Integer.parseInt(twoShelfId));
BookShelfVo vo=new BookShelfVo();
// BookInfoVo vo=new BookInfoVo();
vo.setShelfId(Integer.parseInt(twoShelfId));
vo.setShelfName(bv.getShelfName());
request.setAttribute("shelf", vo);
List list2= bd.findTwoContent();
request.setAttribute("upTwo", list2);
List list= bd.findNotUpByShelfId(Integer.parseInt(twoShelfId));
request.setAttribute("notUp", list);
return new ActionForward("/background/bookSloon.jsp");
}
return null;
}
/**
* 在添加图书时查找二级级目录
*/
public ActionForward findTwo(HttpServletRequest request, HttpServletResponse response) throws Exception {
// String shelfId= request.getParameter("twoContent");
List list= bd.findTwoContent();
request.setAttribute("twoContent", list);
return new ActionForward("/background/merchandiseInformationAdd.jsp");
}
/**
* 查找二级目录的同时也要显示一级目录
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward findTwoBookContent(HttpServletRequest request, HttpServletResponse response) throws Exception {
//获取一级书架id
String shelfId=request.getParameter("shelfId");
//根据货架Id查询货架Name
BookShelfVo bv= dao.findShelfName(Integer.parseInt(shelfId));
BookShelfVo shelfVo=new BookShelfVo();
shelfVo.setShelfId(Integer.parseInt(shelfId));
shelfVo.setShelfName(bv.getShelfName());
request.setAttribute("shelf", shelfVo);
List listOne= dao.findOneBookshelf();
request.setAttribute("oneBookContent", listOne);
List listTwo= dao.findTwoBookshelfName(Integer.parseInt(shelfId));
request.setAttribute("twoBookContent", listTwo);
return new ActionForward("/background/merchandiseInformationList.jsp");
}
/**
* 实现多种不同查询
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward findAllBook(HttpServletRequest request, HttpServletResponse response) throws Exception {
String bookName= request.getParameter("bookType");
String pId=request.getParameter("pid");
String sId=request.getParameter("sid");
List list=null;
if(bookName=="" && pId=="" && sId==""){
list= bd.findAllBook();
}else if(pId=="" && sId==""){
list= bd.findBookByName(bookName);
if(list.size()==0){
return new ActionForward("/background/sorry.jsp");
}
}else if(sId=="" && bookName==""){
list= bd.findBookByOneId(Integer.parseInt(pId));
if(list.size()==0){
return new ActionForward("/background/sorry.jsp");
}
}else if(bookName==""){
list= bd.findBookByTwoId(Integer.parseInt(sId));
if(list.size()==0){
return new ActionForward("/background/sorry.jsp");
}
}else if(bookName!="" && pId!="" && sId!=""){
list= bd.findBookByTwoIdAndName(Integer.parseInt(sId), bookName);
if(list.size()==0){
return new ActionForward("/background/sorry.jsp");
}
}
request.setAttribute("book_list", list);
return new ActionForward("/bookContent.do");
}
/**
* 添加图书信息
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward saveBookInfo(HttpServletRequest request, HttpServletResponse response) throws Exception {
String name="";
String author="";
String publish="";
String prices="";
String discount="";
String content="";
String show="";
String text="";
String picturePath="";
String picture="";
request.setCharacterEncoding("UTF-8");
RequestContext requestContext = new ServletRequestContext(request);
if (FileUpload.isMultipartContent(requestContext)) {
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setRepository(new File(TomCatVO.getTomCatPath()+"/picture/buffer/"));
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(2000000);
List items = new ArrayList();
try {
items = upload.parseRequest(request);
} catch (FileUploadException e1) {
e1.printStackTrace();
System.out.println("文件上传发生错误" + e1.getMessage());
}
for (int i=0;i<items.size();i++){
FileItem fileItem = (FileItem) items.get(i);
if(fileItem.isFormField()){
if("bookName".equals(fileItem.getFieldName()))
{
//文本框里面的值
name=fileItem.getString("UTF-8");
}
if("bookAuthor".equals(fileItem.getFieldName()))
{
author=fileItem.getString("UTF-8");
}
if("bookPublish".equals(fileItem.getFieldName()))
{
publish=fileItem.getString("UTF-8");
}
if("prices".equals(fileItem.getFieldName()))
{
prices=fileItem.getString("UTF-8");
}
if("bookDiscount".equals(fileItem.getFieldName()))
{
discount=fileItem.getString("UTF-8");
}
if("twoContent".equals(fileItem.getFieldName()))
{
content=fileItem.getString("UTF-8");
}
if("show".equals(fileItem.getFieldName()))
{
show=fileItem.getString("UTF-8");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -