Bootstrap4+MySQL前后端综合实训-Day10-AM【实训汇报-下午返校、项目代码(7个包+7个Html页面)】

电玩女神 2022-12-24 05:58 153阅读 0赞

【Bootstrap4前端框架+MySQL数据库】前后端综合实训【10天课程 博客汇总表 详细笔记】【附:实训所有代码】

目录

实训汇报

数据库——所有SQL语句

工程文件展示

代码

①package com.newcapec.dao;

BaseDao.java

ItemUserDao.java

LogsInfoDao.java

NewItemDao.java

NewsInfoDao.java

UserInfoDao.java

②package com.newcapec.entity;

ItemUserEntity.java

LogsInfoEntity.java

NewItemEntity.java

NewsInfoEntity.java

ResultData.java

UserInfoEntity.java

③package com.newcapec.servlet;

AddUserServlet.java

DeleteUserServlet.java

LoginServlet.java

SelectUserByIdServlet.java

SelectUserByPageServlet.java

UpdateUserServlet.java

④package com.newcapec.servlet.newitem;

AddItemServlet.java

DeleteItemServlet.java

SelectItemByIdServlet.java

SelectItembyUserServlet.java

UpdateItemServlet.java

⑤package com.newcapec.servlet.news;

AddNewsServlet.java

⑥package com.newcapec.test;

TestItemUserDao.java

TestLogsInfoDao.java

TestNewItemDao.java

NewsInfoDao.java

TestUserInfoDao.java

⑦package com.newcapec.utils;

DBUtils.java

MD5Utils.java

pages

item_manager.html

news_manager.html

user_manager.html

index.html

login.html

loginFailure.html

phone.html


实训汇报

从昨天下午就开始实训答辩了。

今天上午,继续答辩。

上午10:00左右,所有的小组答辩完毕。

革命尚未成功,同学仍需努力~

数据库——所有SQL语句

  1. /*
  2. SQLyog Ultimate v12.08 (64 bit)
  3. MySQL - 8.0.20 : Database - zykkk
  4. *********************************************************************
  5. */
  6. /*!40101 SET NAMES utf8 */;
  7. /*!40101 SET SQL_MODE=''*/;
  8. /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
  9. /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
  10. /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
  11. /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
  12. CREATE DATABASE /*!32312 IF NOT EXISTS*/`zykkk` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_hungarian_ci */ /*!80016 DEFAULT ENCRYPTION='N' */;
  13. USE `zykkk`;
  14. /*Table structure for table `item_user` */
  15. DROP TABLE IF EXISTS `item_user`;
  16. CREATE TABLE `item_user` (
  17. `item_user_id` int NOT NULL AUTO_INCREMENT,
  18. `user_id` int DEFAULT NULL,
  19. `item_id` int DEFAULT NULL,
  20. `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  21. `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
  22. `status` int DEFAULT '1' COMMENT '1:启用 0:禁用',
  23. PRIMARY KEY (`item_user_id`),
  24. KEY `FK_Reference_2` (`user_id`),
  25. KEY `FK_Reference_3` (`item_id`),
  26. CONSTRAINT `FK_Reference_2` FOREIGN KEY (`user_id`) REFERENCES `user_info` (`user_id`),
  27. CONSTRAINT `FK_Reference_3` FOREIGN KEY (`item_id`) REFERENCES `new_item` (`item_id`)
  28. ) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_hungarian_ci;
  29. /*Data for the table `item_user` */
  30. insert into `item_user`(`item_user_id`,`user_id`,`item_id`,`create_time`,`update_time`,`status`) values (1,1,2,'2020-11-23 11:24:16','2020-11-25 10:27:54',1),(2,2,4,NULL,'2020-11-25 09:38:17',1),(3,1,1,'2020-11-24 09:19:58','2020-11-25 09:38:21',1),(5,1,18,NULL,'2020-11-25 09:44:16',1),(6,1,27,'2020-11-25 11:11:35','2020-11-25 11:11:35',1),(7,1,28,'2020-11-25 11:17:59','2020-11-25 11:17:59',1),(8,1,29,'2020-11-25 11:29:14','2020-11-25 11:29:14',1),(9,1,30,'2020-11-25 11:30:54','2020-11-25 11:30:54',1),(10,1,31,'2020-11-25 11:36:51','2020-11-25 11:36:51',1),(11,1,32,'2020-11-25 16:26:23','2020-11-25 16:26:23',1),(12,1,33,'2020-11-25 16:26:37','2020-11-25 16:26:37',1),(13,1,34,'2020-11-26 10:01:29','2020-11-26 10:01:29',1),(14,1,35,'2020-11-26 10:28:53','2020-11-26 10:28:53',1);
  31. /*Table structure for table `logs_info` */
  32. DROP TABLE IF EXISTS `logs_info`;
  33. CREATE TABLE `logs_info` (
  34. `logs_id` int NOT NULL AUTO_INCREMENT,
  35. `user_id` int DEFAULT NULL,
  36. `logs_content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_hungarian_ci,
  37. `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  38. `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
  39. PRIMARY KEY (`logs_id`),
  40. KEY `FK_Reference_1` (`user_id`),
  41. CONSTRAINT `FK_Reference_1` FOREIGN KEY (`user_id`) REFERENCES `user_info` (`user_id`)
  42. ) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_hungarian_ci;
  43. /*Data for the table `logs_info` */
  44. insert into `logs_info`(`logs_id`,`user_id`,`logs_content`,`create_time`,`update_time`) values (1,1,NULL,NULL,'2020-11-24 09:27:05'),(2,2,NULL,NULL,'2020-11-24 09:27:12'),(3,4,NULL,NULL,'2020-11-23 11:29:06'),(14,1,'woshishenren','2020-11-24 09:24:52','2020-11-24 09:24:52'),(15,1,'woshishenren','2020-11-24 09:25:58','2020-11-24 09:25:58');
  45. /*Table structure for table `new_item` */
  46. DROP TABLE IF EXISTS `new_item`;
  47. CREATE TABLE `new_item` (
  48. `item_id` int NOT NULL AUTO_INCREMENT,
  49. `item_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_hungarian_ci NOT NULL,
  50. `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  51. `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
  52. `status` int DEFAULT '1' COMMENT '1:启用 0:禁用',
  53. PRIMARY KEY (`item_id`)
  54. ) ENGINE=InnoDB AUTO_INCREMENT=36 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_hungarian_ci;
  55. /*Data for the table `new_item` */
  56. insert into `new_item`(`item_id`,`item_name`,`create_time`,`update_time`,`status`) values (1,'呵呵哒','2020-11-24 15:47:00','2020-11-26 10:28:39',1),(2,'党支部','2020-11-24 15:47:03','2020-11-25 14:44:31',0),(3,'分团委','2020-11-24 15:47:05','2020-11-25 14:43:54',1),(4,'院团委','2020-11-24 15:47:08','2020-11-25 14:44:38',1),(5,'111','2020-11-23 15:22:54','2020-11-25 14:45:55',1),(6,'学生会','2020-11-24 09:27:36','2020-11-25 14:46:01',1),(8,'党支部','2020-11-24 13:51:13','2020-11-25 14:46:07',1),(18,'党支部','2020-11-25 09:11:51','2020-11-25 15:49:06',1),(19,'院团委','2020-11-25 10:42:54','2020-11-25 14:46:16',1),(20,'111','2020-11-25 10:54:12','2020-11-25 14:46:19',1),(21,'学生会','2020-11-25 10:56:21','2020-11-25 14:46:35',1),(22,'党支部','2020-11-25 10:57:35','2020-11-25 14:46:43',1),(23,'分团委','2020-11-25 11:00:20','2020-11-25 14:46:48',1),(24,'院团委','2020-11-25 11:00:47','2020-11-25 14:46:55',1),(25,'qweqwe','2020-11-25 11:01:37','2020-11-25 11:01:37',1),(26,'eqweqweqwe','2020-11-25 11:01:53','2020-11-25 11:01:53',1),(27,'分团委','2020-11-25 11:11:35','2020-11-25 15:49:18',1),(28,'sadsads','2020-11-25 11:17:59','2020-11-25 11:18:40',0),(29,'院团委','2020-11-25 11:29:13','2020-11-25 15:49:25',1),(30,'789','2020-11-25 11:30:54','2020-11-25 11:37:19',0),(31,'zyk','2020-11-25 11:36:51','2020-11-25 11:37:19',0),(32,'委员会','2020-11-25 16:26:23','2020-11-26 08:37:48',0),(33,'委员会~~~','2020-11-25 16:26:37','2020-11-26 10:01:40',1),(34,'演示~','2020-11-26 10:01:29','2020-11-26 10:01:33',0),(35,'筑基修士!!!','2020-11-26 10:28:53','2020-11-26 10:29:14',1);
  57. /*Table structure for table `news_info` */
  58. DROP TABLE IF EXISTS `news_info`;
  59. CREATE TABLE `news_info` (
  60. `new_id` int NOT NULL AUTO_INCREMENT,
  61. `item_id` int DEFAULT NULL,
  62. `news_title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_hungarian_ci NOT NULL,
  63. `news_image` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_hungarian_ci DEFAULT NULL,
  64. `news_content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_hungarian_ci,
  65. `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  66. `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
  67. PRIMARY KEY (`new_id`),
  68. KEY `FK_Reference_4` (`item_id`),
  69. CONSTRAINT `FK_Reference_4` FOREIGN KEY (`item_id`) REFERENCES `new_item` (`item_id`)
  70. ) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_hungarian_ci;
  71. /*Data for the table `news_info` */
  72. insert into `news_info`(`new_id`,`item_id`,`news_title`,`news_image`,`news_content`,`create_time`,`update_time`) values (1,2,'蓝桥杯比赛',NULL,NULL,NULL,'2020-11-23 09:27:39'),(2,3,'新学期学费',NULL,NULL,NULL,'2020-11-23 09:28:10'),(3,1,'拔河比赛',NULL,'拔河比赛要使劲!!!','2020-11-25 14:57:28','2020-11-25 14:57:32'),(4,18,'街舞比赛',NULL,'一起摇摆~','2020-11-25 15:54:09','2020-11-25 15:54:11'),(10,27,'数学建模',NULL,'一起加油!','2020-11-25 16:10:02','2020-11-25 22:17:19'),(11,29,'班班唱',NULL,'《走向复兴》','2020-11-25 16:12:23','2020-11-25 16:12:23'),(12,1,'篮球比赛',NULL,'冲冲冲~','2020-11-25 16:13:04','2020-11-25 16:13:04'),(13,1,'NECCS',NULL,'冲呀~','2020-11-25 16:27:22','2020-11-26 08:38:03'),(14,18,'卓见杯',NULL,'啦啦啦~','2020-11-25 17:41:32','2020-11-25 22:17:56'),(15,33,'动则升阳',NULL,'年轻不养生,年老养医生!','2020-11-26 00:12:42','2020-11-26 00:12:42'),(16,33,'11月26日',NULL,'筑基修士','2020-11-26 10:02:20','2020-11-26 10:02:20'),(17,35,'大家好',NULL,'333','2020-11-26 10:29:35','2020-11-26 10:29:35'),(18,35,'大家好!!!',NULL,'333','2020-11-26 10:29:45','2020-11-26 10:29:45');
  73. /*Table structure for table `user_info` */
  74. DROP TABLE IF EXISTS `user_info`;
  75. CREATE TABLE `user_info` (
  76. `user_id` int NOT NULL AUTO_INCREMENT,
  77. `user_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_hungarian_ci NOT NULL,
  78. `user_pwd` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_hungarian_ci NOT NULL,
  79. `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  80. `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
  81. `status` int DEFAULT '1' COMMENT '1:启用 0:禁用',
  82. PRIMARY KEY (`user_id`)
  83. ) ENGINE=InnoDB AUTO_INCREMENT=120 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_hungarian_ci;
  84. /*Data for the table `user_info` */
  85. insert into `user_info`(`user_id`,`user_name`,`user_pwd`,`create_time`,`update_time`,`status`) values (1,'宋书航','1','2020-11-23 09:30:16','2020-11-25 22:16:25',1),(2,'雨柔子','1','2020-11-23 11:25:41','2020-11-25 22:16:25',1),(4,'王五','1','2020-11-23 11:25:58','2020-11-25 22:16:26',0),(5,'赵柳','1','2020-11-23 11:26:12','2020-11-25 22:16:26',0),(8,'田七','1','2020-11-23 11:26:29','2020-11-25 22:16:27',0),(9,'田七','1','2020-11-23 15:03:23','2020-11-25 22:16:28',0),(10,'田七','1','2020-11-23 15:03:43','2020-11-25 22:16:28',0),(11,'戴沐白','1','2020-11-24 10:45:06','2020-11-25 22:16:29',1),(12,'张小凡','1','2020-11-24 10:45:29','2020-11-25 22:16:29',1),(13,'userName2','1','2020-11-24 10:45:29','2020-11-25 22:16:30',0),(15,'碧瑶','1','2020-11-24 10:45:29','2020-11-25 22:16:31',1),(16,'赵恋凡','1','2020-11-24 10:45:29','2020-11-25 22:16:31',1),(17,'李长寿','1','2020-11-24 10:45:29','2020-11-25 22:16:32',1),(18,'蓝梦娥','1','2020-11-24 10:45:29','2020-11-25 22:16:33',1),(22,'路明非','123456','2020-11-24 10:45:29','2020-11-25 17:44:31',1),(23,'楚子航','123456','2020-11-24 10:45:29','2020-11-25 22:14:26',1),(33,'乔微尼','123456','2020-11-24 10:45:29','2020-11-25 23:05:48',1),(97,'userName86','123456','2020-11-24 10:45:32','2020-11-24 10:45:32',1),(98,'userName87','123456','2020-11-24 10:45:32','2020-11-24 10:45:32',1),(99,'userName88','123456','2020-11-24 10:45:32','2020-11-24 10:45:32',1),(100,'userName89','123456','2020-11-24 10:45:32','2020-11-24 10:45:32',1),(101,'2020年好运来~','123456','2020-11-24 10:45:32','2020-11-26 10:01:06',1),(102,'333','123456','2020-11-24 10:45:32','2020-11-26 10:28:14',1),(103,'666','888','2020-11-24 10:45:32','2020-11-26 10:28:26',1),(104,'userName93','123456','2020-11-24 10:45:32','2020-11-26 10:00:54',0),(105,'userName94','123456','2020-11-24 10:45:32','2020-11-26 10:00:47',0),(106,'userName95','123456','2020-11-24 10:45:32','2020-11-26 10:00:47',0),(107,'userName96','123456','2020-11-24 10:45:32','2020-11-26 10:00:47',0),(108,'userName97','123456','2020-11-24 10:45:32','2020-11-26 10:00:47',0),(109,'userName98','123456','2020-11-24 10:45:32','2020-11-25 10:12:58',0),(110,'userName99','123456','2020-11-24 10:45:32','2020-11-25 10:12:58',0),(111,'userName100','123456','2020-11-24 10:45:33','2020-11-25 10:12:58',0),(115,'萧潜','1','2020-11-25 23:00:16','2020-11-25 23:00:16',1),(116,'演示视频','haha','2020-11-26 10:00:33','2020-11-26 10:27:37',0),(117,'啦啦啦','1','2020-11-26 10:27:14','2020-11-26 10:27:37',0),(118,'演示视频','222','2020-11-26 10:27:23','2020-11-26 10:27:37',0),(119,'实训小组hyy','111','2020-11-26 14:37:14','2020-11-26 14:37:14',1);
  86. /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
  87. /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
  88. /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
  89. /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

工程文件展示

20210130161831257.png 20210130162001637.png 20210130162016540.png watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NDk0OTEzNQ_size_16_color_FFFFFF_t_70

代码

①package com.newcapec.dao;

BaseDao.java

  1. package com.newcapec.dao;
  2. import java.sql.SQLException;
  3. import java.util.List;
  4. /**
  5. * JDBC在后期需要使用hibernate/mybatis优化
  6. *
  7. * @author user
  8. *
  9. * @param <T>
  10. */
  11. public interface BaseDao<T> {
  12. // public int insert(T t) throws ClassNotFoundException, SQLException;
  13. public boolean deleteById(int id) throws ClassNotFoundException, SQLException;
  14. public boolean batchDeleteById(int[] ids) throws ClassNotFoundException, SQLException;
  15. public boolean update(T t) throws ClassNotFoundException, SQLException;
  16. public T selectById(int id) throws ClassNotFoundException, SQLException;
  17. public List<T> selectAll() throws ClassNotFoundException, SQLException;
  18. }

ItemUserDao.java

  1. package com.newcapec.dao;
  2. import java.sql.Connection;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.util.ArrayList;
  7. import java.util.Date;
  8. import java.util.List;
  9. import com.newcapec.entity.ItemUserEntity;
  10. import com.newcapec.utils.DBUtils;
  11. public class ItemUserDao implements BaseDao<ItemUserEntity> {
  12. public boolean insert(ItemUserEntity t) throws ClassNotFoundException, SQLException {
  13. boolean flag = false;
  14. // 获取与数据库的连接
  15. Connection connection = DBUtils.openConn();
  16. // ?表示占位符 可以解决sql注入的问题
  17. String sql = "insert into item_user (user_id,item_id,create_time) values (?,?,now())";
  18. PreparedStatement statement = connection.prepareStatement(sql);
  19. statement.setInt(1, t.getUserId());
  20. statement.setInt(2, t.getItemId());
  21. // 执行sql语句
  22. int count = statement.executeUpdate();
  23. if (count > 0) {
  24. flag = true;
  25. }
  26. statement.close();
  27. connection.close();
  28. return flag;
  29. }
  30. @Override
  31. public boolean deleteById(int id) throws ClassNotFoundException, SQLException {
  32. boolean flag = false;
  33. Connection connection = DBUtils.openConn();
  34. String sql = "delete from item_user where item_user_id = ?";
  35. PreparedStatement statement = connection.prepareStatement(sql);
  36. statement.setInt(1, id);
  37. int count = statement.executeUpdate();
  38. if (count > 0) {
  39. flag = true;
  40. }
  41. statement.close();
  42. connection.close();
  43. return flag;
  44. }
  45. @Override
  46. public boolean update(ItemUserEntity t) throws ClassNotFoundException, SQLException {
  47. boolean flag = false;
  48. // 获取连接
  49. Connection connection = DBUtils.openConn();
  50. // sql语句
  51. String sql = "update item_user set user_id = ?,item_id = ? where item_user_id = ?";
  52. // 预处理对象
  53. PreparedStatement statement = connection.prepareStatement(sql);
  54. // 添加参数
  55. statement.setInt(1, t.getUserId());
  56. statement.setInt(2, t.getItemId());
  57. statement.setInt(3, t.getItemUserId());
  58. // 执行预处理对象
  59. int count = statement.executeUpdate();
  60. if (count > 0) {
  61. flag = true;
  62. }
  63. statement.close();
  64. connection.close();
  65. return flag;
  66. }
  67. @Override
  68. public ItemUserEntity selectById(int id) throws ClassNotFoundException, SQLException {
  69. ItemUserEntity ItemUserEntity = null;
  70. Connection connection = DBUtils.openConn();
  71. String sql = "select * from item_user where item_user_id = ?";
  72. PreparedStatement statement = connection.prepareStatement(sql);
  73. statement.setInt(1, id);
  74. ResultSet resultSet = statement.executeQuery();
  75. while (resultSet.next()) {
  76. int itemUserId = resultSet.getInt("item_user_id");
  77. int userId = resultSet.getInt("user_id");
  78. int itemId = resultSet.getInt("item_id");
  79. Date createTime = resultSet.getTimestamp("create_time");
  80. Date updateTime = resultSet.getTimestamp("update_time");
  81. ItemUserEntity = new ItemUserEntity(itemUserId, userId, itemId, createTime, updateTime);
  82. }
  83. resultSet.close();
  84. statement.close();
  85. connection.close();
  86. return ItemUserEntity;
  87. }
  88. @Override
  89. public List<ItemUserEntity> selectAll() throws ClassNotFoundException, SQLException {
  90. List<ItemUserEntity> list = new ArrayList<>();
  91. Connection connection = DBUtils.openConn();
  92. String sql = "select * from item_user and status = 1";
  93. PreparedStatement statement = connection.prepareStatement(sql);
  94. ResultSet resultSet = statement.executeQuery();
  95. while (resultSet.next()) {
  96. int itemUserId = resultSet.getInt("item_user_id");
  97. int userId = resultSet.getInt("user_id");
  98. int itemId = resultSet.getInt("item_id");
  99. Date createTime = resultSet.getTimestamp("create_time");
  100. Date updateTime = resultSet.getTimestamp("update_time");
  101. ItemUserEntity itemUserEntity = new ItemUserEntity(itemUserId, userId, itemId, createTime, updateTime);
  102. list.add(itemUserEntity);
  103. }
  104. resultSet.close();
  105. statement.close();
  106. connection.close();
  107. return list;
  108. }
  109. @Override
  110. public boolean batchDeleteById(int[] ids) throws ClassNotFoundException, SQLException {
  111. // TODO 自动生成的方法存根
  112. return false;
  113. }
  114. }

LogsInfoDao.java

  1. package com.newcapec.dao;
  2. import java.sql.Connection;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.util.ArrayList;
  7. import java.util.Date;
  8. import java.util.List;
  9. import com.newcapec.entity.LogsInfoEntity;
  10. import com.newcapec.utils.DBUtils;
  11. public class LogsInfoDao implements BaseDao<LogsInfoEntity> {
  12. public boolean insert(LogsInfoEntity t) throws ClassNotFoundException, SQLException {
  13. boolean flag = false;
  14. Connection connection = DBUtils.openConn();
  15. String sql = "insert into logs_info (user_id,logs_content,create_time) values (?,?,now())";
  16. PreparedStatement statement = connection.prepareStatement(sql);
  17. statement.setInt(1, t.getUserId());
  18. statement.setString(2, t.getLogsContent());
  19. int count = statement.executeUpdate();
  20. if (count > 0) {
  21. flag = true;
  22. }
  23. statement.close();
  24. connection.close();
  25. return flag;
  26. }
  27. @Override
  28. public boolean deleteById(int id) throws ClassNotFoundException, SQLException {
  29. boolean flag = false;
  30. Connection connection = DBUtils.openConn();
  31. String sql = "delete from logs_info where logs_id = ?";
  32. PreparedStatement statement = connection.prepareStatement(sql);
  33. statement.setInt(1, id);
  34. int count = statement.executeUpdate();
  35. if (count > 0) {
  36. flag = true;
  37. }
  38. statement.close();
  39. connection.close();
  40. return flag;
  41. }
  42. @Override
  43. public boolean update(LogsInfoEntity t) throws ClassNotFoundException, SQLException {
  44. boolean flag = false;
  45. Connection connection = DBUtils.openConn();
  46. String sql = "update logs_info set user_id = ?, logs_content = ? where logs_id = ?";
  47. PreparedStatement statement = connection.prepareStatement(sql);
  48. statement.setInt(1, t.getUserId());
  49. statement.setString(2, t.getLogsContent());
  50. statement.setInt(3, t.getLogsId());
  51. int count = statement.executeUpdate();
  52. if (count > 0) {
  53. flag = true;
  54. }
  55. statement.close();
  56. connection.close();
  57. return flag;
  58. }
  59. @Override
  60. public LogsInfoEntity selectById(int id) throws ClassNotFoundException, SQLException {
  61. LogsInfoEntity logsInfoEntity = null;
  62. Connection connection = DBUtils.openConn();
  63. String sql = "select * from logs_info where logs_id = ?";
  64. PreparedStatement statement = connection.prepareStatement(sql);
  65. statement.setInt(1, id);
  66. ResultSet resultSet = statement.executeQuery();
  67. while (resultSet.next()) {
  68. int newsId = resultSet.getInt("logs_id");
  69. int itemId = resultSet.getInt("user_id");
  70. String logsContent = resultSet.getString("logs_content");
  71. Date createTime = resultSet.getDate("create_time");
  72. Date updateTime = resultSet.getDate("update_time");
  73. logsInfoEntity = new LogsInfoEntity(newsId, itemId, logsContent, createTime, updateTime);
  74. }
  75. resultSet.close();
  76. statement.close();
  77. connection.close();
  78. return logsInfoEntity;
  79. }
  80. @Override
  81. public List<LogsInfoEntity> selectAll() throws ClassNotFoundException, SQLException {
  82. List<LogsInfoEntity> list = new ArrayList<LogsInfoEntity>();
  83. Connection connection = DBUtils.openConn();
  84. String sql = "select * from logs_info";
  85. PreparedStatement statement = connection.prepareStatement(sql);
  86. ResultSet resultSet = statement.executeQuery();
  87. while (resultSet.next()) {
  88. int newsId = resultSet.getInt("logs_id");
  89. int itemId = resultSet.getInt("user_id");
  90. String logsContent = resultSet.getString("logs_content");
  91. Date createTime = resultSet.getDate("create_time");
  92. Date updateTime = resultSet.getDate("update_time");
  93. LogsInfoEntity logsInfoEntity = new LogsInfoEntity(newsId, itemId, logsContent, createTime, updateTime);
  94. list.add(logsInfoEntity);
  95. }
  96. resultSet.close();
  97. statement.close();
  98. connection.close();
  99. return list;
  100. }
  101. @Override
  102. public boolean batchDeleteById(int[] ids) throws ClassNotFoundException, SQLException {
  103. // TODO 自动生成的方法存根
  104. return false;
  105. }
  106. }

NewItemDao.java

  1. package com.newcapec.dao;
  2. import java.sql.Connection;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7. import java.util.ArrayList;
  8. import java.util.Date;
  9. import java.util.List;
  10. import com.newcapec.entity.NewItemEntity;
  11. import com.newcapec.utils.DBUtils;
  12. public class NewItemDao implements BaseDao<NewItemEntity> {
  13. public int insert(NewItemEntity t) throws ClassNotFoundException, SQLException {
  14. Connection connection = DBUtils.openConn();
  15. String sql = "insert into new_item (item_name,create_time) values (?,now())";
  16. PreparedStatement statement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
  17. statement.setString(1, t.getItemName());
  18. statement.executeUpdate();
  19. ResultSet resultSet = statement.getGeneratedKeys();
  20. resultSet.next();
  21. int id = resultSet.getInt(1);
  22. statement.close();
  23. connection.close();
  24. return id;
  25. }
  26. @Override
  27. public boolean deleteById(int id) throws ClassNotFoundException, SQLException {
  28. boolean flag = false;
  29. // 获取连接
  30. Connection connection = DBUtils.openConn();
  31. // sql语句
  32. String sql = "delete from new_item where item_id = ?";
  33. // 预处理对象
  34. PreparedStatement statement = connection.prepareStatement(sql);
  35. // 添加参数
  36. statement.setInt(1, id);
  37. // 执行预处理对象
  38. int count = statement.executeUpdate();
  39. if (count > 0) {
  40. flag = true;
  41. }
  42. statement.close();
  43. connection.close();
  44. return flag;
  45. }
  46. @Override
  47. public boolean update(NewItemEntity t) throws ClassNotFoundException, SQLException {
  48. boolean flag = false;
  49. // 获取连接
  50. Connection connection = DBUtils.openConn();
  51. // sql语句
  52. String sql = "update new_item set item_name = ? where item_id = ?";
  53. // 预处理对象
  54. PreparedStatement statement = connection.prepareStatement(sql);
  55. // 添加参数
  56. statement.setString(1, t.getItemName());
  57. statement.setInt(2, t.getItemId());
  58. // 执行预处理对象
  59. int count = statement.executeUpdate();
  60. if (count > 0) {
  61. flag = true;
  62. }
  63. statement.close();
  64. connection.close();
  65. return flag;
  66. }
  67. @Override
  68. public NewItemEntity selectById(int id) throws ClassNotFoundException, SQLException {
  69. NewItemEntity newItemEntity = null;
  70. Connection connection = DBUtils.openConn();
  71. String sql = "select * from new_item where item_id = ?";
  72. PreparedStatement statement = connection.prepareStatement(sql);
  73. statement.setInt(1, id);
  74. ResultSet resultSet = statement.executeQuery();
  75. while (resultSet.next()) {
  76. int itemId = resultSet.getInt("item_id");
  77. String itemName = resultSet.getString("item_name");
  78. Date createTime = resultSet.getTimestamp("create_time");
  79. Date updateTime = resultSet.getTimestamp("update_time");
  80. newItemEntity = new NewItemEntity(itemId, itemName, createTime, updateTime);
  81. }
  82. resultSet.close();
  83. statement.close();
  84. connection.close();
  85. return newItemEntity;
  86. }
  87. @Override
  88. public List<NewItemEntity> selectAll() throws ClassNotFoundException, SQLException {
  89. List<NewItemEntity> list = new ArrayList<>();
  90. Connection connection = DBUtils.openConn();
  91. String sql = "select * from new_item ";
  92. PreparedStatement statement = connection.prepareStatement(sql);
  93. ResultSet resultSet = statement.executeQuery();
  94. while (resultSet.next()) {
  95. int itemId = resultSet.getInt("item_id");
  96. String itemName = resultSet.getString("item_name");
  97. Date createTime = resultSet.getTimestamp("create_time");
  98. Date updateTime = resultSet.getTimestamp("update_time");
  99. NewItemEntity newItemEntity = new NewItemEntity(itemId, itemName, createTime, updateTime);
  100. list.add(newItemEntity);
  101. }
  102. resultSet.close();
  103. statement.close();
  104. connection.close();
  105. return list;
  106. }
  107. public List<NewItemEntity> selectAllByUserId(int userId) throws ClassNotFoundException, SQLException {
  108. List<NewItemEntity> list = new ArrayList<>();
  109. Connection connection = DBUtils.openConn();
  110. String sql = "SELECT new_item.`item_id`,new_item.`item_name`,new_item.`create_time`,new_item.`update_time` FROM new_item \r\n"
  111. + " INNER JOIN item_user ON new_item.`item_id` = item_user.`item_id`\r\n"
  112. + " INNER JOIN user_info ON user_info.`user_id` = item_user.`user_id`\r\n"
  113. + " WHERE user_info.user_id = ? and new_item.status = 1";
  114. PreparedStatement statement = connection.prepareStatement(sql);
  115. statement.setInt(1, userId);
  116. ResultSet resultSet = statement.executeQuery();
  117. while (resultSet.next()) {
  118. int itemId = resultSet.getInt("item_id");
  119. String itemName = resultSet.getString("item_name");
  120. Date createTime = resultSet.getTimestamp("create_time");
  121. Date updateTime = resultSet.getTimestamp("update_time");
  122. NewItemEntity newItemEntity = new NewItemEntity(itemId, itemName, createTime, updateTime);
  123. list.add(newItemEntity);
  124. }
  125. resultSet.close();
  126. statement.close();
  127. connection.close();
  128. return list;
  129. }
  130. public int selectAllByUserIdCount(int userId) throws ClassNotFoundException, SQLException {
  131. int count = 0;
  132. Connection connection = DBUtils.openConn();
  133. String sql = "SELECT count(*) as allCount FROM new_item \r\n"
  134. + " INNER JOIN item_user ON new_item.`item_id` = item_user.`item_id`\r\n"
  135. + " INNER JOIN user_info ON user_info.`user_id` = item_user.`user_id`\r\n where new_item.status = 1 AND user_info.`user_id` = ?";
  136. PreparedStatement statement = connection.prepareStatement(sql);
  137. statement.setInt(1, userId);
  138. ResultSet resultSet = statement.executeQuery();
  139. while (resultSet.next()) {
  140. count = resultSet.getInt("allCount");
  141. }
  142. resultSet.close();
  143. statement.close();
  144. connection.close();
  145. return count;
  146. }
  147. @Override
  148. public boolean batchDeleteById(int[] ids) throws ClassNotFoundException, SQLException {
  149. boolean flag = false;
  150. // 获取连接
  151. Connection connection = DBUtils.openConn();
  152. // sql语句
  153. // String sql = "delete from new_item where item_id = ?";
  154. String sql = "update new_item set status = 0 where item_id = ?";
  155. // 预处理对象
  156. PreparedStatement statement = connection.prepareStatement(sql);
  157. // 添加参数
  158. for (int id : ids) {
  159. statement.setInt(1, id);
  160. statement.addBatch();
  161. }
  162. int[] result = statement.executeBatch();
  163. // 执行预处理对象
  164. // int count = statement.executeUpdate();
  165. if (result.length > 0) {
  166. flag = true;
  167. }
  168. statement.close();
  169. connection.close();
  170. return flag;
  171. }
  172. }

NewsInfoDao.java

  1. package com.newcapec.dao;
  2. import java.sql.Connection;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.util.ArrayList;
  7. import java.util.Date;
  8. import java.util.List;
  9. import com.newcapec.entity.NewsInfoEntity;
  10. import com.newcapec.utils.DBUtils;
  11. public class NewsInfoDao implements BaseDao<NewsInfoEntity> {
  12. public boolean insert(NewsInfoEntity t) throws ClassNotFoundException, SQLException {
  13. boolean flag = false;
  14. Connection connection = DBUtils.openConn();
  15. String sql = "insert into news_info (item_id,news_title,news_content,create_time) values (?,?,?,now())";
  16. PreparedStatement statement = connection.prepareStatement(sql);
  17. statement.setInt(1, t.getItemId());
  18. statement.setString(2, t.getNewsTitle());
  19. statement.setString(3, t.getNewsContent());
  20. int count = statement.executeUpdate();
  21. if (count > 0) {
  22. flag = true;
  23. }
  24. statement.close();
  25. connection.close();
  26. return flag;
  27. }
  28. @Override
  29. public boolean deleteById(int id) throws ClassNotFoundException, SQLException {
  30. boolean flag = false;
  31. Connection connection = DBUtils.openConn();
  32. String sql = "delete from news_info where news_id = ?";
  33. PreparedStatement statement = connection.prepareStatement(sql);
  34. statement.setInt(1, id);
  35. int count = statement.executeUpdate();
  36. if (count > 0) {
  37. flag = true;
  38. }
  39. statement.close();
  40. connection.close();
  41. return flag;
  42. }
  43. @Override
  44. public boolean update(NewsInfoEntity t) throws ClassNotFoundException, SQLException {
  45. boolean flag = false;
  46. Connection connection = DBUtils.openConn();
  47. String sql = "update news_info set item_id = ?, news_title = ?, news_image = ?, news_content=? where news_id = ?";
  48. PreparedStatement statement = connection.prepareStatement(sql);
  49. statement.setInt(1, t.getItemId());
  50. statement.setString(2, t.getNewsTitle());
  51. statement.setString(3, t.getNewsImage());
  52. statement.setString(4, t.getNewsContent());
  53. statement.setInt(5, t.getNewsId());
  54. int count = statement.executeUpdate();
  55. if (count > 0) {
  56. flag = true;
  57. }
  58. statement.close();
  59. connection.close();
  60. return flag;
  61. }
  62. @Override
  63. public NewsInfoEntity selectById(int id) throws ClassNotFoundException, SQLException {
  64. NewsInfoEntity newsInfoEntity = null;
  65. Connection connection = DBUtils.openConn();
  66. String sql = "select * from news_info where news_id = ?";
  67. PreparedStatement statement = connection.prepareStatement(sql);
  68. statement.setInt(1, id);
  69. ResultSet resultSet = statement.executeQuery();
  70. while (resultSet.next()) {
  71. int newsId = resultSet.getInt("news_id");
  72. int itemId = resultSet.getInt("item_id");
  73. String newsTitle = resultSet.getString("news_title");
  74. String newsContent = resultSet.getString("news_content");
  75. String newsImage = resultSet.getString("news_image");
  76. Date createTime = resultSet.getDate("create_time");
  77. Date updateTime = resultSet.getDate("update_time");
  78. newsInfoEntity = new NewsInfoEntity(newsId, itemId, newsTitle, newsImage, newsContent, createTime,
  79. updateTime);
  80. }
  81. resultSet.close();
  82. statement.close();
  83. connection.close();
  84. return newsInfoEntity;
  85. }
  86. @Override
  87. public List<NewsInfoEntity> selectAll() throws ClassNotFoundException, SQLException {
  88. List<NewsInfoEntity> list = new ArrayList<NewsInfoEntity>();
  89. Connection connection = DBUtils.openConn();
  90. String sql = "select * from news_info";
  91. PreparedStatement statement = connection.prepareStatement(sql);
  92. ResultSet resultSet = statement.executeQuery();
  93. while (resultSet.next()) {
  94. int newsId = resultSet.getInt("news_id");
  95. int itemId = resultSet.getInt("item_id");
  96. String newsTitle = resultSet.getString("news_title");
  97. String newsContent = resultSet.getString("news_content");
  98. String newsImage = resultSet.getString("news_image");
  99. Date createTime = resultSet.getDate("create_time");
  100. Date updateTime = resultSet.getDate("update_time");
  101. NewsInfoEntity newsInfoEntity = new NewsInfoEntity(newsId, itemId, newsTitle, newsImage, newsContent,
  102. createTime, updateTime);
  103. list.add(newsInfoEntity);
  104. }
  105. resultSet.close();
  106. statement.close();
  107. connection.close();
  108. return list;
  109. }
  110. @Override
  111. public boolean batchDeleteById(int[] ids) throws ClassNotFoundException, SQLException {
  112. // TODO 自动生成的方法存根
  113. return false;
  114. }
  115. }

UserInfoDao.java

  1. package com.newcapec.dao;
  2. import java.sql.Connection;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.util.ArrayList;
  7. import java.util.Date;
  8. import java.util.List;
  9. import com.newcapec.entity.UserInfoEntity;
  10. import com.newcapec.utils.DBUtils;
  11. public class UserInfoDao implements BaseDao<UserInfoEntity> {
  12. public UserInfoEntity login(String userName, String userPwd) throws ClassNotFoundException, SQLException {
  13. UserInfoEntity userInfoEntity = null;
  14. Connection connection = DBUtils.openConn();
  15. String sql = "select * from user_info where user_name = ? and user_pwd = ?";
  16. PreparedStatement statement = connection.prepareStatement(sql);
  17. statement.setString(1, userName);
  18. statement.setString(2, userPwd);
  19. ResultSet resultSet = statement.executeQuery();
  20. while (resultSet.next()) {
  21. int userId = resultSet.getInt("user_id");
  22. Date createTime = resultSet.getTimestamp("create_time");
  23. Date updateTime = resultSet.getTimestamp("update_time");
  24. userInfoEntity = new UserInfoEntity(userId, userName, userPwd, createTime, updateTime);
  25. }
  26. resultSet.close();
  27. statement.close();
  28. connection.close();
  29. return userInfoEntity;
  30. }
  31. public boolean insert(UserInfoEntity t) throws ClassNotFoundException, SQLException {
  32. boolean flag = false;
  33. // 获取与数据库的连接
  34. Connection connection = DBUtils.openConn();
  35. // ?表示占位符 可以解决sql注入的问题
  36. String sql = "insert into user_info (user_name,user_pwd,create_time) values (?,?,now())";
  37. PreparedStatement statement = connection.prepareStatement(sql);
  38. statement.setString(1, t.getUserName());
  39. statement.setString(2, t.getUserPwd());
  40. // 执行sql语句
  41. int count = statement.executeUpdate();
  42. if (count > 0) {
  43. flag = true;
  44. }
  45. statement.close();
  46. connection.close();
  47. return flag;
  48. }
  49. @Override
  50. public boolean deleteById(int id) throws ClassNotFoundException, SQLException {
  51. boolean flag = false;
  52. // 获取连接
  53. Connection connection = DBUtils.openConn();
  54. // sql语句
  55. // String sql = "delete from user_info where user_id = ?";
  56. String sql = "update user_info set status = 0 where user_id = ?";
  57. // 预处理对象
  58. PreparedStatement statement = connection.prepareStatement(sql);
  59. // 添加参数
  60. statement.setInt(1, id);
  61. // 执行预处理对象
  62. int count = statement.executeUpdate();
  63. if (count > 0) {
  64. flag = true;
  65. }
  66. statement.close();
  67. connection.close();
  68. return flag;
  69. }
  70. @Override
  71. public boolean update(UserInfoEntity t) throws ClassNotFoundException, SQLException {
  72. boolean flag = false;
  73. // 获取连接
  74. Connection connection = DBUtils.openConn();
  75. // sql语句
  76. String sql = "update user_info set user_name = ?,user_pwd = ? where user_id = ?";
  77. // 预处理对象
  78. PreparedStatement statement = connection.prepareStatement(sql);
  79. // 添加参数
  80. statement.setString(1, t.getUserName());
  81. statement.setString(2, t.getUserPwd());
  82. statement.setInt(3, t.getUserId());
  83. // 执行预处理对象
  84. int count = statement.executeUpdate();
  85. if (count > 0) {
  86. flag = true;
  87. }
  88. statement.close();
  89. connection.close();
  90. return flag;
  91. }
  92. @Override
  93. public UserInfoEntity selectById(int id) throws ClassNotFoundException, SQLException {
  94. UserInfoEntity userInfoEntity = null;
  95. Connection connection = DBUtils.openConn();
  96. String sql = "select * from user_info where user_id = ? and status = 1";
  97. PreparedStatement statement = connection.prepareStatement(sql);
  98. statement.setInt(1, id);
  99. ResultSet resultSet = statement.executeQuery();
  100. while (resultSet.next()) {
  101. int userId = resultSet.getInt("user_id");
  102. String userName = resultSet.getString("user_name");
  103. String userPwd = resultSet.getString("user_pwd");
  104. Date createTime = resultSet.getTimestamp("create_time");
  105. Date updateTime = resultSet.getTimestamp("update_time");
  106. userInfoEntity = new UserInfoEntity(userId, userName, userPwd, createTime, updateTime);
  107. }
  108. resultSet.close();
  109. statement.close();
  110. connection.close();
  111. return userInfoEntity;
  112. }
  113. @Override
  114. public List<UserInfoEntity> selectAll() throws ClassNotFoundException, SQLException {
  115. List<UserInfoEntity> list = new ArrayList<>();
  116. Connection connection = DBUtils.openConn();
  117. String sql = "select * from user_info";
  118. PreparedStatement statement = connection.prepareStatement(sql);
  119. ResultSet resultSet = statement.executeQuery();
  120. while (resultSet.next()) {
  121. int userId = resultSet.getInt("user_id");
  122. String userName = resultSet.getString("user_name");
  123. String userPwd = resultSet.getString("user_pwd");
  124. Date createTime = resultSet.getTimestamp("create_time");
  125. Date updateTime = resultSet.getTimestamp("update_time");
  126. UserInfoEntity userInfoEntity = new UserInfoEntity(userId, userName, userPwd, createTime, updateTime);
  127. list.add(userInfoEntity);
  128. }
  129. resultSet.close();
  130. statement.close();
  131. connection.close();
  132. return list;
  133. }
  134. public List<UserInfoEntity> selectByPage(int offset, int limit) throws ClassNotFoundException, SQLException {
  135. List<UserInfoEntity> list = new ArrayList<>();
  136. Connection connection = DBUtils.openConn();
  137. String sql = "select * from user_info where status = 1 limit ?,?";
  138. PreparedStatement statement = connection.prepareStatement(sql);
  139. statement.setInt(1, offset);
  140. statement.setInt(2, limit);
  141. ResultSet resultSet = statement.executeQuery();
  142. while (resultSet.next()) {
  143. int userId = resultSet.getInt("user_id");
  144. String userName = resultSet.getString("user_name");
  145. String userPwd = resultSet.getString("user_pwd");
  146. Date createTime = resultSet.getTimestamp("create_time");
  147. Date updateTime = resultSet.getTimestamp("update_time");
  148. UserInfoEntity userInfoEntity = new UserInfoEntity(userId, userName, userPwd, createTime, updateTime);
  149. list.add(userInfoEntity);
  150. }
  151. resultSet.close();
  152. statement.close();
  153. connection.close();
  154. return list;
  155. }
  156. public int selectCount() throws ClassNotFoundException, SQLException {
  157. int count = 0;
  158. Connection connection = DBUtils.openConn();
  159. String sql = "SELECT COUNT(*) AS userCount FROM user_info where status = 1";
  160. PreparedStatement statement = connection.prepareStatement(sql);
  161. ResultSet resultSet = statement.executeQuery();
  162. while (resultSet.next()) {
  163. count = resultSet.getInt("userCount");
  164. }
  165. resultSet.close();
  166. statement.close();
  167. connection.close();
  168. return count;
  169. }
  170. @Override
  171. public boolean batchDeleteById(int[] ids) throws ClassNotFoundException, SQLException {
  172. boolean flag = false;
  173. // 获取连接
  174. Connection connection = DBUtils.openConn();
  175. // sql语句
  176. // String sql = "delete from user_info where user_id = ?";
  177. String sql = "update user_info set status = 0 where user_id = ?";
  178. // 预处理对象
  179. PreparedStatement statement = connection.prepareStatement(sql);
  180. // 添加参数
  181. for (int id : ids) {
  182. statement.setInt(1, id);
  183. statement.addBatch();
  184. }
  185. int[] result = statement.executeBatch();
  186. // 执行预处理对象
  187. // int count = statement.executeUpdate();
  188. if (result.length > 0) {
  189. flag = true;
  190. }
  191. statement.close();
  192. connection.close();
  193. return flag;
  194. }
  195. }

②package com.newcapec.entity;

ItemUserEntity.java

  1. package com.newcapec.entity;
  2. import java.util.Date;
  3. public class ItemUserEntity extends Object {
  4. private int itemUserId;
  5. private int userId;
  6. private int itemId;
  7. private Date createTime;
  8. private Date updateTime;
  9. public ItemUserEntity() {
  10. }
  11. public ItemUserEntity(int itemUserId, int userId, int itemId, Date createTime, Date updateTime) {
  12. super();
  13. this.itemUserId = itemUserId;
  14. this.userId = userId;
  15. this.itemId = itemId;
  16. this.createTime = createTime;
  17. this.updateTime = updateTime;
  18. }
  19. public int getItemUserId() {
  20. return itemUserId;
  21. }
  22. public void setItemUserId(int itemUserId) {
  23. this.itemUserId = itemUserId;
  24. }
  25. public int getUserId() {
  26. return userId;
  27. }
  28. public void setUserId(int userId) {
  29. this.userId = userId;
  30. }
  31. public int getItemId() {
  32. return itemId;
  33. }
  34. public void setItemId(int itemId) {
  35. this.itemId = itemId;
  36. }
  37. public Date getCreateTime() {
  38. return createTime;
  39. }
  40. public void setCreateTime(Date createTime) {
  41. this.createTime = createTime;
  42. }
  43. public Date getUpdateTime() {
  44. return updateTime;
  45. }
  46. public void setUpdateTime(Date updateTime) {
  47. this.updateTime = updateTime;
  48. }
  49. @Override
  50. public String toString() {
  51. return "ItemUserEntity [itemUserId=" + itemUserId + ", userId=" + userId + ", itemId=" + itemId
  52. + ", createTime=" + createTime + ", updateTime=" + updateTime + "]";
  53. }
  54. }

LogsInfoEntity.java

  1. package com.newcapec.entity;
  2. import java.util.Date;
  3. public class LogsInfoEntity extends Object {
  4. private int logsId;
  5. private int userId;
  6. private String logsContent;
  7. private Date createTime;
  8. private Date updateTime;
  9. public LogsInfoEntity() {
  10. }
  11. public LogsInfoEntity(int logsId, int userId, String logsContent, Date createTime, Date updateTime) {
  12. super();
  13. this.logsId = logsId;
  14. this.userId = userId;
  15. this.logsContent = logsContent;
  16. this.createTime = createTime;
  17. this.updateTime = updateTime;
  18. }
  19. public int getLogsId() {
  20. return logsId;
  21. }
  22. public void setLogsId(int logsId) {
  23. this.logsId = logsId;
  24. }
  25. public int getUserId() {
  26. return userId;
  27. }
  28. public void setUserId(int userId) {
  29. this.userId = userId;
  30. }
  31. public String getLogsContent() {
  32. return logsContent;
  33. }
  34. public void setLogsContent(String logsContent) {
  35. this.logsContent = logsContent;
  36. }
  37. public Date getCreateTime() {
  38. return createTime;
  39. }
  40. public void setCreateTime(Date createTime) {
  41. this.createTime = createTime;
  42. }
  43. public Date getUpdateTime() {
  44. return updateTime;
  45. }
  46. public void setUpdateTime(Date updateTime) {
  47. this.updateTime = updateTime;
  48. }
  49. @Override
  50. public String toString() {
  51. return "LogsInfoEntity [logsId=" + logsId + ", userId=" + userId + ", logsContent=" + logsContent
  52. + ", createTime=" + createTime + ", updateTime=" + updateTime + "]";
  53. }
  54. }

NewItemEntity.java

  1. package com.newcapec.entity;
  2. import java.util.Date;
  3. import com.alibaba.fastjson.annotation.JSONField;
  4. public class NewItemEntity extends Object {
  5. private int itemId;
  6. private String itemName;
  7. @JSONField(format = "yyyy-MM-dd HH:mm:ss")
  8. private Date createTime;
  9. @JSONField(format = "yyyy-MM-dd HH:mm:ss")
  10. private Date updateTime;
  11. public NewItemEntity() {
  12. }
  13. public NewItemEntity(int itemId, String itemName) {
  14. super();
  15. this.itemId = itemId;
  16. this.itemName = itemName;
  17. }
  18. public NewItemEntity(int itemId, String itemName, Date createTime, Date updateTime) {
  19. super();
  20. this.itemId = itemId;
  21. this.itemName = itemName;
  22. this.createTime = createTime;
  23. this.updateTime = updateTime;
  24. }
  25. public int getItemId() {
  26. return itemId;
  27. }
  28. public void setItemId(int itemId) {
  29. this.itemId = itemId;
  30. }
  31. public String getItemName() {
  32. return itemName;
  33. }
  34. public void setItemName(String itemName) {
  35. this.itemName = itemName;
  36. }
  37. public Date getCreateTime() {
  38. return createTime;
  39. }
  40. public void setCreateTime(Date createTime) {
  41. this.createTime = createTime;
  42. }
  43. public Date getUpdateTime() {
  44. return updateTime;
  45. }
  46. public void setUpdateTime(Date updateTime) {
  47. this.updateTime = updateTime;
  48. }
  49. @Override
  50. public String toString() {
  51. return "NewItemEntity [itemId=" + itemId + ", itemName=" + itemName + ", createTime=" + createTime
  52. + ", updateTime=" + updateTime + "]";
  53. }
  54. }

NewsInfoEntity.java

  1. package com.newcapec.entity;
  2. import java.util.Date;
  3. public class NewsInfoEntity extends Object {
  4. private int newsId;
  5. private int itemId;
  6. private String newsTitle;
  7. private String newsImage;
  8. private String newsContent;
  9. private Date createTime;
  10. private Date updateTime;
  11. public NewsInfoEntity() {
  12. }
  13. public NewsInfoEntity(int newsId, int itemId, String newsTitle, String newsImage, String newsContent,
  14. Date createTime, Date updateTime) {
  15. super();
  16. this.newsId = newsId;
  17. this.itemId = itemId;
  18. this.newsTitle = newsTitle;
  19. this.newsImage = newsImage;
  20. this.newsContent = newsContent;
  21. this.createTime = createTime;
  22. this.updateTime = updateTime;
  23. }
  24. public int getNewsId() {
  25. return newsId;
  26. }
  27. public void setNewsId(int newsId) {
  28. this.newsId = newsId;
  29. }
  30. public int getItemId() {
  31. return itemId;
  32. }
  33. public void setItemId(int itemId) {
  34. this.itemId = itemId;
  35. }
  36. public String getNewsTitle() {
  37. return newsTitle;
  38. }
  39. public void setNewsTitle(String newsTitle) {
  40. this.newsTitle = newsTitle;
  41. }
  42. public String getNewsImage() {
  43. return newsImage;
  44. }
  45. public void setNewsImage(String newsImage) {
  46. this.newsImage = newsImage;
  47. }
  48. public String getNewsContent() {
  49. return newsContent;
  50. }
  51. public void setNewsContent(String newsContent) {
  52. this.newsContent = newsContent;
  53. }
  54. public Date getCreateTime() {
  55. return createTime;
  56. }
  57. public void setCreateTime(Date createTime) {
  58. this.createTime = createTime;
  59. }
  60. public Date getUpdateTime() {
  61. return updateTime;
  62. }
  63. public void setUpdateTime(Date updateTime) {
  64. this.updateTime = updateTime;
  65. }
  66. @Override
  67. public String toString() {
  68. return "NewsInfoEntity [newsId=" + newsId + ", itemId=" + itemId + ", newsTitle=" + newsTitle + ", newsImage="
  69. + newsImage + ", newsContent=" + newsContent + ", createTime=" + createTime + ", updateTime="
  70. + updateTime + "]";
  71. }
  72. }

ResultData.java

  1. package com.newcapec.entity;
  2. public class ResultData<T> {
  3. private int total;
  4. private T rows;
  5. private String code;
  6. public ResultData() {
  7. super();
  8. }
  9. public ResultData(int total, T rows, String code) {
  10. super();
  11. this.total = total;
  12. this.rows = rows;
  13. this.code = code;
  14. }
  15. public int getTotal() {
  16. return total;
  17. }
  18. public void setTotal(int total) {
  19. this.total = total;
  20. }
  21. public T getRows() {
  22. return rows;
  23. }
  24. public void setRows(T rows) {
  25. this.rows = rows;
  26. }
  27. public String getCode() {
  28. return code;
  29. }
  30. public void setCode(String code) {
  31. this.code = code;
  32. }
  33. @Override
  34. public String toString() {
  35. return "ResultData [total=" + total + ", rows=" + rows + ", code=" + code + "]";
  36. }
  37. }

UserInfoEntity.java

  1. package com.newcapec.entity;
  2. import java.util.Date;
  3. import com.alibaba.fastjson.annotation.JSONField;
  4. public class UserInfoEntity {
  5. private int userId;
  6. private String userName;
  7. private String userPwd;
  8. @JSONField(format = "yyyy-MM-dd HH:mm:ss")
  9. private Date createTime;
  10. @JSONField(format = "yyyy-MM-dd HH:mm:ss")
  11. private Date updateTime;
  12. public UserInfoEntity() {
  13. }
  14. public UserInfoEntity(int userId, String userName, String userPwd) {
  15. super();
  16. this.userId = userId;
  17. this.userName = userName;
  18. this.userPwd = userPwd;
  19. }
  20. public UserInfoEntity(int userId, String userName, String userPwd, Date createTime, Date updateTime) {
  21. super();
  22. this.userId = userId;
  23. this.userName = userName;
  24. this.userPwd = userPwd;
  25. this.createTime = createTime;
  26. this.updateTime = updateTime;
  27. }
  28. public int getUserId() {
  29. return userId;
  30. }
  31. public void setUserId(int userId) {
  32. this.userId = userId;
  33. }
  34. public String getUserName() {
  35. return userName;
  36. }
  37. public void setUserName(String userName) {
  38. this.userName = userName;
  39. }
  40. public String getUserPwd() {
  41. return userPwd;
  42. }
  43. public void setUserPwd(String userPwd) {
  44. this.userPwd = userPwd;
  45. }
  46. public Date getCreateTime() {
  47. return createTime;
  48. }
  49. public void setCreateTime(Date createTime) {
  50. this.createTime = createTime;
  51. }
  52. public Date getUpdateTime() {
  53. return updateTime;
  54. }
  55. public void setUpdateTime(Date updateTime) {
  56. this.updateTime = updateTime;
  57. }
  58. @Override
  59. public String toString() {
  60. return "UserInfoEntity [userId=" + userId + ", userName=" + userName + ", userPwd=" + userPwd + ", createTime="
  61. + createTime + ", updateTime=" + updateTime + "]";
  62. }
  63. }

③package com.newcapec.servlet;

AddUserServlet.java

  1. package com.newcapec.servlet;
  2. import java.io.IOException;
  3. import java.sql.SQLException;
  4. import java.util.HashMap;
  5. import javax.servlet.ServletException;
  6. import javax.servlet.annotation.WebServlet;
  7. import javax.servlet.http.HttpServlet;
  8. import javax.servlet.http.HttpServletRequest;
  9. import javax.servlet.http.HttpServletResponse;
  10. import com.alibaba.fastjson.JSON;
  11. import com.newcapec.dao.UserInfoDao;
  12. import com.newcapec.entity.UserInfoEntity;
  13. /**
  14. * Servlet implementation class AddUserServlet
  15. */
  16. @WebServlet(name = "/AddUserServlet", urlPatterns = "/AddUserServlet")
  17. public class AddUserServlet extends HttpServlet {
  18. private static final long serialVersionUID = 1L;
  19. private UserInfoDao userInfoDao = new UserInfoDao();
  20. /**
  21. * @see HttpServlet#HttpServlet()
  22. */
  23. public AddUserServlet() {
  24. super();
  25. // TODO Auto-generated constructor stub
  26. }
  27. /**
  28. * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
  29. * response)
  30. */
  31. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  32. throws ServletException, IOException {
  33. // TODO Auto-generated method stub
  34. response.getWriter().append("Served at: ").append(request.getContextPath());
  35. }
  36. /**
  37. * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
  38. * response)
  39. */
  40. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  41. throws ServletException, IOException {
  42. request.setCharacterEncoding("utf-8");
  43. response.setContentType("text/json;charset=utf-8");
  44. String userName = request.getParameter("userName");
  45. String userPwd = request.getParameter("userPwd");
  46. UserInfoEntity userInfoEntity = new UserInfoEntity();
  47. userInfoEntity.setUserName(userName);
  48. userInfoEntity.setUserPwd(userPwd);
  49. try {
  50. boolean flag = userInfoDao.insert(userInfoEntity);
  51. HashMap<String, Boolean> result = new HashMap<>();
  52. result.put("flag", flag);
  53. response.getWriter().write(JSON.toJSONString(result));
  54. } catch (ClassNotFoundException | SQLException e) {
  55. // TODO 自动生成的 catch 块
  56. e.printStackTrace();
  57. }
  58. }
  59. }

DeleteUserServlet.java

  1. package com.newcapec.servlet;
  2. import java.io.IOException;
  3. import java.sql.SQLException;
  4. import java.util.Arrays;
  5. import java.util.HashMap;
  6. import javax.servlet.ServletException;
  7. import javax.servlet.annotation.WebServlet;
  8. import javax.servlet.http.HttpServlet;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11. import com.alibaba.fastjson.JSON;
  12. import com.newcapec.dao.UserInfoDao;
  13. /**
  14. * Servlet implementation class DeleteUserServlet
  15. */
  16. @WebServlet(name = "/DeleteUserServlet", urlPatterns = "/DeleteUserServlet")
  17. public class DeleteUserServlet extends HttpServlet {
  18. private static final long serialVersionUID = 1L;
  19. private UserInfoDao userInfoDao = new UserInfoDao();
  20. /**
  21. * @see HttpServlet#HttpServlet()
  22. */
  23. public DeleteUserServlet() {
  24. super();
  25. // TODO Auto-generated constructor stub
  26. }
  27. /**
  28. * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
  29. * response)
  30. */
  31. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  32. throws ServletException, IOException {
  33. // TODO Auto-generated method stub
  34. response.getWriter().append("Served at: ").append(request.getContextPath());
  35. }
  36. /**
  37. * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
  38. * response)
  39. */
  40. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  41. throws ServletException, IOException {
  42. // 此处可以使用过滤器批量处理
  43. request.setCharacterEncoding("utf-8");
  44. response.setContentType("text/json;charset=utf-8");
  45. String[] userIds = request.getParameterValues("userIds[]");
  46. // 使用userInfoDao执行批量删除
  47. int[] ids = new int[userIds.length];
  48. for (int i = 0; i < userIds.length; i++) {
  49. ids[i] = Integer.valueOf(userIds[i]);
  50. }
  51. try {
  52. boolean flag = userInfoDao.batchDeleteById(ids);
  53. HashMap<String, Boolean> result = new HashMap<>();
  54. result.put("flag", flag);
  55. response.getWriter().write(JSON.toJSONString(result));
  56. } catch (ClassNotFoundException | SQLException e) {
  57. // TODO 自动生成的 catch 块
  58. e.printStackTrace();
  59. }
  60. }
  61. }

LoginServlet.java

  1. package com.newcapec.servlet;
  2. import java.io.IOException;
  3. import java.sql.SQLException;
  4. import javax.servlet.ServletException;
  5. import javax.servlet.annotation.WebServlet;
  6. import javax.servlet.http.HttpServlet;
  7. import javax.servlet.http.HttpServletRequest;
  8. import javax.servlet.http.HttpServletResponse;
  9. import com.newcapec.dao.UserInfoDao;
  10. import com.newcapec.entity.UserInfoEntity;
  11. /**
  12. * Servlet implementation class LoginServlet
  13. */
  14. @WebServlet(name = "/LoginServlet", urlPatterns = "/LoginServlet")
  15. public class LoginServlet extends HttpServlet {
  16. private UserInfoDao userInfoDao = new UserInfoDao();
  17. private static final long serialVersionUID = 1L;
  18. /**
  19. * @see HttpServlet#HttpServlet()
  20. */
  21. public LoginServlet() {
  22. super();
  23. // TODO Auto-generated constructor stub
  24. }
  25. /**
  26. * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
  27. * response)
  28. */
  29. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  30. throws ServletException, IOException {
  31. // TODO Auto-generated method stub
  32. response.getWriter().append("Served at: ").append(request.getContextPath());
  33. }
  34. /**
  35. * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
  36. * response)
  37. */
  38. // 注意:在正规开发中 登录密码需要加密
  39. // 需要有验证码
  40. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  41. throws ServletException, IOException {
  42. request.setCharacterEncoding("UTF-8");
  43. String userName = request.getParameter("userName");
  44. String userPwd = request.getParameter("userPwd");
  45. try {
  46. UserInfoEntity userInfoEntity = userInfoDao.login(userName, userPwd);
  47. if (userInfoEntity != null) {
  48. // 登录成功
  49. request.getSession().setAttribute("userInfo", userInfoEntity);
  50. response.sendRedirect("index.html");
  51. } else {
  52. // 登录失败 重定向
  53. response.sendRedirect("loginFailure.html");
  54. }
  55. } catch (ClassNotFoundException | SQLException e) {
  56. // TODO 自动生成的 catch 块
  57. e.printStackTrace();
  58. }
  59. }
  60. }

SelectUserByIdServlet.java

  1. package com.newcapec.servlet;
  2. import java.io.IOException;
  3. import java.sql.SQLException;
  4. import javax.servlet.ServletException;
  5. import javax.servlet.annotation.WebServlet;
  6. import javax.servlet.http.HttpServlet;
  7. import javax.servlet.http.HttpServletRequest;
  8. import javax.servlet.http.HttpServletResponse;
  9. import com.alibaba.fastjson.JSON;
  10. import com.newcapec.dao.UserInfoDao;
  11. import com.newcapec.entity.UserInfoEntity;
  12. /**
  13. * Servlet implementation class SelectUserByIdServlet
  14. */
  15. @WebServlet(name = "/SelectUserByIdServlet", urlPatterns = "/SelectUserByIdServlet")
  16. public class SelectUserByIdServlet extends HttpServlet {
  17. private static final long serialVersionUID = 1L;
  18. private UserInfoDao userInfoDao = new UserInfoDao();
  19. /**
  20. * @see HttpServlet#HttpServlet()
  21. */
  22. public SelectUserByIdServlet() {
  23. super();
  24. // TODO Auto-generated constructor stub
  25. }
  26. /**
  27. * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
  28. * response)
  29. */
  30. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  31. throws ServletException, IOException {
  32. // 此处可以使用过滤器批量处理
  33. request.setCharacterEncoding("utf-8");
  34. response.setContentType("text/json;charset=utf-8");
  35. int userId = Integer.parseInt(request.getParameter("userId"));
  36. try {
  37. UserInfoEntity userInfoEntity = userInfoDao.selectById(userId);
  38. response.getWriter().write(JSON.toJSONString(userInfoEntity));
  39. } catch (ClassNotFoundException | SQLException e) {
  40. // TODO 自动生成的 catch 块
  41. e.printStackTrace();
  42. }
  43. }
  44. /**
  45. * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
  46. * response)
  47. */
  48. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  49. throws ServletException, IOException {
  50. // TODO Auto-generated method stub
  51. doGet(request, response);
  52. }
  53. }

SelectUserByPageServlet.java

  1. package com.newcapec.servlet;
  2. import java.io.IOException;
  3. import java.sql.SQLException;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import javax.servlet.ServletException;
  7. import javax.servlet.annotation.WebServlet;
  8. import javax.servlet.http.HttpServlet;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11. import com.alibaba.fastjson.JSON;
  12. import com.newcapec.dao.UserInfoDao;
  13. import com.newcapec.entity.ResultData;
  14. import com.newcapec.entity.UserInfoEntity;
  15. /**
  16. * Servlet implementation class SelectAllServlet
  17. */
  18. @WebServlet(name = "/SelectAllServlet", urlPatterns = "/SelectAllServlet")
  19. public class SelectUserByPageServlet extends HttpServlet {
  20. private static final long serialVersionUID = 1L;
  21. private UserInfoDao userInfoDao = new UserInfoDao();
  22. /**
  23. * @see HttpServlet#HttpServlet()
  24. */
  25. public SelectUserByPageServlet() {
  26. super();
  27. // TODO Auto-generated constructor stub
  28. }
  29. /**
  30. * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
  31. * response)
  32. */
  33. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  34. throws ServletException, IOException {
  35. response.setCharacterEncoding("utf-8");
  36. response.setContentType("text/json;charset=utf-8");
  37. // 当前页码
  38. // 页大小
  39. int offset = Integer.parseInt(request.getParameter("offset"));
  40. int limit = Integer.parseInt(request.getParameter("limit"));
  41. // bootstrap-table插件需要后台传回total/rows
  42. ResultData<List<UserInfoEntity>> data = new ResultData<>();
  43. try {
  44. data.setRows(userInfoDao.selectByPage(offset, limit));
  45. data.setTotal(userInfoDao.selectCount());
  46. response.getWriter().write(JSON.toJSONString(data));
  47. } catch (ClassNotFoundException | SQLException e1) {
  48. // TODO 自动生成的 catch 块
  49. e1.printStackTrace();
  50. }
  51. }
  52. /**
  53. * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
  54. * response)
  55. */
  56. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  57. throws ServletException, IOException {
  58. // TODO Auto-generated method stub
  59. doGet(request, response);
  60. }
  61. }

UpdateUserServlet.java

  1. package com.newcapec.servlet;
  2. import java.io.IOException;
  3. import java.sql.SQLException;
  4. import java.util.HashMap;
  5. import javax.servlet.ServletException;
  6. import javax.servlet.annotation.WebServlet;
  7. import javax.servlet.http.HttpServlet;
  8. import javax.servlet.http.HttpServletRequest;
  9. import javax.servlet.http.HttpServletResponse;
  10. import com.alibaba.fastjson.JSON;
  11. import com.newcapec.dao.UserInfoDao;
  12. import com.newcapec.entity.UserInfoEntity;
  13. /**
  14. * Servlet implementation class UpdateUserServlet
  15. */
  16. @WebServlet(name = "/UpdateUserServlet", urlPatterns = "/UpdateUserServlet")
  17. public class UpdateUserServlet extends HttpServlet {
  18. private static final long serialVersionUID = 1L;
  19. private UserInfoDao userInfoDao = new UserInfoDao();
  20. /**
  21. * @see HttpServlet#HttpServlet()
  22. */
  23. public UpdateUserServlet() {
  24. super();
  25. // TODO Auto-generated constructor stub
  26. }
  27. /**
  28. * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
  29. * response)
  30. */
  31. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  32. throws ServletException, IOException {
  33. // TODO Auto-generated method stub
  34. response.getWriter().append("Served at: ").append(request.getContextPath());
  35. }
  36. /**
  37. * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
  38. * response)
  39. */
  40. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  41. throws ServletException, IOException {
  42. // 此处可以使用过滤器批量处理
  43. request.setCharacterEncoding("utf-8");
  44. response.setContentType("text/json;charset=utf-8");
  45. int userId = Integer.parseInt(request.getParameter("userId"));
  46. String userName = request.getParameter("userName");
  47. String userPwd = request.getParameter("userPwd");
  48. UserInfoEntity entity = new UserInfoEntity(userId, userName, userPwd);
  49. try {
  50. boolean flag = userInfoDao.update(entity);
  51. HashMap<String, Boolean> result = new HashMap<>();
  52. result.put("flag", flag);
  53. response.getWriter().write(JSON.toJSONString(result));
  54. } catch (ClassNotFoundException | SQLException e) {
  55. // TODO 自动生成的 catch 块
  56. e.printStackTrace();
  57. }
  58. }
  59. }

④​​​​​​​package com.newcapec.servlet.newitem;

AddItemServlet.java

  1. package com.newcapec.servlet.newitem;
  2. import java.io.IOException;
  3. import java.sql.SQLException;
  4. import java.util.HashMap;
  5. import javax.servlet.ServletException;
  6. import javax.servlet.annotation.WebServlet;
  7. import javax.servlet.http.HttpServlet;
  8. import javax.servlet.http.HttpServletRequest;
  9. import javax.servlet.http.HttpServletResponse;
  10. import com.alibaba.fastjson.JSON;
  11. import com.newcapec.dao.ItemUserDao;
  12. import com.newcapec.dao.NewItemDao;
  13. import com.newcapec.entity.ItemUserEntity;
  14. import com.newcapec.entity.NewItemEntity;
  15. import com.newcapec.entity.UserInfoEntity;
  16. /**
  17. * Servlet implementation class AddUserServlet
  18. */
  19. @WebServlet(name = "/AddItemServlet", urlPatterns = "/AddItemServlet")
  20. public class AddItemServlet extends HttpServlet {
  21. private static final long serialVersionUID = 1L;
  22. private NewItemDao newItemDao = new NewItemDao();
  23. private ItemUserDao itemUserDao = new ItemUserDao();
  24. /**
  25. * @see HttpServlet#HttpServlet()
  26. */
  27. public AddItemServlet() {
  28. super();
  29. // TODO Auto-generated constructor stub
  30. }
  31. /**
  32. * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
  33. * response)
  34. */
  35. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  36. throws ServletException, IOException {
  37. // TODO Auto-generated method stub
  38. response.getWriter().append("Served at: ").append(request.getContextPath());
  39. }
  40. /**
  41. * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
  42. * response)
  43. */
  44. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  45. throws ServletException, IOException {
  46. request.setCharacterEncoding("utf-8");
  47. response.setContentType("text/json;charset=utf-8");
  48. String ItemName = request.getParameter("itemName");
  49. NewItemEntity newItemEntity = new NewItemEntity();
  50. newItemEntity.setItemName(ItemName);
  51. ItemUserEntity itemUserEntity = new ItemUserEntity();
  52. // itemUserEntity.setItemId(itemId);
  53. try {
  54. int itemId = newItemDao.insert(newItemEntity);
  55. itemUserEntity.setItemId(itemId);
  56. UserInfoEntity userInfoEntity = (UserInfoEntity) request.getSession().getAttribute("userInfo");
  57. itemUserEntity.setUserId(userInfoEntity.getUserId());
  58. boolean flag = itemUserDao.insert(itemUserEntity);
  59. HashMap<String, Boolean> result = new HashMap<>();
  60. result.put("flag", flag);
  61. response.getWriter().write(JSON.toJSONString(result));
  62. } catch (ClassNotFoundException | SQLException e) {
  63. // TODO 自动生成的 catch 块
  64. e.printStackTrace();
  65. }
  66. }
  67. }

DeleteItemServlet.java

  1. package com.newcapec.servlet.newitem;
  2. import java.io.IOException;
  3. import java.sql.SQLException;
  4. import java.util.HashMap;
  5. import javax.servlet.ServletException;
  6. import javax.servlet.annotation.WebServlet;
  7. import javax.servlet.http.HttpServlet;
  8. import javax.servlet.http.HttpServletRequest;
  9. import javax.servlet.http.HttpServletResponse;
  10. import com.alibaba.fastjson.JSON;
  11. import com.newcapec.dao.NewItemDao;
  12. /**
  13. * Servlet implementation class DeleteItemServlet
  14. */
  15. @WebServlet(name = "/DeleteItemServlet", urlPatterns = "/DeleteItemServlet")
  16. public class DeleteItemServlet extends HttpServlet {
  17. private static final long serialVersionUID = 1L;
  18. private NewItemDao newItemDao = new NewItemDao();
  19. /**
  20. * @see HttpServlet#HttpServlet()
  21. */
  22. public DeleteItemServlet() {
  23. super();
  24. // TODO Auto-generated constructor stub
  25. }
  26. /**
  27. * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
  28. * response)
  29. */
  30. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  31. throws ServletException, IOException {
  32. // TODO Auto-generated method stub
  33. response.getWriter().append("Served at: ").append(request.getContextPath());
  34. }
  35. /**
  36. * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
  37. * response)
  38. */
  39. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  40. throws ServletException, IOException {
  41. // 此处可以使用过滤器批量处理
  42. request.setCharacterEncoding("utf-8");
  43. response.setContentType("text/json;charset=utf-8");
  44. String[] itemIds = request.getParameterValues("itemIds[]");
  45. // 使用newItemDao执行批量删除
  46. int[] ids = new int[itemIds.length];
  47. for (int i = 0; i < itemIds.length; i++) {
  48. ids[i] = Integer.valueOf(itemIds[i]);
  49. }
  50. try {
  51. boolean flag = newItemDao.batchDeleteById(ids);
  52. HashMap<String, Boolean> result = new HashMap<>();
  53. result.put("flag", flag);
  54. response.getWriter().write(JSON.toJSONString(result));
  55. } catch (ClassNotFoundException | SQLException e) {
  56. // TODO 自动生成的 catch 块
  57. e.printStackTrace();
  58. }
  59. }
  60. }

SelectItemByIdServlet.java

  1. package com.newcapec.servlet.newitem;
  2. import java.io.IOException;
  3. import java.sql.SQLException;
  4. import javax.servlet.ServletException;
  5. import javax.servlet.annotation.WebServlet;
  6. import javax.servlet.http.HttpServlet;
  7. import javax.servlet.http.HttpServletRequest;
  8. import javax.servlet.http.HttpServletResponse;
  9. import com.alibaba.fastjson.JSON;
  10. import com.newcapec.dao.NewItemDao;
  11. import com.newcapec.entity.NewItemEntity;
  12. /**
  13. * Servlet implementation class SelectUserByIdServlet
  14. */
  15. @WebServlet(name = "/SelectItemByIdServlet", urlPatterns = "/SelectItemByIdServlet")
  16. public class SelectItemByIdServlet extends HttpServlet {
  17. private static final long serialVersionUID = 1L;
  18. private NewItemDao newItemDao = new NewItemDao();
  19. /**
  20. * @see HttpServlet#HttpServlet()
  21. */
  22. public SelectItemByIdServlet() {
  23. super();
  24. // TODO Auto-generated constructor stub
  25. }
  26. /**
  27. * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
  28. * response)
  29. */
  30. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  31. throws ServletException, IOException {
  32. // 此处可以使用过滤器批量处理
  33. request.setCharacterEncoding("utf-8");
  34. response.setContentType("text/json;charset=utf-8");
  35. int itemId = Integer.parseInt(request.getParameter("itemId"));
  36. try {
  37. NewItemEntity newItemEntity = newItemDao.selectById(itemId);
  38. response.getWriter().write(JSON.toJSONString(newItemEntity));
  39. } catch (ClassNotFoundException | SQLException e) {
  40. // TODO 自动生成的 catch 块
  41. e.printStackTrace();
  42. }
  43. }
  44. /**
  45. * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
  46. * response)
  47. */
  48. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  49. throws ServletException, IOException {
  50. // TODO Auto-generated method stub
  51. doGet(request, response);
  52. }
  53. }

SelectItembyUserServlet.java

  1. package com.newcapec.servlet.newitem;
  2. import java.io.IOException;
  3. import java.sql.SQLException;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import javax.servlet.ServletException;
  7. import javax.servlet.annotation.WebServlet;
  8. import javax.servlet.http.HttpServlet;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11. import com.alibaba.fastjson.JSON;
  12. import com.newcapec.dao.NewItemDao;
  13. import com.newcapec.entity.NewItemEntity;
  14. import com.newcapec.entity.UserInfoEntity;
  15. /**
  16. * Servlet implementation class SelectItembyUserServlet
  17. */
  18. @WebServlet(name = "/SelectItembyUserServlet", urlPatterns = "/SelectItembyUserServlet")
  19. public class SelectItembyUserServlet extends HttpServlet { // 获取item数据表中的数据
  20. private static final long serialVersionUID = 1L;
  21. private NewItemDao newItemDao = new NewItemDao();
  22. /**
  23. * @see HttpServlet#HttpServlet()
  24. */
  25. public SelectItembyUserServlet() {
  26. super();
  27. // TODO Auto-generated constructor stub
  28. }
  29. /**
  30. * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
  31. * response)
  32. */
  33. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  34. throws ServletException, IOException {
  35. request.setCharacterEncoding("utf-8");
  36. response.setContentType("text/json;charset=utf-8");
  37. // 通过userId获取
  38. UserInfoEntity userInfoEntity = (UserInfoEntity) request.getSession().getAttribute("userInfo");
  39. try {
  40. List<NewItemEntity> rows = newItemDao.selectAllByUserId(userInfoEntity.getUserId());
  41. int total = newItemDao.selectAllByUserIdCount(userInfoEntity.getUserId());
  42. HashMap<String, Object> result = new HashMap<>();
  43. result.put("rows", rows);
  44. result.put("total", total);
  45. response.getWriter().write(JSON.toJSONString(result));
  46. } catch (ClassNotFoundException | SQLException e) {
  47. // TODO 自动生成的 catch 块
  48. e.printStackTrace();
  49. }
  50. }
  51. /**
  52. * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
  53. * response)
  54. */
  55. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  56. throws ServletException, IOException {
  57. // TODO Auto-generated method stub
  58. doGet(request, response);
  59. }
  60. }

UpdateItemServlet.java

  1. package com.newcapec.servlet.newitem;
  2. import java.io.IOException;
  3. import java.sql.SQLException;
  4. import java.util.HashMap;
  5. import javax.servlet.ServletException;
  6. import javax.servlet.annotation.WebServlet;
  7. import javax.servlet.http.HttpServlet;
  8. import javax.servlet.http.HttpServletRequest;
  9. import javax.servlet.http.HttpServletResponse;
  10. import com.alibaba.fastjson.JSON;
  11. import com.newcapec.dao.NewItemDao;
  12. import com.newcapec.entity.NewItemEntity;
  13. /**
  14. * Servlet implementation class UpdateUserServlet
  15. */
  16. @WebServlet(name = "/UpdateItemServlet", urlPatterns = "/UpdateItemServlet")
  17. public class UpdateItemServlet extends HttpServlet {
  18. private static final long serialVersionUID = 1L;
  19. private NewItemDao newItemDao = new NewItemDao();
  20. /**
  21. * @see HttpServlet#HttpServlet()
  22. */
  23. public UpdateItemServlet() {
  24. super();
  25. // TODO Auto-generated constructor stub
  26. }
  27. /**
  28. * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
  29. * response)
  30. */
  31. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  32. throws ServletException, IOException {
  33. // TODO Auto-generated method stub
  34. response.getWriter().append("Served at: ").append(request.getContextPath());
  35. }
  36. /**
  37. * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
  38. * response)
  39. */
  40. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  41. throws ServletException, IOException {
  42. // 此处可以使用过滤器批量处理
  43. request.setCharacterEncoding("utf-8");
  44. response.setContentType("text/json;charset=utf-8");
  45. int itemId = Integer.parseInt(request.getParameter("itemId"));
  46. String itemName = request.getParameter("itemName");
  47. NewItemEntity entity = new NewItemEntity(itemId, itemName);
  48. try {
  49. boolean flag = newItemDao.update(entity);
  50. HashMap<String, Boolean> result = new HashMap<>();
  51. result.put("flag", flag);
  52. response.getWriter().write(JSON.toJSONString(result));
  53. } catch (ClassNotFoundException | SQLException e) {
  54. // TODO 自动生成的 catch 块
  55. e.printStackTrace();
  56. }
  57. }
  58. }

⑤package com.newcapec.servlet.news;

AddNewsServlet.java

  1. package com.newcapec.servlet.news;
  2. import java.io.IOException;
  3. import java.sql.SQLException;
  4. import java.util.HashMap;
  5. import javax.servlet.ServletException;
  6. import javax.servlet.annotation.WebServlet;
  7. import javax.servlet.http.HttpServlet;
  8. import javax.servlet.http.HttpServletRequest;
  9. import javax.servlet.http.HttpServletResponse;
  10. import com.alibaba.fastjson.JSON;
  11. import com.newcapec.dao.NewsInfoDao;
  12. import com.newcapec.entity.NewsInfoEntity;
  13. /**
  14. * Servlet implementation class AddNewsServlet
  15. */
  16. @WebServlet(name = "/AddNewsServlet", urlPatterns = "/AddNewsServlet")
  17. public class AddNewsServlet extends HttpServlet {
  18. private static final long serialVersionUID = 1L;
  19. private NewsInfoDao newsInfoDao = new NewsInfoDao();
  20. /**
  21. * @see HttpServlet#HttpServlet()
  22. */
  23. public AddNewsServlet() {
  24. super();
  25. // TODO Auto-generated constructor stub
  26. }
  27. /**
  28. * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
  29. * response)
  30. */
  31. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  32. throws ServletException, IOException {
  33. // TODO Auto-generated method stub
  34. response.getWriter().append("Served at: ").append(request.getContextPath());
  35. }
  36. /**
  37. * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
  38. * response)
  39. */
  40. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  41. throws ServletException, IOException {
  42. // TODO Auto-generated method stub
  43. // doGet(request, response);
  44. request.setCharacterEncoding("utf-8");
  45. response.setContentType("text/json;charset=utf-8");
  46. String addNewsTitle = request.getParameter("addNewsTitle");
  47. String addNewsItem = request.getParameter("addNewsItem"); // 栏目id
  48. String addNewsContent = request.getParameter("addNewsContent");
  49. NewsInfoEntity newsInfoEntity = new NewsInfoEntity();
  50. newsInfoEntity.setNewsTitle(addNewsTitle);
  51. newsInfoEntity.setItemId(Integer.parseInt(addNewsItem));
  52. newsInfoEntity.setNewsContent(addNewsContent);
  53. try {
  54. boolean flag = newsInfoDao.insert(newsInfoEntity);
  55. HashMap<String, Boolean> result = new HashMap<>();
  56. result.put("flag", flag);
  57. response.getWriter().write(JSON.toJSONString(result));
  58. } catch (ClassNotFoundException | SQLException e) {
  59. // TODO 自动生成的 catch 块
  60. e.printStackTrace();
  61. }
  62. }
  63. }

⑥package com.newcapec.test;

TestItemUserDao.java

  1. package com.newcapec.test;
  2. import java.sql.SQLException;
  3. import java.util.List;
  4. import org.junit.Assert;
  5. import org.junit.Test;
  6. import com.newcapec.dao.ItemUserDao;
  7. import com.newcapec.entity.ItemUserEntity;
  8. public class TestItemUserDao {
  9. private ItemUserDao ItemUserDao = new ItemUserDao();
  10. @Test
  11. public void testInsert() throws ClassNotFoundException, SQLException {
  12. ItemUserEntity itemUserEntity = new ItemUserEntity();
  13. itemUserEntity.setUserId(1);
  14. itemUserEntity.setItemId(1);
  15. Assert.assertTrue(ItemUserDao.insert(itemUserEntity));
  16. }
  17. @Test
  18. public void testDeleteById() throws ClassNotFoundException, SQLException {
  19. Assert.assertTrue(ItemUserDao.deleteById(1));
  20. }
  21. @Test
  22. public void testUpdate() throws ClassNotFoundException, SQLException {
  23. ItemUserEntity entity = ItemUserDao.selectById(2);
  24. entity.setItemId(2);
  25. Assert.assertTrue(ItemUserDao.update(entity));
  26. }
  27. @Test
  28. public void testSelectAll() throws ClassNotFoundException, SQLException {
  29. System.out.println(ItemUserDao.selectAll());
  30. }
  31. }

TestLogsInfoDao.java

  1. package com.newcapec.test;
  2. import java.sql.SQLException;
  3. import java.util.List;
  4. import org.junit.Assert;
  5. import org.junit.Test;
  6. import com.newcapec.dao.LogsInfoDao;
  7. import com.newcapec.entity.LogsInfoEntity;
  8. public class TestLogsInfoDao {
  9. private LogsInfoDao logsInfoDao = new LogsInfoDao();
  10. @Test
  11. public void testInsert() throws ClassNotFoundException, SQLException {
  12. LogsInfoEntity logsInfoEntity = new LogsInfoEntity();
  13. logsInfoEntity.setUserId(1);
  14. logsInfoEntity.setLogsContent("woshishenren");
  15. // userInfoDao.insert(userInfoEntity);
  16. Assert.assertTrue(logsInfoDao.insert(logsInfoEntity));
  17. }
  18. @Test
  19. public void testSelect() throws ClassNotFoundException, SQLException {
  20. List<LogsInfoEntity> list = logsInfoDao.selectAll();
  21. System.out.println(list);
  22. }
  23. @Test
  24. public void testDeleteById() throws ClassNotFoundException, SQLException {
  25. Assert.assertTrue(logsInfoDao.deleteById(2));
  26. }
  27. @Test
  28. public void testUpdate() throws ClassNotFoundException, SQLException {
  29. LogsInfoEntity logsInfoEntity = logsInfoDao.selectById(2);
  30. logsInfoEntity.setUserId(1);
  31. logsInfoDao.update(logsInfoEntity);
  32. }
  33. @Test
  34. public void testselectById() throws ClassNotFoundException, SQLException {
  35. System.out.println(logsInfoDao.selectById(1));
  36. }
  37. }

TestNewItemDao.java

  1. package com.newcapec.test;
  2. import java.sql.SQLException;
  3. import java.util.List;
  4. import org.junit.Assert;
  5. import org.junit.Test;
  6. import com.newcapec.dao.NewItemDao;
  7. import com.newcapec.entity.NewItemEntity;
  8. public class TestNewItemDao {
  9. private NewItemDao newItemDao = new NewItemDao();
  10. @Test
  11. public void testInsert() throws ClassNotFoundException, SQLException {
  12. NewItemEntity newItemEntity = new NewItemEntity();
  13. newItemEntity.setItemId(1);
  14. newItemEntity.setItemName("插入测试");
  15. // Assert.assertTrue(newItemDao.insert(newItemEntity));
  16. }
  17. @Test
  18. public void testDeleteById() throws ClassNotFoundException, SQLException {
  19. Assert.assertTrue(newItemDao.deleteById(14));
  20. }
  21. @Test
  22. public void testUpdate() throws ClassNotFoundException, SQLException {
  23. NewItemEntity entity = newItemDao.selectById(1);
  24. entity.setItemName("更新item测试");
  25. Assert.assertTrue(newItemDao.update(entity));
  26. }
  27. @Test
  28. public void testSelectAll() throws ClassNotFoundException, SQLException {
  29. System.out.println(newItemDao.selectAll());
  30. }
  31. }

NewsInfoDao.java

  1. package com.newcapec.test;
  2. import java.sql.SQLException;
  3. import org.junit.Assert;
  4. import org.junit.Test;
  5. import com.newcapec.dao.NewsInfoDao;
  6. import com.newcapec.entity.NewsInfoEntity;
  7. public class TestNewsInfoDao {
  8. private NewsInfoDao newsInfoDao = new NewsInfoDao();
  9. @Test
  10. public void testInsert() throws ClassNotFoundException, SQLException {
  11. NewsInfoEntity newsInfoEntity = new NewsInfoEntity();
  12. newsInfoEntity.setItemId(1);
  13. newsInfoEntity.setNewsTitle("新能源召回大户特斯拉的“美式”傲慢|观潮");
  14. newsInfoEntity.setNewsImage(
  15. "http://pics1.baidu.com/feed/71cf3bc79f3df8dcecfa18268a75ee8c46102829.jpeg?token=32875797d2ded1ed2a9334df610bccf7");
  16. newsInfoEntity.setNewsContent("新浪科技 花子健\r\n" + "从“硬件升级”到“召回”,理想汽车只用了5天。\r\n"
  17. + "而不久前的威马汽车召回事件,前后耗时23天,威马汽车将之定义为“史上最快召回”。如果仅仅是简单对比,理想汽车无疑刷新了历史记录。\r\n"
  18. + "对于新造车势力来说,受限于工艺和新技术,召回是大概率事件。目前除了小鹏未有实际的召回经历之外,蔚来汽车、威马汽车以及理想汽车,包括外来者特斯拉,都遇到过召回。只不过,中国新造车势力和特斯拉表现出来的态度截然不同。\r\n"
  19. + "“惶恐”的造车新势力\r\n" + "11月1日,理想汽车在媒体沟通会上宣布了针对前悬架下摆臂球销和底盘的“免费升级”,其中前悬架下摆臂球销受力太低与理想ONE多次出现断轴事件有关系。\r\n"
  20. + "但理想汽车的措辞遭到质疑。一方面是理想汽车CEO李想公开承认“升级肯定是因为产品有缺陷,我们是在行驶当中发生碰撞断掉的几率高于平均值。”而另外一方面,则是在一开始否认“召回”,以“免费升级”代替。\r\n"
  21. + "理想汽车销售服务副总裁刘杰强调,升级和那种由于车辆本身在行驶过程中出现故障和质量问题的召回,是不一样的。11月6日,理想汽车最终宣布召回10469辆理想ONE,占已交付车辆的将近50%。\r\n"
  22. + "官方披露的信息显示,截至2020年10月31日,理想ONE累计发生了97起前悬架碰撞事故,其中前悬架下摆臂球头从球销脱出的情况超过10起,造成了理想汽车在碰撞之后断轴的严重事故。");
  23. Assert.assertTrue(newsInfoDao.insert(newsInfoEntity));
  24. }
  25. @Test
  26. public void testDeleteById() throws ClassNotFoundException, SQLException {
  27. Assert.assertTrue(newsInfoDao.deleteById(1));
  28. }
  29. @Test
  30. public void testUpdate() throws ClassNotFoundException, SQLException {
  31. NewsInfoEntity entity = newsInfoDao.selectById(2);
  32. entity.setNewsTitle("图书馆维修,暂停开放一天");
  33. Assert.assertTrue(newsInfoDao.update(entity));
  34. }
  35. @Test
  36. public void testSelectAll() throws ClassNotFoundException, SQLException {
  37. System.out.println(newsInfoDao.selectAll());
  38. }
  39. }

TestUserInfoDao.java

  1. package com.newcapec.test;
  2. import java.sql.SQLException;
  3. import java.util.List;
  4. import org.junit.Assert;
  5. import org.junit.Test;
  6. import com.newcapec.dao.UserInfoDao;
  7. import com.newcapec.entity.UserInfoEntity;
  8. public class TestUserInfoDao {
  9. private UserInfoDao userInfoDao = new UserInfoDao();
  10. @Test
  11. public void testInsert() throws ClassNotFoundException, SQLException {
  12. /*
  13. * UserInfoEntity userInfoEntity = new UserInfoEntity();
  14. * userInfoEntity.setUserName("田七"); userInfoEntity.setUserPwd("123456");
  15. * //userInfoDao.insert(userInfoEntity);
  16. * Assert.assertTrue(userInfoDao.insert(userInfoEntity));
  17. */
  18. for (int i = 1; i <= 100; i++) {
  19. UserInfoEntity userInfoEntity = new UserInfoEntity();
  20. userInfoEntity.setUserName("userName" + i);
  21. userInfoEntity.setUserPwd("123456");
  22. // userInfoDao.insert(userInfoEntity);
  23. Assert.assertTrue(userInfoDao.insert(userInfoEntity));
  24. }
  25. }
  26. @Test
  27. public void testSelect() throws ClassNotFoundException, SQLException {
  28. List<UserInfoEntity> list = userInfoDao.selectAll();
  29. System.out.println(list);
  30. }
  31. @Test
  32. public void testDeleteById() throws ClassNotFoundException, SQLException {
  33. Assert.assertTrue(userInfoDao.deleteById(7));
  34. }
  35. @Test
  36. public void testUpdate() throws ClassNotFoundException, SQLException {
  37. UserInfoEntity userInfoEntity = userInfoDao.selectById(1);
  38. userInfoEntity.setUserName("zhangsan");
  39. userInfoDao.update(userInfoEntity);
  40. }
  41. @Test
  42. public void testselectById() throws ClassNotFoundException, SQLException {
  43. System.out.println(userInfoDao.selectById(1));
  44. }
  45. }

⑦package com.newcapec.utils;

DBUtils.java

  1. package com.newcapec.utils;
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.SQLException;
  5. import com.mysql.jdbc.Driver;
  6. /**
  7. * 获取与数据库的连接 此处后期需要使用阿里巴巴的druid数据库连接池优化
  8. *
  9. * @author user
  10. *
  11. */
  12. public class DBUtils {
  13. public static Connection openConn() throws ClassNotFoundException, SQLException {
  14. // 连接数据库四要素
  15. // url username password driver
  16. String user = "root";
  17. String password = "root";
  18. // String driver = "com.mysql.jdbc.Driver";
  19. // String url = "jdbc:mysql://127.0.0.1:3306/zykkk?characterEncoding=UTF-8";
  20. String driver = "com.mysql.cj.jdbc.Driver";
  21. String url = "jdbc:mysql://localhost:3306/zykkk?characterEncoding=utf-8&serverTimezone=UTC";// (UTC表示标准时区)
  22. // 注册数据库驱动
  23. Class.forName(driver);
  24. return DriverManager.getConnection(url, user, password);
  25. }
  26. }

MD5Utils.java

  1. package com.newcapec.utils;
  2. import java.security.MessageDigest;
  3. public class MD5Utils {
  4. /***
  5. * MD5加码 生成32位md5码
  6. */
  7. public static String stringMD5(String inStr) {
  8. MessageDigest md5 = null;
  9. try {
  10. md5 = MessageDigest.getInstance("MD5");
  11. } catch (Exception e) {
  12. System.out.println(e.toString());
  13. e.printStackTrace();
  14. return "";
  15. }
  16. char[] charArray = inStr.toCharArray();
  17. byte[] byteArray = new byte[charArray.length];
  18. for (int i = 0; i < charArray.length; i++)
  19. byteArray[i] = (byte) charArray[i];
  20. byte[] md5Bytes = md5.digest(byteArray);
  21. StringBuffer hexValue = new StringBuffer();
  22. for (int i = 0; i < md5Bytes.length; i++) {
  23. int val = ((int) md5Bytes[i]) & 0xff;
  24. if (val < 16)
  25. hexValue.append("0");
  26. hexValue.append(Integer.toHexString(val));
  27. }
  28. return hexValue.toString();
  29. }
  30. /**
  31. * 加密解密算法 执行一次加密,两次解密
  32. */
  33. public static String convertMD5(String inStr) {
  34. char[] a = inStr.toCharArray();
  35. for (int i = 0; i < a.length; i++) {
  36. a[i] = (char) (a[i] ^ 't');
  37. }
  38. String s = new String(a);
  39. return s;
  40. }
  41. // 测试主函数
  42. public static void main(String args[]) {
  43. String s = new String("1233");
  44. System.out.println("原始:" + s);
  45. System.out.println("MD5后:" + stringMD5(s));
  46. System.out.println("加密的:" + convertMD5(s));
  47. System.out.println("解密的:" + convertMD5(convertMD5(s)));
  48. }
  49. }

pages

item_manager.html

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <!-- 新 Bootstrap4 核心 CSS 文件 -->
  6. <link rel="stylesheet" href="../bootstrap4/css/bootstrap.min.css">
  7. <link rel="stylesheet" type="text/css" href="../font-awesome-4.7.0/css/font-awesome.min.css" />
  8. <link href="../bootstrap-table/bootstrap-table.min.css" rel="stylesheet" />
  9. <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
  10. <script src="../jquery/jquery.min.js"></script>
  11. <!-- bootstrap.bundle.min.js 用于弹窗、提示、下拉菜单,包含了 popper.min.js -->
  12. <script src="../js/popper.min.js"></script>
  13. <!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
  14. <script src="../bootstrap4/js/bootstrap.min.js"></script>
  15. <script src="../bootstrap-table/bootstrap-table.js"></script>
  16. <script src="../bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>
  17. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  18. <title>栏目管理</title>
  19. <script type="text/javascript">
  20. function batchDelete() {
  21. var rows = $('#newItemTab').bootstrapTable('getSelections');
  22. console.log(rows);
  23. var itemIds = new Array();
  24. for (var i = 0; i < rows.length; i++) {
  25. itemIds.push(rows[i].itemId);
  26. }
  27. console.log(itemIds);
  28. $.ajax({
  29. type: "POST",
  30. url: "../DeleteItemServlet",
  31. data: { "itemIds": itemIds },
  32. success: function (msg) {
  33. if (msg.flag) {
  34. alert("batchDelete()成功");
  35. //刷新数据
  36. $('#newItemTab').bootstrapTable("refresh");
  37. } else {
  38. alert("失败");
  39. }
  40. }
  41. });
  42. }
  43. function addNewItem() {
  44. var itemName = $("#addItemName").val();
  45. var itemdata = {
  46. "itemName": itemName
  47. };
  48. $.ajax({
  49. type: "POST",
  50. url: "../AddItemServlet",
  51. data: itemdata,
  52. success: function (msg) {
  53. if (msg.flag) {
  54. alert("addNewItem()成功");
  55. //刷新数据
  56. $('#newItemTab').bootstrapTable("refresh");
  57. } else {
  58. alert("失败");
  59. }
  60. $("#addItemName").val("");
  61. }
  62. });
  63. }
  64. function edit(itemId) { // 编辑用户信息
  65. console.log(itemId);
  66. //通过该ID获取数据
  67. //通过ajax发起请求获取用户信息
  68. $.ajax({
  69. type: "get",
  70. url: "../SelectItemByIdServlet",
  71. data: { "itemId": itemId },
  72. success: function (msg) {
  73. console.log(msg);
  74. //获取成功后填入参数展示模态框
  75. $("input[name='itemId']").val(msg.itemId);
  76. $("input[name='itemName']").val(msg.itemName);
  77. $("#updateNewItem").modal('show');
  78. }
  79. });
  80. //执行更新
  81. }
  82. function updateNewItem() { // 刷新页面信息
  83. var newItem = {
  84. "itemId": $("input[name='itemId']").val(),
  85. "itemName": $("input[name='itemName']").val()
  86. };
  87. $.ajax({
  88. type: "post",
  89. url: "../UpdateItemServlet",
  90. data: newItem,
  91. success: function (msg) {
  92. if (msg.flag) {
  93. alert("updateNewItem()成功");
  94. //刷新数据
  95. $('#newItemTab').bootstrapTable("refresh");
  96. } else {
  97. alert("失败");
  98. }
  99. $("input[name='itemId']").val("");
  100. $("input[name='itemName']").val("");
  101. }
  102. });
  103. }
  104. </script>
  105. </head>
  106. <body>
  107. <div style="padding: 10px">
  108. <div id="toolbar" style="display: flex;">
  109. <button type="button" class="btn btn-info" data-toggle="modal" data-target="#addNewItem"><i
  110. class="fa fa-plus"></i> 添加</button>
  111. <button type="button" class="btn btn-danger" onclick="batchDelete()"><i class="fa fa-minus"></i>
  112. 批量删除</button>
  113. <!-- <input type="text" placeholder="请输入栏目名" id="itemName" value="新闻处"/><button class="btn btn-info" onclick='search()'><i class="fa fa-search"></i></button> -->
  114. </div>
  115. <table id="newItemTab" class="table table-hover table-bordered table-striped">
  116. </table>
  117. <div class="modal fade" id="updateNewItem">
  118. <div class="modal-dialog">
  119. <div class="modal-content">
  120. <!-- 模态框头部 -->
  121. <div class="modal-header bg-info">
  122. <h4 class="modal-title">更新栏目信息</h4>
  123. <button type="button" class="close" data-dismiss="modal">×</button>
  124. </div>
  125. <!-- 模态框主体 -->
  126. <div class="modal-body">
  127. <form>
  128. <input type="hidden" name="itemId" />
  129. <div class="input-group mb-3">
  130. <div class="input-group-prepend">
  131. <span class="input-group-text"><i class="fa fa-user"></i></span>
  132. </div>
  133. <input type="text" name="itemName" class="form-control" placeholder="Itemname">
  134. </div>
  135. </form>
  136. </div>
  137. <!-- 模态框底部 -->
  138. <div class="modal-footer">
  139. <button type="button" class="btn btn-success" data-dismiss="modal"
  140. onclick=updateNewItem()>更新</button>
  141. <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
  142. </div>
  143. </div>
  144. </div>
  145. </div>
  146. <!-- 模态框 -->
  147. <div class="modal fade" id="addNewItem">
  148. <div class="modal-dialog">
  149. <div class="modal-content">
  150. <!-- 模态框头部 -->
  151. <div class="modal-header bg-info">
  152. <h4 class="modal-title">添加栏目信息</h4>
  153. <button type="button" class="close" data-dismiss="modal">×</button>
  154. </div>
  155. <!-- 模态框主体 -->
  156. <div class="modal-body">
  157. <form>
  158. <div class="input-group mb-3">
  159. <div class="input-group-prepend">
  160. <span class="input-group-text"><i class="fa fa-user"></i></span>
  161. </div>
  162. <input type="text" id="addItemName" class="form-control" placeholder="Itemname">
  163. </div>
  164. </form>
  165. </div>
  166. <!-- 模态框底部 -->
  167. <div class="modal-footer">
  168. <button type="button" class="btn btn-success" data-dismiss="modal"
  169. onclick=addNewItem()>添加!</button>
  170. <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
  171. </div>
  172. </div>
  173. </div>
  174. </div>
  175. </div>
  176. <script>
  177. var icons = {
  178. paginationSwitchDown: 'fa-caret-square-down',
  179. paginationSwitchUp: 'fa-caret-square-up',
  180. refresh: 'fa-refresh',
  181. toggleOff: 'fa-toggle-off',
  182. toggleOn: 'fa-toggle-on',
  183. columns: 'fa-th-list',
  184. fullscreen: 'fa-arrows-alt',
  185. detailOpen: 'fa-plus',
  186. detailClose: 'fa-minus'
  187. };
  188. //异步加载表格数据
  189. $('#newItemTab').bootstrapTable({
  190. url: '../SelectItembyUserServlet', //请求后台的URL(*)
  191. method: 'get', //请求方式(*)
  192. toolbar: '#toolbar', //工具按钮用哪个容器
  193. striped: true, //是否显示行间隔色
  194. cache: false, //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)
  195. pagination: true, //是否显示分页(*)
  196. icons: icons, //重新定义图标 修复图标加载失败问题
  197. queryParams: function (params) {
  198. var temp = { //这里的键的名字和控制器的变量名必须一直,这边改动,控制器也需要改成一样的
  199. limit: params.limit, //页面大小
  200. offset: params.offset //页码
  201. //itemName: $("#itemName").val()
  202. //statu: $("#txt_search_statu").val()
  203. };
  204. return temp;
  205. },
  206. sidePagination: "server", //分页方式:client客户端分页,server服务端分页(*)
  207. pageNumber: 1, //初始化加载第一页,默认第一页
  208. pageSize: 10, //每页的记录行数(*)
  209. pageList: [10, 15, 20, 25], //可供选择的每页的行数(*)
  210. //search: true, //是否显示表格搜索,此搜索是客户端搜索,不会进服务端,所以,个人感觉意义不大
  211. strictSearch: true,
  212. showRefresh: true, //是否显示刷新按钮
  213. clickToSelect: true, //是否启用点击选中行
  214. uniqueId: "itemId", //每一行的唯一标识,一般为主键列
  215. //showToggle:true, //是否显示详细视图和列表视图的切换按钮
  216. //cardView: false, //是否显示详细视图
  217. columns: [{
  218. checkbox: true
  219. }, {
  220. field: 'itemId',
  221. title: '栏目Id'
  222. }, {
  223. field: 'itemName',
  224. title: '栏目名称'
  225. }, {
  226. field: 'createTime',
  227. title: '创建时间'
  228. }, {
  229. field: 'updateTime',
  230. title: '更新时间'
  231. }, {
  232. field: 'itemId',
  233. title: '编辑',
  234. formatter: function (value, row, index) {
  235. var e = '<a class="btn btn-waring" href="#" mce_href="#" title="编辑" onclick="edit(\''
  236. + row.itemId
  237. + '\')"><i class="fa fa-edit"></i>编辑</a> ';
  238. return e;
  239. }
  240. }]
  241. });
  242. </script>
  243. </body>
  244. </html>

news_manager.html

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>新闻管理</title>
  6. <!-- 新 Bootstrap4 核心 CSS 文件 -->
  7. <link rel="stylesheet" href="../bootstrap4/css/bootstrap.min.css">
  8. <link rel="stylesheet" type="text/css" href="../font-awesome-4.7.0/css/font-awesome.min.css" />
  9. <link href="../bootstrap-table/bootstrap-table.min.css" rel="stylesheet" />
  10. <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
  11. <script src="../jquery/jquery.min.js"></script>
  12. <!-- bootstrap.bundle.min.js 用于弹窗、提示、下拉菜单,包含了 popper.min.js -->
  13. <script src="../js/popper.min.js"></script>
  14. <!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
  15. <script src="../bootstrap4/js/bootstrap.min.js"></script>
  16. <script src="../bootstrap-table/bootstrap-table.js"></script>
  17. <script src="../bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>
  18. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  19. <style type="text/css">
  20. body {
  21. display: flex;
  22. flex-direction: column;
  23. min-height: 100vh;
  24. }
  25. #header {
  26. display: flex;
  27. align-items: center;
  28. justify-content: space-between;
  29. font-size: 20px;
  30. margin: 15px;
  31. }
  32. #header>a {
  33. color: #007FB0;
  34. }
  35. #bodychild1>a {
  36. color: #007FB0;
  37. }
  38. #header>#header1 {
  39. display: flex;
  40. flex-direction: row;
  41. }
  42. #header1>#header2 {
  43. display: flex;
  44. flex-direction: row;
  45. }
  46. #body {
  47. display: flex;
  48. flex-direction: column;
  49. border: 1px solid darkgrey;
  50. margin: 15px;
  51. }
  52. #body1 {
  53. height: 50px;
  54. display: flex;
  55. flex-grow: 1;
  56. align-items: center;
  57. padding: 20px;
  58. background-color: #cecece;
  59. border-bottom: 1px solid darkgrey;
  60. }
  61. #body2 {
  62. height: 500px;
  63. display: flex;
  64. flex-direction: column;
  65. margin: 20px;
  66. }
  67. #body3 {
  68. height: 50px;
  69. display: flex;
  70. flex-direction: row;
  71. margin: 10px;
  72. }
  73. #body4 {
  74. height: 40px;
  75. width: 80px;
  76. display: flex;
  77. justify-content: center;
  78. align-items: center;
  79. border: 1px solid darkgrey;
  80. }
  81. </style>
  82. <script type="text/javascript">
  83. $(function () {
  84. $.ajax({
  85. url: "../SelectItembyUserServlet",
  86. method: "get",
  87. success: function (data) {
  88. for (var i = 0; i < data.rows.length; i++) {
  89. //var $option = $("<option value="+data.rows[i].itetmId+">"+data.rows[i].itemName+"</option");
  90. $("#addNewsItem").append("<option value=" + data.rows[i].itemId + ">" + data.rows[i].itemName + "</option");
  91. }
  92. }
  93. });
  94. });
  95. function addNewItem() {
  96. var addNewsTitle = $("#addNewsTitle").val();
  97. var addNewsItem = $("#addNewsItem").val();
  98. var addNewsContent = $("#addNewsContent").val();
  99. console.log(addNewsTitle);
  100. console.log(addNewsItem);
  101. console.log(addNewsContent);
  102. var newsdata = {
  103. "addNewsTitle": addNewsTitle,
  104. "addNewsItem": addNewsItem,
  105. "addNewsContent": addNewsContent
  106. };
  107. console.log(newsdata);
  108. //return;
  109. $.ajax({
  110. type: "POST",
  111. url: "../AddNewsServlet",
  112. data: newsdata,
  113. success: function (msg) {
  114. if (msg.flag) {
  115. alert("成功插入新闻,芜湖~");
  116. //刷新数据 $('#newItemTab').bootstrapTable("refresh");
  117. } else {
  118. alert("插入新闻失败~");
  119. }
  120. //$("#addItemName").val("");
  121. }
  122. });
  123. }
  124. </script>
  125. </head>
  126. <body>
  127. <div id="header">
  128. <a>新闻管理</a>
  129. <div id="header1">
  130. <div class="dropdown">
  131. <button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown"
  132. style="background-color: white; color: #cbcbcb;">
  133. 教务处
  134. </button>
  135. <div class="dropdown-menu">
  136. <a class="dropdown-item" href="#">学生会</a>
  137. <a class="dropdown-item" href="#">党支部</a>
  138. <a class="dropdown-item" href="#">分团委</a>
  139. </div>
  140. <!-- <select>
  141. <option value="volvo">Volvo</option>
  142. <option value="saab">Saab</option>
  143. <option value="opel">Opel</option>
  144. <option value="audi">Audi</option>
  145. </select> -->
  146. </div>
  147. <div id="header2"><input type="text" class="form-control" placeholder="用户名">
  148. <span class="input-group-text"><a href="#"><i class="fa-circle-thin"></i></a></span>
  149. </div>
  150. </div>
  151. </div>
  152. <!-- header yes -->
  153. <div id="body">
  154. <div id="body1">
  155. <a>发布新闻</a>
  156. </div>
  157. <div id="body2">
  158. <div id="body3">
  159. <div id="body4"><a>标题</a> </div>
  160. <div><input id="addNewsTitle" type="text" placeholder="新闻标题" style="height: 40px;width: 300px;"></div>
  161. </div>
  162. <div id="body3">
  163. <div id="body4"><a>栏目</a> </div>
  164. <!-- <div class="dropdown" style="width: 300px">
  165. <button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" style="background-color: white; color: #b8b8b8;width: 150px;height: 40px">
  166. 教务处
  167. </button>
  168. <div class="dropdown-menu">
  169. <a class="dropdown-item" href="#">学生会</a>
  170. <a class="dropdown-item" href="#">党支部</a>
  171. <a class="dropdown-item" href="#">分团委</a>
  172. <a class="dropdown-item" href="#">院团委</a>
  173. </div>
  174. </div> -->
  175. <select id="addNewsItem" class="form-control" style="height: 40px;width: 300px;">
  176. </select>
  177. </div>
  178. <div style="margin: 10px;">
  179. <textarea id="addNewsContent" rows="10" cols="100" placeholder="新闻内容"></textarea>
  180. </div>
  181. <div style="margin: 10px;"><button type="button" class="btn btn-primary" style="width: 80px;"
  182. onClick="addNewItem()">发布</button></div>
  183. </div>
  184. </body>
  185. </html>

user_manager.html

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <!-- 新 Bootstrap4 核心 CSS 文件 -->
  6. <link rel="stylesheet" href="../bootstrap4/css/bootstrap.min.css">
  7. <link rel="stylesheet" type="text/css" href="../font-awesome-4.7.0/css/font-awesome.min.css" />
  8. <link href="../bootstrap-table/bootstrap-table.min.css" rel="stylesheet" />
  9. <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
  10. <script src="../jquery/jquery.min.js"></script>
  11. <!-- bootstrap.bundle.min.js 用于弹窗、提示、下拉菜单,包含了 popper.min.js -->
  12. <script src="../js/popper.min.js"></script>
  13. <!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
  14. <script src="../bootstrap4/js/bootstrap.min.js"></script>
  15. <script src="../bootstrap-table/bootstrap-table.js"></script>
  16. <script src="../bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>
  17. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  18. <title>用户管理</title>
  19. <script type="text/javascript">
  20. function batchDelete() {
  21. var rows = $('#userInfoTab').bootstrapTable('getSelections');
  22. console.log(rows);
  23. var userIds = new Array();
  24. for (var i = 0; i < rows.length; i++) {
  25. userIds.push(rows[i].userId);
  26. }
  27. console.log(userIds);
  28. $.ajax({
  29. type: "POST",
  30. url: "../DeleteUserServlet",
  31. data: { "userIds": userIds },
  32. success: function (msg) {
  33. if (msg.flag) {
  34. alert("成功");
  35. //刷新数据
  36. $('#userInfoTab').bootstrapTable("refresh");
  37. } else {
  38. alert("失败");
  39. }
  40. }
  41. });
  42. }
  43. function addUserInfo() {
  44. var userName = $("#addUserName").val();
  45. var userPwd = $("#addUserPwd").val();
  46. var userdata = {
  47. "userName": userName,
  48. "userPwd": userPwd
  49. };
  50. $.ajax({
  51. type: "POST",
  52. url: "../AddUserServlet",
  53. data: userdata,
  54. success: function (msg) {
  55. if (msg.flag) {
  56. alert("成功");
  57. //刷新数据
  58. $('#userInfoTab').bootstrapTable("refresh");
  59. } else {
  60. alert("失败");
  61. }
  62. $("#addUserName").val("");
  63. $("#addUserPwd").val("");
  64. }
  65. });
  66. }
  67. function edit(userId) {
  68. console.log(userId);
  69. //通过该ID获取数据
  70. //通过ajax发起请求获取用户信息
  71. $.ajax({
  72. type: "get",
  73. url: "../SelectUserByIdServlet",
  74. data: { "userId": userId },
  75. success: function (msg) {
  76. console.log(msg);
  77. //获取成功后填入参数展示模态框
  78. $("input[name='userId']").val(msg.userId);
  79. $("input[name='userName']").val(msg.userName);
  80. $("input[name='userPwd']").val(msg.userPwd);
  81. $("#updateUserInfo").modal('show');
  82. }
  83. });
  84. //执行更新
  85. }
  86. function updateUserInfo() {
  87. var userInfo = {
  88. "userId": $("input[name='userId']").val(),
  89. "userName": $("input[name='userName']").val(),
  90. "userPwd": $("input[name='userPwd']").val()
  91. };
  92. $.ajax({
  93. type: "post",
  94. url: "../UpdateUserServlet",
  95. data: userInfo,
  96. success: function (msg) {
  97. if (msg.flag) {
  98. alert("成功");
  99. //刷新数据
  100. $('#userInfoTab').bootstrapTable("refresh");
  101. } else {
  102. alert("失败");
  103. }
  104. $("input[name='userId']").val("");
  105. $("input[name='userName']").val("");
  106. $("input[name='userPwd']").val("");
  107. }
  108. });
  109. }
  110. </script>
  111. </head>
  112. <body>
  113. <div style="padding: 10px">
  114. <div id="toolbar" style="display: flex;">
  115. <button type="button" class="btn btn-info" data-toggle="modal" data-target="#addUserInfo"><i
  116. class="fa fa-plus"></i> 添加</button>
  117. <button type="button" class="btn btn-danger" onclick="batchDelete()"><i class="fa fa-minus"></i>
  118. 批量删除</button>
  119. <!-- <input type="text" placeholder="请输入用户名" id="userName" value="zhangsan"/><button class="btn btn-info" onclick='search()'><i class="fa fa-search"></i></button> -->
  120. </div>
  121. <table id="userInfoTab" class="table table-hover table-bordered table-striped">
  122. </table>
  123. <div class="modal fade" id="updateUserInfo">
  124. <div class="modal-dialog">
  125. <div class="modal-content">
  126. <!-- 模态框头部 -->
  127. <div class="modal-header bg-info">
  128. <h4 class="modal-title">更新用户信息</h4>
  129. <button type="button" class="close" data-dismiss="modal">×</button>
  130. </div>
  131. <!-- 模态框主体 -->
  132. <div class="modal-body">
  133. <form>
  134. <input type="hidden" name="userId" />
  135. <div class="input-group mb-3">
  136. <div class="input-group-prepend">
  137. <span class="input-group-text"><i class="fa fa-user"></i></span>
  138. </div>
  139. <input type="text" name="userName" class="form-control" placeholder="Username">
  140. </div>
  141. <div class="input-group mb-3">
  142. <div class="input-group-prepend">
  143. <span class="input-group-text"><i class="fa fa-lock"></i></span>
  144. </div>
  145. <input type="password" name="userPwd" class="form-control" placeholder="userpwd">
  146. </div>
  147. </form>
  148. </div>
  149. <!-- 模态框底部 -->
  150. <div class="modal-footer">
  151. <button type="button" class="btn btn-success" data-dismiss="modal"
  152. onclick=updateUserInfo()>更新</button>
  153. <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
  154. </div>
  155. </div>
  156. </div>
  157. </div>
  158. <!-- 模态框 -->
  159. <div class="modal fade" id="addUserInfo">
  160. <div class="modal-dialog">
  161. <div class="modal-content">
  162. <!-- 模态框头部 -->
  163. <div class="modal-header bg-info">
  164. <h4 class="modal-title">添加用户信息</h4>
  165. <button type="button" class="close" data-dismiss="modal">×</button>
  166. </div>
  167. <!-- 模态框主体 -->
  168. <div class="modal-body">
  169. <form>
  170. <div class="input-group mb-3">
  171. <div class="input-group-prepend">
  172. <span class="input-group-text"><i class="fa fa-user"></i></span>
  173. </div>
  174. <input type="text" id="addUserName" class="form-control" placeholder="Username">
  175. </div>
  176. <div class="input-group mb-3">
  177. <div class="input-group-prepend">
  178. <span class="input-group-text"><i class="fa fa-lock"></i></span>
  179. </div>
  180. <input type="password" id="addUserPwd" class="form-control" placeholder="userpwd">
  181. </div>
  182. </form>
  183. </div>
  184. <!-- 模态框底部 -->
  185. <div class="modal-footer">
  186. <button type="button" class="btn btn-success" data-dismiss="modal"
  187. onclick=addUserInfo()>添加</button>
  188. <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
  189. </div>
  190. </div>
  191. </div>
  192. </div>
  193. </div>
  194. <script>
  195. var icons = {
  196. paginationSwitchDown: 'fa-caret-square-down',
  197. paginationSwitchUp: 'fa-caret-square-up',
  198. refresh: 'fa-refresh',
  199. toggleOff: 'fa-toggle-off',
  200. toggleOn: 'fa-toggle-on',
  201. columns: 'fa-th-list',
  202. fullscreen: 'fa-arrows-alt',
  203. detailOpen: 'fa-plus',
  204. detailClose: 'fa-minus'
  205. };
  206. //异步加载表格数据
  207. $('#userInfoTab').bootstrapTable({
  208. url: '../SelectAllServlet', //请求后台的URL(*)
  209. method: 'get', //请求方式(*)
  210. toolbar: '#toolbar', //工具按钮用哪个容器
  211. striped: true, //是否显示行间隔色
  212. cache: false, //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)
  213. pagination: true, //是否显示分页(*)
  214. icons: icons, //重新定义图标 修复图标加载失败问题
  215. queryParams: function (params) {
  216. var temp = { //这里的键的名字和控制器的变量名必须一直,这边改动,控制器也需要改成一样的
  217. limit: params.limit, //页面大小
  218. offset: params.offset //页码
  219. //userName: $("#userName").val()
  220. //statu: $("#txt_search_statu").val()
  221. };
  222. return temp;
  223. },
  224. sidePagination: "server", //分页方式:client客户端分页,server服务端分页(*)
  225. pageNumber: 1, //初始化加载第一页,默认第一页
  226. pageSize: 10, //每页的记录行数(*)
  227. pageList: [10, 15, 20, 25], //可供选择的每页的行数(*)
  228. //search: true, //是否显示表格搜索,此搜索是客户端搜索,不会进服务端,所以,个人感觉意义不大
  229. strictSearch: true,
  230. showRefresh: true, //是否显示刷新按钮
  231. clickToSelect: true, //是否启用点击选中行
  232. uniqueId: "userId", //每一行的唯一标识,一般为主键列
  233. //showToggle:true, //是否显示详细视图和列表视图的切换按钮
  234. //cardView: false, //是否显示详细视图
  235. columns: [{
  236. checkbox: true
  237. }, {
  238. field: 'userId',
  239. title: '用户Id'
  240. }, {
  241. field: 'userName',
  242. title: '用户名'
  243. }, {
  244. field: 'createTime',
  245. title: '创建时间'
  246. }, {
  247. field: 'updateTime',
  248. title: '更新时间'
  249. }, {
  250. field: 'userId',
  251. title: '编辑',
  252. formatter: function (value, row, index) {
  253. var e = '<a class="btn btn-waring" href="#" mce_href="#" title="编辑" onclick="edit(\''
  254. + row.userId
  255. + '\')"><i class="fa fa-edit"></i>编辑</a> ';
  256. return e;
  257. }
  258. }]
  259. });
  260. </script>
  261. </body>
  262. </html>

index.html

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title></title>
  6. <!-- 新 Bootstrap4 核心 CSS 文件 -->
  7. <link rel="stylesheet" href="bootstrap4/css/bootstrap.min.css">
  8. <link rel="stylesheet" type="text/css" href="font-awesome-4.7.0/css/font-awesome.min.css" />
  9. <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
  10. <script src="jquery/jquery.min.js"></script>
  11. <!-- bootstrap.bundle.min.js 用于弹窗、提示、下拉菜单,包含了 popper.min.js -->
  12. <script src="js/popper.min.js"></script>
  13. <!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
  14. <script src="bootstrap4/js/bootstrap.min.js"></script>
  15. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  16. <title>主页</title>
  17. <style type="text/css">
  18. body {
  19. display: flex;
  20. flex-direction: column;
  21. min-height: 100vh;
  22. }
  23. header {
  24. height: 80px;
  25. background-color: #007FB0;
  26. display: flex;
  27. align-items: center;
  28. padding-left: 40px;
  29. }
  30. #main {
  31. flex-grow: 1;
  32. display: flex;
  33. }
  34. #left {
  35. background-color: #EEEEEE;
  36. /* border: 1px #004085 solid; */
  37. }
  38. #left {
  39. width: 200px;
  40. flex-shrink: 0;
  41. display: flex;
  42. flex-direction: column;
  43. }
  44. #left>p {
  45. height: 40px;
  46. padding: 0px;
  47. margin: 0px;
  48. display: flex;
  49. justify-content: center;
  50. align-items: center;
  51. background-color: #F5F5F5;
  52. border-bottom: 1px solid darkgrey;
  53. }
  54. #left>a {
  55. height: 50px;
  56. background-color: #EEEEEE;
  57. border-bottom: 1px darkgrey solid;
  58. border-right: 1px darkgrey solid;
  59. display: flex;
  60. justify-content: center;
  61. align-items: center;
  62. text-decoration: none;
  63. color: #007FB0;
  64. }
  65. #left>a:hover {
  66. background-color: white;
  67. }
  68. #left>a:nth-child(2) {
  69. background-image: url(img/icon_01.png);
  70. background-repeat: no-repeat;
  71. background-position: 40px 18px;
  72. }
  73. #left>a:nth-child(3) {
  74. background-image: url(img/icon_02.png);
  75. background-repeat: no-repeat;
  76. background-position: 40px 18px;
  77. }
  78. #left>a:nth-child(4) {
  79. background-image: url(img/icon_03.png);
  80. background-repeat: no-repeat;
  81. background-position: 40px 18px;
  82. }
  83. #content {
  84. flex-grow: 1;
  85. }
  86. </style>
  87. </head>
  88. <body>
  89. <header>
  90. <img src="img/tit.png" />
  91. </header>
  92. <div id="main">
  93. <div id="left">
  94. <p>当前用户:管理员“lwx”</p>
  95. <a href="pages/user_manager.html" target="myFrame">账户管理</a>
  96. <a href="pages/item_manager.html" target="myFrame">栏目管理</a>
  97. <a href="pages/news_manager.html" target="myFrame">新闻管理</a>
  98. </div>
  99. <iframe id="content" frameborder="0" name="myFrame" src="pages/user_manager.html"></iframe>
  100. </div>
  101. </body>
  102. </html>

login.html

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title></title>
  6. <!-- 新 Bootstrap4 核心 CSS 文件 -->
  7. <link rel="stylesheet" href="bootstrap4/css/bootstrap.min.css">
  8. <link rel="stylesheet" type="text/css" href="font-awesome-4.7.0/css/font-awesome.min.css" />
  9. <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
  10. <script src="jquery/jquery.min.js"></script>
  11. <!-- bootstrap.bundle.min.js 用于弹窗、提示、下拉菜单,包含了 popper.min.js -->
  12. <script src="js/popper.min.js"></script>
  13. <!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
  14. <script src="bootstrap4/js/bootstrap.min.js"></script>
  15. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  16. <style type="text/css">
  17. header,
  18. footer {
  19. height: 100px;
  20. /* background-color: #005CBF; */
  21. }
  22. body {
  23. display: flex;
  24. flex-direction: column;
  25. min-height: 100vh;
  26. }
  27. #main {
  28. flex-grow: 1;
  29. background-image: url(img/banner.jpg);
  30. background-repeat: no-repeat;
  31. background-size: cover;
  32. display: flex;
  33. align-items: center;
  34. justify-content: flex-end;
  35. }
  36. #login {
  37. height: 400px;
  38. width: 400px;
  39. background-color: white;
  40. margin-right: 100px;
  41. border-radius: 10px;
  42. }
  43. </style>
  44. <title>login</title>
  45. </head>
  46. <body>
  47. <header></header>
  48. <div id="main">
  49. <div id="login">
  50. <form style="padding: 20px;" action="LoginServlet" method="post">
  51. <div class="input-group mb-3">
  52. <div class="input-group-prepend">
  53. <span class="input-group-text"><i class="fa fa-user"></i></span>
  54. </div>
  55. <input type="text" name="userName" class="form-control" placeholder="请输入用户名">
  56. </div>
  57. <div class="input-group mb-3">
  58. <div class="input-group-prepend">
  59. <span class="input-group-text"><i class="fa fa-lock"></i></span>
  60. </div>
  61. <input type="text" name="userPwd" class="form-control" placeholder="Username">
  62. </div>
  63. <button type="submit" class="btn btn-info form-control">登录</button>
  64. </form>
  65. </div>
  66. </div>
  67. <footer></footer>
  68. </body>
  69. </html>

loginFailure.html

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Insert title here</title>
  6. </head>
  7. <body>
  8. 登录失败,请重新<a href="login.html">登录</a>
  9. </body>
  10. </html>

phone.html

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title></title>
  6. <!-- 新 Bootstrap4 核心 CSS 文件 -->
  7. <link rel="stylesheet" href="bootstrap4/css/bootstrap.min.css">
  8. <link rel="stylesheet" type="text/css" href="font-awesome-4.7.0/css/font-awesome.min.css" />
  9. <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
  10. <script src="jquery/jquery.min.js"></script>
  11. <!-- bootstrap.bundle.min.js 用于弹窗、提示、下拉菜单,包含了 popper.min.js -->
  12. <script src="js/popper.min.js"></script>
  13. <!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
  14. <script src="bootstrap4/js/bootstrap.min.js"></script>
  15. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  16. <title>主页</title>
  17. <style type="text/css">
  18. body {
  19. margin: 0px;
  20. }
  21. header {
  22. height: 54px;
  23. background-color: #F8F8F8;
  24. display: flex;
  25. justify-content: space-between;
  26. padding: 0px 10px;
  27. align-items: center; /*垂直居中*/
  28. }
  29. #back, #close-page {
  30. color: #FFC74F;
  31. }
  32. nav {
  33. height: 45px;
  34. border-bottom: 1px solid #FFC74F;
  35. display: flex;
  36. }
  37. nav>a {
  38. text-decoration: none;
  39. flex-grow: 1; /*flex-grow属性定义项目的放大比例,默认为0,即如果存在剩余空间,也不放大。*/
  40. border-right: 1px #FFC74F solid;
  41. background-color: antiquewhite;
  42. display: flex;
  43. justify-content: center;
  44. align-items: center;
  45. color: brown;
  46. }
  47. .col-7 {
  48. display: flex;
  49. flex-direction: column;
  50. justify-content: space-between;
  51. }
  52. .row {
  53. margin-bottom: 5px;
  54. background-color: rgb(250, 235, 215, 0.5);
  55. }
  56. </style>
  57. </head>
  58. <body>
  59. <header>
  60. <span id="back"><i class="fa fa-chevron-left"></i> 返回</span>
  61. <span>校内新闻</span>
  62. <span id="close-page"><a href="login.html">登录</a></span>
  63. </header>
  64. <nav>
  65. <a href="#">教务处</a>
  66. <a href="#">委员会</a>
  67. <a href="#">管理会</a>
  68. </nav>
  69. <div class="container-fluid">
  70. <div class="row">
  71. <div class="col-5">
  72. <img src="img/1.jpg" class="img-fluid" />
  73. </div>
  74. <div class="col-7">
  75. <h5>我是一条莫得感情的信息。</h5>
  76. <span>2020-11-19 09:15</span>
  77. </div>
  78. </div>
  79. <div class="row">
  80. <div class="col-5">
  81. <img src="img/2.jpg" class="img-fluid" />
  82. </div>
  83. <div class="col-7">
  84. <h5>新闻手机登录端展示。</h5>
  85. <span>2020-11-19 09:15</span>
  86. </div>
  87. </div>
  88. <div class="row">
  89. <div class="col-5">
  90. <img src="img/3.jpg" class="img-fluid" />
  91. </div>
  92. <div class="col-7">
  93. <h5>冲呀~</h5>
  94. <span>2020-11-19 09:15</span>
  95. </div>
  96. </div>
  97. <div class="row">
  98. <div class="col-5">
  99. <img src="img/dragon.gif" class="img-fluid" />
  100. </div>
  101. <div class="col-7">
  102. <h5>奥里给~</h5>
  103. <span>2020-11-19 09:15</span>
  104. </div>
  105. </div>
  106. <div class="row">
  107. <div class="col-5">
  108. <img src="img/1.jpg" class="img-fluid" />
  109. </div>
  110. <div class="col-7">
  111. <h5>我是一条莫得感情的信息。</h5>
  112. <span>2020-11-19 09:15</span>
  113. </div>
  114. </div>
  115. <div class="row">
  116. <div class="col-5">
  117. <img src="img/2.jpg" class="img-fluid" />
  118. </div>
  119. <div class="col-7">
  120. <h5>新闻手机登录端展示。</h5>
  121. <span>2020-11-19 09:15</span>
  122. </div>
  123. </div>
  124. <div class="row">
  125. <div class="col-5">
  126. <img src="img/3.jpg" class="img-fluid" />
  127. </div>
  128. <div class="col-7">
  129. <h5>冲呀~</h5>
  130. <span>2020-11-19 09:15</span>
  131. </div>
  132. </div>
  133. <div class="row">
  134. <div class="col-5">
  135. <img src="img/dragon.gif" class="img-fluid" />
  136. </div>
  137. <div class="col-7">
  138. <h5>奥里给~</h5>
  139. <span>2020-11-19 09:15</span>
  140. </div>
  141. </div>
  142. <div class="row">
  143. <div class="col-5">
  144. <img src="img/dog.jpg" class="img-fluid" />
  145. </div>
  146. <div class="col-7">
  147. <h5>加油~</h5>
  148. <span>2020-11-19 09:15</span>
  149. </div>
  150. </div>
  151. </div>
  152. </body>
  153. </html>

2021年1月30日 下午 附上代码。

发表评论

表情:
评论列表 (有 0 条评论,153人围观)

还没有评论,来说两句吧...

相关阅读