📄 sectioninfodao.java
字号:
/*
Author:青鸟学子
QQ:64578820
Msn:foart@hotmail.com
*/
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;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -