📄 editcontentimpl.java
字号:
package com.myContent.service.impl;
import java.sql.SQLException;
import java.util.List;
import org.apache.log4j.Logger;
import com.gd.jdbc.impl.GdDbConnection;
import com.myContent.dao.ContentDAO;
import com.myContent.dao.impl.ContentDAOImpl;
import com.myContent.service.EditContent;
import com.myContent.vo.Content;
public class EditContentImpl implements EditContent{
static Logger logger = Logger.getLogger(EditContentImpl.class.getName());
private ContentDAO contentDao = null;
/**该方法用来获取所有的内容
*/
public List getAllContent() throws Exception {
List list = null;
//取得连接
GdDbConnection con = new GdDbConnection(this);
try {
contentDao = new ContentDAOImpl(con.getConnection(this));
//获取所有内容类别
list = contentDao.queryAllContent();
} catch (SQLException e) {
logger.error(e);
} catch(Exception e) {
logger.error(e);
} finally {
//关闭连接
con.close(this);
return list;
}
}
/**该方法用来实现向数据库查询内容
*/
public Content queryContent(Content content) throws Exception {
Content content1 = null;
//取得连接
GdDbConnection con = new GdDbConnection(this);
try {
contentDao = new ContentDAOImpl(con.getConnection(this));
//获取内容
content1 = contentDao.queryContent(content.getId());
} catch (SQLException e) {
logger.error(e);
} catch(Exception e) {
logger.error(e);
} finally {
//关闭连接
con.close(this);
return content1;
}
}
/**该方法用来实现向数据库新增内容
*/
public int saveContent(Content content) throws Exception {
int counts = 0;
//取得连接
GdDbConnection con = new GdDbConnection(this);
try {
contentDao = new ContentDAOImpl(con.getConnection(this));
//开始进行事务处理
con.beginTransaction(this);
//新增内容
counts = contentDao.createContent(content);
//事务提交
con.commit(this);
} catch (SQLException e) {
logger.error(e);
} catch(Exception e) {
//事务回滚
con.rollback(this);
logger.error(e);
} finally {
//关闭连接
con.close(this);
return counts;
}
}
/**该方法用来实现向数据库修改内容
*/
public int updateContent(Content content) throws Exception {
int counts = 0;
//取得连接
GdDbConnection con = new GdDbConnection(this);
try {
contentDao = new ContentDAOImpl(con.getConnection(this));
//开始进行事务处理
con.beginTransaction(this);
//新增内容
counts = contentDao.updateContent(content);
//事务提交
con.commit(this);
} catch (SQLException e) {
logger.error(e);
} catch(Exception e) {
//事务回滚
con.rollback(this);
logger.error(e);
} finally {
//关闭连接
con.close(this);
return counts;
}
}
/**该方法用来实现向数据库删除内容
*/
public int deleteContent(Content content) throws Exception {
int counts = 0;
//取得连接
GdDbConnection con = new GdDbConnection(this);
try {
contentDao = new ContentDAOImpl(con.getConnection(this));
//开始进行事务处理
con.beginTransaction(this);
//新增内容
counts = contentDao.deleteContent(content);
//事务提交
con.commit(this);
} catch (SQLException e) {
logger.error(e);
} catch(Exception e) {
//事务回滚
con.rollback(this);
logger.error(e);
} finally {
//关闭连接
con.close(this);
return counts;
}
}
/**该方法用来根据类别获取所有的内容
*/
public List getAllContentByType(int typeId) throws Exception {
List list = null;
//取得连接
GdDbConnection con = new GdDbConnection(this);
try {
contentDao = new ContentDAOImpl(con.getConnection(this));
//获取所有内容类别
list = contentDao.queryAllContent(typeId);
} catch (SQLException e) {
logger.error(e);
} catch(Exception e) {
logger.error(e);
} finally {
//关闭连接
con.close(this);
return list;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -