Repository navigation
Expand file tree
/
Copy pathSectionInfoDAO.java
More file actions
executable file
·141 lines (130 loc) · 3.8 KB
/
Copy pathSectionInfoDAO.java
File metadata and controls
executable file
·141 lines (130 loc) · 3.8 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package com.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.entity.SectionInfo;
import com.page.*;
public class SectionInfoDAO {
private BaseDAO dao = new BaseDAO();
private ResultSet rs = null;
private List<NavigationPage> list = new ArrayList<NavigationPage>();
/**
* 根据版块id,获得所有子版块
*
* @param sId
* 版块编号
* @return List<SectionInfo> 返回一个集合
*/
public List<SectionInfo> getSectionById(Integer sId) {
List<SectionInfo> list = new ArrayList<SectionInfo>();//版块列表
String sql = "select * from sectionInfo " +
"where sparentId = ?";//根据版块编号查找子版块
try {
rs = dao.executeQuery(sql, new Object[]{sId });//执行查询
while (rs != null && rs.next()) { //如果查找到记录
SectionInfo section = new SectionInfo();//版块信息对象
section.setSid(rs.getInt("sId")); //设置版块编号
section.setSmasterid(rs.getInt("sMasterId"));//设置版主编号
section.setSname(rs.getString("sName")); //设置版块名称
section.setSparentid(rs.getInt("sParentId"));//设置父版块编号
section.setStopiccount(rs.getInt("sTopicCount"));//设置版块主题数
list.add(section);//添加版块对象
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
dao.closeResultSet(); //关闭结果集
dao.closeStatement(); //关闭处理对象
dao.closeConnection(); //关闭连接对象
}
return list; //返回版块列表
}
/**
* 根据id,获得它的父版块信息
*
* @param id
* 版块编号
* @return List<SectionInfo> 返回一个对象
*/
public SectionInfo getPSectionById(Integer id) {
SectionInfo section = null;
String sql = "select * from sectionInfo where sId = ?";
try {
rs = dao.executeQuery(sql, new Object[] { id });
if (rs != null && rs.next()) {
section = new SectionInfo();
section.setSid(rs.getInt("sId"));
section.setSmasterid(rs.getInt("sMasterId"));
section.setSname(rs.getString("sName"));
section.setSparentid(rs.getInt("sParentId"));
section.setStopiccount(rs.getInt("sTopicCount"));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
dao.closeResultSet();
dao.closeStatement();
dao.closeConnection();
}
return section;
}
/**
* 根据版块id获得导航条
*
* @param sId
* 版块编号
* @return List<String> 返回一个集合 注意:如果在同一个类中多次调用此方法,则必须调用clearList()清除上一次的结果
*/
public List<NavigationPage> getNavigationMenuById(Integer sId) {
String sql = "select sParentId,sName,sId from sectionInfo where sid = ?";
try {
rs = dao.executeQuery(sql, new Object[] { sId });
if (rs != null && rs.next()) {
NavigationPage temp = new NavigationPage();
temp.setParentid(rs.getInt("sParentId"));
temp.setSid(rs.getInt("sId"));
temp.setSname(rs.getString("sName"));
list.add(temp);
this.getNavigationMenuById(rs.getInt("sParentId"));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
dao.closeResultSet();
dao.closeStatement();
dao.closeConnection();
}
return list;
}
/**
* 清空list对象
*/
public void clearList() {
this.list.clear();
}
/**
* 根据版块id判断是否父版块
*
* @param sId
* 版块编号
* @return Boolean 返回一个布尔型
*/
public Boolean isParentById(Integer sId) {
String sql = "select * from sectionInfo where sid = ? and sParentId = 0";
try {
rs = dao.executeQuery(sql, new Object[] { sId });
if (rs != null && rs.next()) {
return true;
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
dao.closeResultSet();
dao.closeStatement();
dao.closeConnection();
}
return false;
}
}