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