package com.zhiyou100.dao.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.sun.crypto.provider.RSACipher;
import com.zhiyou100.dao.NoticeDao;
import com.zhiyou100.entity.NoticeDo;
import com.zhiyou100.util.DBUtil;
import com.zhiyou100.util.NoticeSearchTypeName;
public class NoticeDaoImpl implements NoticeDao {
@Override
public List<NoticeDo> listNotice(long pageIndex) {
List<NoticeDo> list = new ArrayList<NoticeDo>();
try (Connection connection = DBUtil.INSTANCE.getConnection();) {
String sql = "SELECT n.id,u.name,n.title,d.name,n.content,n.begin_time,n.end_time FROM notice as n,user as u,department as d "
+ "WHERE n.is_delete =0 AND n.user_id =u.id AND n.department_id=d.id LIMIT ?,5";
try (PreparedStatement prepareStatement = connection.prepareStatement(sql);) {
prepareStatement.setLong(1, pageIndex);
try (ResultSet executeQuery = prepareStatement.executeQuery();) {
while (executeQuery.next()) {
NoticeDo noticeDo = new NoticeDo();
noticeDo.setId(executeQuery.getLong(1));
noticeDo.setUserName(executeQuery.getString(2));
noticeDo.setContent(executeQuery.getString(3));
noticeDo.setDepartmentName(executeQuery.getString(4));
noticeDo.setContent(executeQuery.getString(5));
noticeDo.setBeginTime(executeQuery.getDate(6));
noticeDo.setEndTime(executeQuery.getDate(7));
list.add(noticeDo);
}
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
@Override
public long countNotice() {
long count = 0;
try (Connection connection = DBUtil.INSTANCE.getConnection();) {
String sql = "SELECT COUNT(*) FROM notice as n, user as u, department as d WHERE n.is_delete = 0 AND n.user_id = u.id AND n.department_id = d.id;";
try (PreparedStatement prepareStatement = connection.prepareStatement(sql);) {
try (ResultSet executeQuery = prepareStatement.executeQuery();) {
while (executeQuery.next()) {
count = executeQuery.getInt(1);
}
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return count;
}
@Override
public List<NoticeDo> listNotice(String keyword, NoticeSearchTypeName type, long pageIndex) {
ArrayList<NoticeDo> list = new ArrayList<NoticeDo>();
try (Connection connection = DBUtil.INSTANCE.getConnection();) {
String sql = null;
switch (type) {
case NOTICE_TITLE:
sql = "SELECT n.id, u.name, n.title, d.name, n.content, n.begin_time, n.end_time FROM notice as n, user as u, department as d WHERE n.is_delete = 0 AND n.title like ? AND n.user_id = u.id AND n.department_id = d.id LIMIT ?, 5;";
break;
case NOTICE_CONTENT:
sql = "SELECT n.id, u.name, n.title, d.name, n.content, n.begin_time, n.end_time FROM notice as n, user as u, department as d WHERE n.is_delete = 0 AND n.content like ? AND n.user_id = u.id AND n.department_id = d.id LIMIT ?, 5;";
break;
case USER_NAME:
sql = "SELECT n.id, u.name, n.title, d.name, n.content, n.begin_time, n.end_time FROM notice as n, user as u, department as d WHERE n.is_delete = 0 AND u.name like ? AND n.user_id = u.id AND n.department_id = d.id LIMIT ?, 5;";
break;
case DEPARTMENT_NAME:
sql = "SELECT n.id, u.name, n.title, d.name, n.content, n.begin_time, n.end_time FROM notice as n, user as u, department as d WHERE n.is_delete = 0 AND d.name like ? AND n.user_id = u.id AND n.department_id = d.id LIMIT ?, 5;";
break;
default:
break;
}
try (PreparedStatement preparedStatement = connection.prepareStatement(sql);) {
preparedStatement.setString(1, "%" + keyword + "%");
preparedStatement.setLong(2, pageIndex);
try (ResultSet executeQuery = preparedStatement.executeQuery();) {
while (executeQuery.next()) {
NoticeDo noticeDo = new NoticeDo();
noticeDo.setId(executeQuery.getLong(1));
noticeDo.setUserName(executeQuery.getString(2));
noticeDo.setTitle(executeQuery.getString(3));
noticeDo.setDepartmentName(executeQuery.getString(4));
noticeDo.setContent(executeQuery.getString(5));
noticeDo.setBeginTime(executeQuery.getDate(6));
noticeDo.setEndTime(executeQuery.getDate(7));
list.add(noticeDo);
}
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
@Override
public long countNotice(String keyword, NoticeSearchTypeName type) {
long count = 0;
try (Connection connection = DBUtil.INSTANCE.getConnection();) {
String sql = "";
switch (type) {
case NOTICE_CONTENT:
sql = "SELECT COUNT(*) FROM notice as n, user as u, department as d WHERE n.is_delete = 0 AND n.title like ? AND n.user_id = u.id AND n.department_id = d.id;";
break;
case NOTICE_TITLE:
sql = "SELECT COUNT(*) FROM notice as n, user as u, department as d WHERE n.is_delete = 0 AND n.title like ? AND n.user_id = u.id AND n.department_id = d.id;";
break;
case USER_NAME:
sql = "SELECT COUNT(*) FROM notice as n, user as u, department as d WHERE n.is_delete = 0 AND n.title like ? AND n.user_id = u.id AND n.department_id = d.id;";
break;
case DEPARTMENT_NAME:
sql = "SELECT COUNT(*) FROM notice as n, user as u, department as d WHERE n.is_delete = 0 AND n.title like ? AND n.user_id = u.id AND n.department_id = d.id;";
break;
default:
break;
}
try (PreparedStatement prepareStatement = connection.prepareStatement(sql);) {
prepareStatement.setString(1, "%" + keyword + "%");
try (ResultSet executeQuery = prepareStatement.executeQuery();) {
while (executeQuery.next()) {
count = executeQuery.getLong(1);
}
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return count;
}
@Override
public NoticeDo getNoticeById(long id) {
NoticeDo noticeDo = null;
try (Connection connection = DBUtil.INSTANCE.getConnection();) {
String sql = "SELECT n.id, u.name, n.title, d.name, n.content, n.begin_time, n.end_time, d.id FROM notice as n, user as u, department as d WHERE n.is_delete = 0 AND n.id = ? AND n.user_id = u.id AND n.department_id = d.id;";
try (PreparedStatement prepareStatement = connection.prepareStatement(sql);) {
prepareStatement.setLong(1, id);
try (ResultSet executeQuery = prepareStatement.executeQuery();) {
while (executeQuery.next()) {
noticeDo = new NoticeDo();
noticeDo.setId(executeQuery.getLong(1));
noticeDo.setUserName(executeQuery.getString(2));
noticeDo.setTitle(executeQuery.getString(3));
noticeDo.setDepartmentName(executeQuery.getString(4));
noticeDo.setContent(executeQuery.getString(5));
noticeDo.setBeginTime(executeQuery.getDate(6));
noticeDo.setEndTime(executeQuery.getDate(7));
noticeDo.setDepartmentId(executeQuery.getLong(8));
}
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return noticeDo;
}
@Override
public void addNotice(NoticeDo notice) {
try (Connection connection = DBUtil.INSTANCE.getConnection();) {
String sql = "INSERT INTO notice(user_id, title, department_id, content, begin_time, end_time) VALUES (?, ?, ?, ?, ?, ?);";
try (PreparedStatement prepareStatement = connection.prepareStatement(sql);) {
prepareStatement.setLong(1, notice.getUserId());
prepareStatement.setString(2, notice.getTitle());
prepareStatement.setLong(3, notice.getDepartmentId());
prepareStatement.setString(4, notice.getContent());
prepareStatement.setDate(5, notice.getBeginTime());
prepareStatement.setDate(6, notice.getEndTime());
prepareStatement.executeUpdate();
没有合适的资源?快使用搜索试试~ 我知道了~
客户关系管理系统 使用(JavaBean+Jsp+Servlet) 搭建.zip
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共280个文件
svn-base:127个
java:81个
jsp:34个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 173 浏览量
2023-08-10
23:19:13
上传
评论
收藏 1.4MB ZIP 举报
温馨提示
用Java写的项目,项目真实可靠,能正常运行,欢迎下载使用。用Java写的项目,项目真实可靠,能正常运行,欢迎下载使用。用Java写的项目,项目真实可靠,能正常运行,欢迎下载使用。用Java写的项目,项目真实可靠,能正常运行,欢迎下载使用。用Java写的项目,项目真实可靠,能正常运行,欢迎下载使用。用Java写的项目,项目真实可靠,能正常运行,欢迎下载使用。用Java写的项目,项目真实可靠,能正常运行,欢迎下载使用。用Java写的项目,项目真实可靠,能正常运行,欢迎下载使用。用Java写的项目,项目真实可靠,能正常运行,欢迎下载使用。用Java写的项目,项目真实可靠,能正常运行,欢迎下载使用。用Java写的项目,项目真实可靠,能正常运行,欢迎下载使用。用Java写的项目,项目真实可靠,能正常运行,欢迎下载使用。
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![jar](https://img-home.csdnimg.cn/images/20210720083455.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 280 条
- 1
- 2
- 3
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/2e5877b4fb644fb3a0267656bb6912ba_java_cjkl.jpg!1)
c++服务器开发
- 粉丝: 3045
- 资源: 4461
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)