Administrator
2023-02-15 ffffbd25e21205601cb9ae60e93ebb2e31b9607e
提交 | 用户 | 时间
58d006 1 package com.mandi.dao.common;
A 2
3 import java.nio.file.Files;
4 import java.nio.file.Paths;
5
6 import javax.servlet.ServletContext;
7
8 import org.hibernate.Session;
9
10 import com.google.gson.JsonArray;
11 import com.google.gson.JsonElement;
12 import com.google.gson.JsonObject;
13 import com.google.gson.JsonParser;
14 import com.mandi.common.JSONobj;
15
16
17 public class Daomethod {
18     public static int countpages(int count,int pagesize)
19     {
20         if(pagesize==0)
21             return 0;
22         int pages=(count/pagesize)+((count%pagesize==0)?0:1);
23         return pages;
24     }
25     
26     /**
27      * 
28      * @param count
29      * @param pagesize
30      * @return 
31      * @author mengly 
32      * @version 创建时间:2016年7月23日 下午7:28:02
33      */
34     public static int countpage(int count,int pagesize)
35     {
36         if(pagesize==0)
37             return 0;
38         //int count=((Number)dao.getSQLOne_noclose(sql)).intValue();
39         int page=(count/pagesize)-((count%pagesize==0)?1:0);
40         return page;
41     }
42     
43     
44     
45     /**
46      * 
47      * @param imgs,json字符串,[{url:"sss",name:"sfsd",size:121},{url:"sss",name:"sfsd",size:121},{url:"sss",name:"sfsd",size:121}]
48      * @param c
49      */
50     public static void removefiles(String imgs,ServletContext c)
51     {
52         if(imgs==null||imgs.isEmpty())
53             return;
54         try {
55             JsonParser jp=new JsonParser();
56             JsonArray ja=jp.parse(imgs).getAsJsonArray();
57             for (JsonElement jsonElement : ja) {
58                 JsonObject jo=jsonElement.getAsJsonObject();
59                 String url=JSONobj.getstring(jo, "url");
60                 String realpath=c.getRealPath(url);
61                 Files.delete(Paths.get(realpath));
62             }
63         } catch (Exception e) {
64             e.printStackTrace();
65         }
66     }
67     /**
68      * 
69      * @param s
70      * @return 
71      * @author mengly 
72      * @version 创建时间:2015年9月15日 下午12:47:53
73      */
74     public static boolean checksession(Session s)
75     {
76         if(s==null)
77             return false;
78         Workcheckconnection wc= new Workcheckconnection();
79         s.doWork(wc);
80         return wc.isFlg();
81     }
82     
83 }