巴巴运动网学习笔记(51-55)

1.完成上传文件的分页显示(显示id,文件路径,上传日期)

a.UploadAction

View Code
 1 package cnblogs.xiaoqiu.web.action.upload;
 2 import java.util.LinkedHashMap;
 3 import javax.annotation.Resource;
 4 import javax.servlet.http.HttpServletRequest;
 5 import javax.servlet.http.HttpServletResponse;
 6 import org.apache.struts.action.Action;
 7 import org.apache.struts.action.ActionForm;
 8 import org.apache.struts.action.ActionForward;
 9 import org.apache.struts.action.ActionMapping;
10 import org.springframework.stereotype.Controller;
11 import cnblogs.xiaoqiu.bean.PagingBean;
12 import cnblogs.xiaoqiu.bean.ScrollResult;
13 import cnblogs.xiaoqiu.bean.upload.UploadFile;
14 import cnblogs.xiaoqiu.service.upload.UploadService;
15 import cnblogs.xiaoqiu.web.action.formbean.UploadForm;
16 @Controller("/control/upload/list")
17 public class UploadAction extends Action {
18     @Resource(name="uploadServiceImpl")
19     private UploadService uploadService;
20     @Override
21     public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)
22     throws Exception {
23         UploadForm uploadForm = (UploadForm)form;
24         int pageCounts = 10;
25         int currentPage = uploadForm.getCurrentPage();
26         int begin = (currentPage-1)*pageCounts;
27         LinkedHashMap<String, String> orderHashMap = new LinkedHashMap<String, String>();
28         orderHashMap.put("id", "desc");
29         ScrollResult<UploadFile> scrollResult = uploadService.getScrollResult(UploadFile.class, begin, pageCounts, orderHashMap);
30         PagingBean<UploadFile> pagingBean = new PagingBean<UploadFile>(currentPage,scrollResult,pageCounts);
31         request.setAttribute("pagingBean", pagingBean);
32         return mapping.findForward("list");
33     }
34     
35 }

b.uploadfile.jsp

View Code
 1 <%@ page contentType="text/html;charset=UTF-8" %>
 2 <%@ include file="/WEB-INF/page/share/taglib.jsp" %>
 3 <html>
 4 <head>
 5 <title>上传文件管理</title>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <link rel="stylesheet" href="/css/vip.css" type="text/css">
 8 <script language="JavaScript">
 9     function topage(page){
10         var form = document.forms[0];
11         form.currentPage.value = page;
12         form.submit();
13     }
14 
15     function selectAll(allSelect,selects){
16         var state = allSelect.checked;
17         if(selects.length){
18             for(var i=0;i<selects.length;i++){
19                 selects[i].checked = state;
20             }
21         }else{
22             selects.checked = state;
23         }
24     }
25 
26     function deletesFile(myForm){
27         myForm.method.value="delete";
28         myForm.action="/control/upload/manager.do";
29         myForm.submit();
30     }
31 </script>
32 <SCRIPT language=JavaScript src="/js/FoshanRen.js">
33 </SCRIPT>
34 </head>
35 
36 <body bgcolor="#FFFFFF" text="#000000" marginwidth="0" marginheight="0">
37 <html:form action="/control/upload/list.do" method="post">
38 <html:hidden property="currentPage"/>
39 <input type="hidden" name="method"/>
40   <table width="98%" border="0" cellspacing="1" cellpadding="2" align="center">
41     <tr ><td colspan="4"  bgcolor="6f8ac4" align="right">
42         <%@ include file="/WEB-INF/page/share/paging.jsp" %>
43     </td></tr>
44     <tr>
45       <td width="10%" bgcolor="6f8ac4"> <div align="center"></div></td>
46       <td width="20%" bgcolor="6f8ac4"> <div align="center"><font color="#FFFFFF">代号</font></div></td>
47       <td width="35%" bgcolor="6f8ac4"> <div align="center"><font color="#FFFFFF">文件</font></div></td>
48       <td width="35%" nowrap bgcolor="6f8ac4"> <div align="center"><font color="#FFFFFF">上传日期</font></div></td>
49     </tr>
50     <!-----------------------LOOP START---------------------------->
51 <c:forEach items="${pagingBean.scrollResult.resultList}" var="uploadFile">
52     <tr>
53       <td bgcolor="f5f5f5"> <div align="center"><input type="checkbox" name="deleteIds" value="${uploadFile.id }"/></div></td>
54       <td bgcolor="f5f5f5"> <div align="center">${uploadFile.id }</div></td> 
55       <td bgcolor="f5f5f5"> <div align="center"><a href="${uploadFile.filePath }" target="_blank">${uploadFile.filePath }</a></div></td>
56       <td bgcolor="f5f5f5"> <div align="center">${uploadFile.uploadTime }</div></td>
57     </tr>
58 </c:forEach>
59     <!----------------------LOOP END------------------------------->
60     <tr> 
61       <td bgcolor="f5f5f5" colspan="6" align="center"><table width="100%" border="0" cellspacing="1" cellpadding="3">
62           <tr> 
63               <td width="10%">
64               <div align="center"><input type="checkbox" name="deleteAll" onclick="javascript:selectAll(this,this.form.deleteIds)"/></div>
65               </td>
66               <td width="90%">
67               <input name="deleteBtn" type="button" class="frm_btn" id="deleteBtn" onClick="javascript:deletesFile(this.form)" value="删除文件"> &nbsp;&nbsp;
68             </td>
69           </tr>
70         </table></td>
71     </tr>
72   </table>
73 </html:form>
74 </body>
75 </html>

c.UploadForm

View Code
 1 package cnblogs.xiaoqiu.web.action.formbean;
 2 
 3 import org.apache.struts.upload.FormFile;
 4 
 5 public class UploadForm extends BaseForm {
 6     private static final long serialVersionUID = 1724297881513682925L;
 7     
 8     private FormFile uploadFile;
 9     private int id;
10     private int[] deleteIds;
11     
12     
13     public int[] getDeleteIds() {
14         return deleteIds;
15     }
16 
17     public void setDeleteIds(int[] deleteIds) {
18         this.deleteIds = deleteIds;
19     }
20 
21     public int getId() {
22         return id;
23     }
24 
25     public void setId(int id) {
26         this.id = id;
27     }
28 
29     public FormFile getUploadFile() {
30         return uploadFile;
31     }
32     
33     public void setUploadFile(FormFile uploadFile) {
34         this.uploadFile = uploadFile;
35     }
36     
37 }

2.完成文件列表的全选功能(添加复选框,编写javascript函数,formbean中添加ids[])
3.完成上传文件的多选删除功能

View Code
 1 public ActionForward delete(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)
 2     throws Exception {
 3         UploadForm uploadForm = (UploadForm)form;
 4         int[] ids = uploadForm.getDeleteIds();
 5         for(int i=0;i<ids.length;i++){
 6             UploadFile uploadFile = uploadService.find(UploadFile.class, ids[i]);
 7             String filePath = uploadFile.getFilePath();
 8             if(filePath!=null){
 9                 File file = new File(request.getSession().getServletContext().getRealPath(filePath));
10                 file.delete();
11                 uploadService.delete(UploadFile.class, uploadFile.getId());
12                 request.setAttribute("message", "删除成功");
13             }
14             else {
15                 request.setAttribute("message", "删除失败");
16             }
17         }
18         request.setAttribute("jump", PropertiesTool.getValue("control.upload.list"));
19         return mapping.findForward("message");
20     }

4.产品管理模块的详细分析与设计
a.产品的相关操作:分页显示,添加,修改,查询,上架/下架
b.产品的相关字段

5.创建产品实体对象

View Code
  1 package cnblogs.xiaoqiu.bean.product;
  2 
  3 import java.io.Serializable;
  4 import java.util.Date;
  5 
  6 import javax.persistence.Entity;
  7 @Entity
  8 public class Product implements Serializable{
  9     private static final long serialVersionUID = 8608943966862111393L;
 10     private String id;
 11     private String name;
 12     private Brand brand;
 13     private ProductType productType;
 14     private String model;
 15     private float basePrice = 0;
 16     private float marketPrice = 0;
 17     private float sellPrice = 0;
 18     private String description;
 19     private String buyExplain;
 20     private Date createTime = new Date();
 21     private boolean isVisible = true;
 22     private float weight = 0;
 23     private boolean isCommend = false;
 24     private int clickCount = 0;
 25     private int sellCount = 0;
 26     private Sex sexRequest = Sex.NONE;
 27     public String getId() {
 28         return id;
 29     }
 30     public void setId(String id) {
 31         this.id = id;
 32     }
 33     public String getName() {
 34         return name;
 35     }
 36     public void setName(String name) {
 37         this.name = name;
 38     }
 39     public Brand getBrand() {
 40         return brand;
 41     }
 42     public void setBrand(Brand brand) {
 43         this.brand = brand;
 44     }
 45     public ProductType getProductType() {
 46         return productType;
 47     }
 48     public void setProductType(ProductType productType) {
 49         this.productType = productType;
 50     }
 51     public String getModel() {
 52         return model;
 53     }
 54     public void setModel(String model) {
 55         this.model = model;
 56     }
 57     public float getBasePrice() {
 58         return basePrice;
 59     }
 60     public void setBasePrice(float basePrice) {
 61         this.basePrice = basePrice;
 62     }
 63     public float getMarketPrice() {
 64         return marketPrice;
 65     }
 66     public void setMarketPrice(float marketPrice) {
 67         this.marketPrice = marketPrice;
 68     }
 69     public float getSellPrice() {
 70         return sellPrice;
 71     }
 72     public void setSellPrice(float sellPrice) {
 73         this.sellPrice = sellPrice;
 74     }
 75     public String getDescription() {
 76         return description;
 77     }
 78     public void setDescription(String description) {
 79         this.description = description;
 80     }
 81     public String getBuyExplain() {
 82         return buyExplain;
 83     }
 84     public void setBuyExplain(String buyExplain) {
 85         this.buyExplain = buyExplain;
 86     }
 87     public Date getCreateTime() {
 88         return createTime;
 89     }
 90     public void setCreateTime(Date createTime) {
 91         this.createTime = createTime;
 92     }
 93     public boolean isVisible() {
 94         return isVisible;
 95     }
 96     public void setVisible(boolean isVisible) {
 97         this.isVisible = isVisible;
 98     }
 99     public float getWeight() {
100         return weight;
101     }
102     public void setWeight(float weight) {
103         this.weight = weight;
104     }
105     public boolean isCommend() {
106         return isCommend;
107     }
108     public void setCommend(boolean isCommend) {
109         this.isCommend = isCommend;
110     }
111     public int getClickCount() {
112         return clickCount;
113     }
114     public void setClickCount(int clickCount) {
115         this.clickCount = clickCount;
116     }
117     public int getSellCount() {
118         return sellCount;
119     }
120     public void setSellCount(int sellCount) {
121         this.sellCount = sellCount;
122     }
123     public Sex getSexRequest() {
124         return sexRequest;
125     }
126     public void setSexRequest(Sex sexRequest) {
127         this.sexRequest = sexRequest;
128     }
129     
130     
131 }
View Code
1 package cnblogs.xiaoqiu.bean.product;
2 
3 public enum Sex {
4     NONE{public String getName(){return "男女不限";}},
5     MALE{public String getName(){return "男";}},
6     FEMALE{public String getName(){return "女";}};
7     public abstract String getName();
8 }

 

posted @ 2012-04-12 17:02  xiao秋  阅读(595)  评论(0编辑  收藏  举报