Esempio n. 1
0
 /**
  * 上传活动剪影模块的图片
  *
  * @param items
  * @param dir
  * @return
  */
 public static String uploadHdjy(List<FileItem> items, String dir, int hdid) {
   String filePath = "";
   String fileName;
   Date date = new Date();
   SimpleDateFormat format = new SimpleDateFormat("HH-mm-ss");
   if (items == null || items.isEmpty()) {
     return "";
   }
   for (FileItem item : items) {
     if (!item.isFormField()) {
       try {
         String type = item.getName().substring((item.getName().lastIndexOf(".")));
         fileName = item.getName().substring(0, item.getName().indexOf("."));
         fileName = fileName + "(" + format.format(date) + ")" + type;
         if (!Constants.PICTURE_TYPE.contains(type.toLowerCase())) { // 限制文件上传类型
           return "";
         }
         File tempFile = new File(dir);
         if (!tempFile.exists()) { // 如果文件夹不存在
           tempFile.mkdirs(); // 创建一个新的空文件夹
         }
         zoomOut(item.getInputStream(), fileName, dir);
         filePath = dir + "\\" + fileName;
         // 把上传的活动剪影的信息同步写入数据库
         String filename = dir + "\\" + fileName;
         String temp = filename.substring(filename.indexOf("image") - 1);
         String databaseName = temp.replaceAll("\\\\", "/");
         Sthd sthd = new Sthd();
         sthd.setHdid(hdid);
         Hyberbin hyb = new Hyberbin(sthd, true);
         sthd = hyb.showOne("select hdid,hdsj from sthd");
         Hdjy hdjy = new Hdjy();
         hyb.changeTable(hdjy);
         hdjy.setHdid(hdid);
         hdjy.setJytp(databaseName);
         hdjy.setJysj(sthd.getHdsj());
         hyb.insert("jyid");
         hyb.reallyClose();
       } catch (Exception ex) {
         Logger.getLogger(Util.class.getName()).log(Level.SEVERE, null, ex);
       }
     }
   }
   return filePath;
 }
Esempio n. 2
0
 /**
  * 批量删除时用到的简便方法
  *
  * @param hyb 数据库操作
  * @param str 批量值
  * @param fieldName 删除的条件
  * @return
  */
 public static String getDeleteSql(Hyberbin hyb, String[] str, String fieldName) {
   String sql = "";
   for (int i = 0; i < str.length; i++) { // 得到所要删除的主贴的id
     hyb.addParmeter(str[i]);
     sql += " or " + fieldName + "=?";
   }
   sql = sql.substring(3);
   return sql;
 }