前台数据封装

   现在我觉得前台没有必要在用前台数据填充javabean来传向后台来处理数据,如果一个程序有几百个表,是不是要用几百个javabean呢?
   把前台所有传向后台的数据封装成Map,传向后台也一样处理.


public boolean isMultipart() {
return !StringUtils.isBlank(request.getContentType()) && request.getContentType().indexOf("multipart/form-data") > -1;
}


private Map<String, Object> createParamMap() {


if (isMultipart()) {


// 上传文件处理
DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);


List<FileItem> fileItemList = null;


try {
fileItemList = upload.parseRequest(request);
} catch (Exception e) {
throw new ServiceException(e);
}


for (FileItem fileItem : fileItemList) {


if (fileItem.isFormField()) {
paramMap.put(fileItem.getFieldName(), fileItem.getString());
} else if (fileItem.getSize() > 0) {
if (!paramMap.containsKey(fileItem.getFieldName())) {
paramMap.put(fileItem.getFieldName(), new ArrayList<FileItem>());
}
((List) paramMap.get(fileItem.getFieldName())).add(fileItem);
}
}
}


{
Enumeration paramNames = request.getParameterNames();


if (paramNames != null) {
while (paramNames.hasMoreElements()) {
String paramName = (String) paramNames.nextElement();
String paramValue = request.getParameter(paramName);
if (paramName != null && !paramName.equals("")) {
      paramMap.put(paramName, paramValue);
}
}
}
}


return paramMap;
}


你可能感兴趣的:(exception,list,String,object,upload,null)