Sfoglia il codice sorgente

【提交内容】:删除personBean FileBean

wangyj18 9 anni fa
parent
commit
1b74c59117

+ 0 - 127
display-server/src/com/ai/server/bean/FileBean.java

@ -1,127 +0,0 @@
1
package com.ai.server.bean;
2

3
import java.io.File;
4
import java.io.FileOutputStream;
5
import java.io.InputStream;
6
import java.io.OutputStream;
7
import java.net.MalformedURLException;
8
import java.util.List;
9

10
import javax.servlet.http.HttpServletRequest;
11

12
import org.apache.commons.fileupload.FileItem;
13
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
14
import org.apache.commons.fileupload.servlet.ServletFileUpload;
15

16
import com.ai.server.core.bean.DisplayBean;
17
import com.ai.server.util.ApplicationPath;
18
import com.ailk.common.data.IData;
19
import com.ailk.common.data.impl.DataMap;
20
import com.ailk.mobile.servlet.ServletManager;
21
import com.ailk.mobile.util.FileUtil;
22
import com.ailk.mobile.util.MobileUtility;
23

24
public class FileBean extends DisplayBean{
25
	
26
	/**
27
	 * 获取文件存储路径
28
	 */
29
	private String getSavePath(HttpServletRequest request, String uploadPath) throws MalformedURLException{
30
		// 目录转换,兼容linux和windows
31
		uploadPath = uploadPath.replace("\\", File.separator).replace("/", File.separator);
32
		// 获取文件需要上传到的路径
33
		String savePath = FileUtil.connectFilePath(ApplicationPath.getFilePath(request), "upload", uploadPath);
34
		return savePath;
35
	}
36
	
37
	/**
38
	 * 获取文件名
39
	 */
40
	private String getFileName(){
41
		return String.valueOf(System.currentTimeMillis());
42
	}
43

44
	public IData uploadFile(IData param) throws Exception{
45
		HttpServletRequest request = ServletManager.getRequest();
46
		if (!ServletFileUpload.isMultipartContent(request)) {
47
			MobileUtility.error("获取的上传文件并非以文件流格式传送,请核查!");
48
		}
49
		String uploadPath = param.getString("UPLOAD_PATH","temp");//没有指定目录则生成临时目录
50
		String savePath = getSavePath(request, uploadPath);
51
		
52
		File file = new File(savePath);
53
		if(! file.exists() && ! file.mkdirs()){
54
			MobileUtility.error("生成上传文件夹失败,无法进行上传操作!");
55
		}
56
		
57
		IData result = new DataMap();//上传成功的返回信息
58
		result.put("SAVE_PATH", savePath);
59
		
60
		String fileName = param.getString("FILE_NAME",getFileName());//没有指定文件名则生成临时文件名
61
		result.put("FILE_NAME", fileName);
62
		
63
		try{
64
			//获得磁盘文件条目工厂
65
			DiskFileItemFactory factory = new DiskFileItemFactory();
66
	        //临时存储室,存储室和最终存储目录可以不同
67
	        factory.setRepository(file);
68
	        //设置缓存的大小,当上传文件超过上限,会使用临时目录.
69
	        factory.setSizeThreshold(5*1024*1024);// 5M
70
	        //文件上传处理
71
	        ServletFileUpload upload = new ServletFileUpload(factory);
72
			
73
        	List<?> fileList = upload.parseRequest(request);
74
            for(int i = 0; i < fileList.size(); i++){
75
            	FileItem item = (FileItem)fileList.get(i);
76
                //获取表单的属性名字
77
                String name = item.getFieldName();
78
                 
79
            	//如果获取的 表单信息是普通的文本信息
80
                if(item.isFormField()){
81
                 	//获取用户具体输入的字符串,因为表单提交过来的是字符串类型的
82
                 	String value = item.getString();
83
                    request.setAttribute(name, value);
84
                    //获取用户保存目录
85
                }else{
86
                	//获取路径名
87
	             	String value = item.getName();
88
	                int start = value.lastIndexOf("\\");
89
	                String filename = value.substring(start + 1);
90
	                //保存文件名
91
	                request.setAttribute(name, filename);
92
	                
93
	                //检查保存目录
94
	                File saveDir = new File(savePath);
95
	         		if(! saveDir.exists() && ! saveDir.mkdirs()){
96
	         			MobileUtility.error("生成上传保存文件夹失败,无法进行上传操作!");
97
	         		}
98
	         		//设置保存文件
99
	                File saveFile = new File(savePath, filename);
100
	                //写到磁盘上
101
	                OutputStream out = new FileOutputStream(saveFile);
102
	                InputStream in = item.getInputStream();
103
	                
104
	                int length = 0;
105
	                byte[] buf = new byte[1024];
106
	                //写出到文件中
107
	                while((length = in.read(buf) ) != -1) {
108
	                    //在BUF数组中取出数据写到(输出流)磁盘上
109
	                    out.write(buf, 0, length);
110
	                }
111
	                out.flush();
112
	                in.close();
113
	                out.close();
114
	                log.debug("获取上传文件的总共的容量:" + item.getSize());
115
	                result.put("size", item.getSize());
116
               }
117
           }
118
       }catch (Exception e) {
119
    	   MobileUtility.error("上传失败", e);
120
       }
121
       return result;
122
	}
123
	
124
	public IData downloadFile(IData param) throws Exception{
125
		return null;
126
	}
127
}

+ 0 - 33
display-server/src/com/ai/server/bean/PersonBean.java

@ -1,33 +0,0 @@
1
package com.ai.server.bean;
2

3
import com.ai.server.core.bean.DisplayBean;
4
import com.ailk.common.data.IData;
5
import com.ailk.common.data.impl.DataMap;
6

7
public class PersonBean extends DisplayBean {
8

9
	public IData getPersonDetailMore(IData param) {
10
		IData result = new DataMap();
11
		int personId = param.getInt("id");
12
		if (personId <= 0) {
13
			throw new RuntimeException("获取参数失败!");
14
		}
15
		if (personId == 1) {
16
			result.put("name", "小胖");
17
			result.put("age", 20);
18
			result.put("gender", "男");
19
			result.put("dept", "移动部门");
20
		} else if (personId == 2) {
21
			result.put("name", "张三");
22
			result.put("age", 22);
23
			result.put("gender", "男");
24
			result.put("dept", "联通部门");
25
		} else if (personId == 3) {
26
			result.put("name", "李四");
27
			result.put("age", 24);
28
			result.put("gender", "女");
29
			result.put("dept", "财务部门");
30
		}
31
		return result;
32
	}
33
}

+ 25 - 0
display-server/src/com/ai/server/bean/SceneBean.java

@ -185,4 +185,29 @@ public class SceneBean extends DisplayBean {
185 185
			return false;
186 186
		}
187 187
	}
188
	
189
	public IData getPersonDetailMore(IData param) {
190
		IData result = new DataMap();
191
		int personId = param.getInt("id");
192
		if (personId <= 0) {
193
			throw new RuntimeException("获取参数失败!");
194
		}
195
		if (personId == 1) {
196
			result.put("name", "小胖");
197
			result.put("age", 20);
198
			result.put("gender", "男");
199
			result.put("dept", "移动部门");
200
		} else if (personId == 2) {
201
			result.put("name", "张三");
202
			result.put("age", 22);
203
			result.put("gender", "男");
204
			result.put("dept", "联通部门");
205
		} else if (personId == 3) {
206
			result.put("name", "李四");
207
			result.put("age", 24);
208
			result.put("gender", "女");
209
			result.put("dept", "财务部门");
210
		}
211
		return result;
212
	}
188 213
}