Repository navigation
Expand file tree
/
Copy pathExcelAction.java
More file actions
executable file
·68 lines (58 loc) · 1.6 KB
/
Copy pathExcelAction.java
File metadata and controls
executable file
·68 lines (58 loc) · 1.6 KB
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
package basis;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import admin.Admin;
import com.opensymphony.xwork2.ActionSupport;
public class ExcelAction extends ActionSupport {
private List<Object> list = new ArrayList<>();
private static final long serialVersionUID = 1L;
private File excelPath;
@Override
public String execute() throws Exception {
Session session = Hfsession.init();
Transaction tx = session.beginTransaction();
try {
Query q = session.createQuery("from Admin");
list = q.list();
tx.commit();
Hfsession.close();
} catch (Exception e) {
e.printStackTrace();
}
String[] str = new String[2];
str[0] = "姓名";
str[1] = "密码";
Excel.exportExcel("我嚓.xls", str,list);
return SUCCESS;
}
public String importExcel(){
try {
Session session = Hfsession.init();
Transaction tx = session.beginTransaction();
InputStream fis = new FileInputStream(excelPath);
List<Admin> admins = new ArrayList<>();
admins = Excel.importExcel(fis);
for(Admin info:admins) {
session.save(info);
}
tx.commit();
Hfsession.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return SUCCESS;
}
public File getExcelPath() {
return excelPath;
}
public void setExcelPath(File excelPath) {
this.excelPath = excelPath;
}
}