Merge remote-tracking branch 'origin/master'
# Conflicts: # src/com/hellogithub/dao/UserDao.java
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
Target Server Version : 80031 (8.0.31)
|
||||
File Encoding : 65001
|
||||
|
||||
Date: 02/07/2023 22:50:04
|
||||
Date: 03/07/2023 11:28:18
|
||||
*/
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
@@ -99,16 +99,18 @@ CREATE TABLE `comment` (
|
||||
`isUsed` int NULL DEFAULT NULL COMMENT '是否使用过',
|
||||
`commentTime` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '评论时间',
|
||||
`isValid` int NULL DEFAULT NULL COMMENT '是否有效',
|
||||
`star` int NULL DEFAULT NULL COMMENT '评分',
|
||||
PRIMARY KEY (`commentId`) USING BTREE,
|
||||
INDEX `userId_comment`(`userId` ASC) USING BTREE,
|
||||
INDEX `projectId_comment`(`projectId` ASC) USING BTREE,
|
||||
CONSTRAINT `projectId_comment` FOREIGN KEY (`projectId`) REFERENCES `project` (`projectId`) ON DELETE RESTRICT ON UPDATE RESTRICT,
|
||||
CONSTRAINT `userId_comment` FOREIGN KEY (`userId`) REFERENCES `project` (`userId`) ON DELETE RESTRICT ON UPDATE RESTRICT
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '评论表' ROW_FORMAT = DYNAMIC;
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '评论表' ROW_FORMAT = DYNAMIC;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of comment
|
||||
-- ----------------------------
|
||||
INSERT INTO `comment` VALUES (1, 1, 1, 'hao好好', 1, '2023', 1, NULL);
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for project
|
||||
@@ -134,14 +136,19 @@ CREATE TABLE `project` (
|
||||
INDEX `categoryId_project`(`categoryId` ASC) USING BTREE,
|
||||
CONSTRAINT `categoryId_project` FOREIGN KEY (`categoryId`) REFERENCES `category` (`categoryId`) ON DELETE RESTRICT ON UPDATE RESTRICT,
|
||||
CONSTRAINT `userId` FOREIGN KEY (`userId`) REFERENCES `user` (`userId`) ON DELETE RESTRICT ON UPDATE RESTRICT
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '项目表' ROW_FORMAT = DYNAMIC;
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 9 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '项目表' ROW_FORMAT = DYNAMIC;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of project
|
||||
-- ----------------------------
|
||||
INSERT INTO `project` VALUES (1, 1, 'primihub', '11111', 'https://pic.imgdb.cn/item/6495df131ddac507cc80689f.png', '由密码学专家团队打造的开源隐私计算平台\r\nHelloGitHub 评分\r\n', '随着《数据安全法》和《个人信息保护法》的相继颁布,隐私计算技术在近两年迎来了前所未有的热度。该项目是由密码学专家团队打造的隐私计算平台,它开箱即用、安全可靠,支持隐匿查询、隐私求交、联合统计、数据资源管理等功能,实现了“数据可用不可见”,为数据安全流通保驾护航。', 1, '2023-06-30 18:58:01', 1, 1, '1111', 1, 111);
|
||||
INSERT INTO `project` VALUES (2, 1, 'primihub', '11111', 'https://pic.imgdb.cn/item/6495df131ddac507cc80689f.png', '由密码学专家团队打造的开源隐私计算平台\r\nHelloGitHub 评分\r\n', '随着《数据安全法》和《个人信息保护法》的相继颁布,隐私计算技术在近两年迎来了前所未有的热度。该项目是由密码学专家团队打造的隐私计算平台,它开箱即用、安全可靠,支持隐匿查询、隐私求交、联合统计、数据资源管理等功能,实现了“数据可用不可见”,为数据安全流通保驾护航。', 1, '2023-06-30 18:58:01', 1, 1, '1111', 1, 222);
|
||||
INSERT INTO `project` VALUES (3, 1, 'primihub', '11111', 'https://pic.imgdb.cn/item/6495df131ddac507cc80689f.png', '由密码学专家团队打造的开源隐私计算平台\r\nHelloGitHub 评分\r\n', '随着《数据安全法》和《个人信息保护法》的相继颁布,隐私计算技术在近两年迎来了前所未有的热度。该项目是由密码学专家团队打造的隐私计算平台,它开箱即用、安全可靠,支持隐匿查询、隐私求交、联合统计、数据资源管理等功能,实现了“数据可用不可见”,为数据安全流通保驾护航。', 1, '2023-06-30 18:58:01', 2, 1, '1111', 1, 3333);
|
||||
INSERT INTO `project` VALUES (1, 1, 'primihub', '11111', 'https://pic.imgdb.cn/item/6495df131ddac507cc80689f.png', '由密码学专家团队打造的开源隐私计算平台\r\nHelloGitHub 评分\r\n', '随着《数据安全法》和《个人信息保护法》的相继颁布,隐私计算技术在近两年迎来了前所未有的热度。该项目是由密码学专家团队打造的隐私计算平台,它开箱即用、安全可靠,支持隐匿查询、隐私求交、联合统计、数据资源管理等功能,实现了“数据可用不可见”,为数据安全流通保驾护航。', 1, '2023-06-30 18:58:01', 1, 1, '1111', 1, 15);
|
||||
INSERT INTO `project` VALUES (2, 2, 'primihub', '11111', 'https://pic.imgdb.cn/item/6495df131ddac507cc80689f.png', '由密码学专家团队打造的开源隐私计算平台\r\nHelloGitHub 评分\r\n', '随着《数据安全法》和《个人信息保护法》的相继颁布,隐私计算技术在近两年迎来了前所未有的热度。该项目是由密码学专家团队打造的隐私计算平台,它开箱即用、安全可靠,支持隐匿查询、隐私求交、联合统计、数据资源管理等功能,实现了“数据可用不可见”,为数据安全流通保驾护航。', 1, '2023-06-30 18:58:01', 2, 1, '1111', 1, 23);
|
||||
INSERT INTO `project` VALUES (3, 1, 'primihub', '11111', 'https://pic.imgdb.cn/item/6495df131ddac507cc80689f.png', '由密码学专家团队打造的开源隐私计算平台\r\nHelloGitHub 评分\r\n', '随着《数据安全法》和《个人信息保护法》的相继颁布,隐私计算技术在近两年迎来了前所未有的热度。该项目是由密码学专家团队打造的隐私计算平台,它开箱即用、安全可靠,支持隐匿查询、隐私求交、联合统计、数据资源管理等功能,实现了“数据可用不可见”,为数据安全流通保驾护航。', 1, '2023-06-30 18:58:01', 3, 1, '1111', 1, 333);
|
||||
INSERT INTO `project` VALUES (4, 1, 'primihub', '11111', 'https://pic.imgdb.cn/item/6495df131ddac507cc80689f.png', '由密码学专家团队打造的开源隐私计算平台\r\nHelloGitHub 评分\r\n', '随着《数据安全法》和《个人信息保护法》的相继颁布,隐私计算技术在近两年迎来了前所未有的热度。该项目是由密码学专家团队打造的隐私计算平台,它开箱即用、安全可靠,支持隐匿查询、隐私求交、联合统计、数据资源管理等功能,实现了“数据可用不可见”,为数据安全流通保驾护航。', 1, '2023-06-30 18:58:01', 4, 1, '1111', 1, 4444);
|
||||
INSERT INTO `project` VALUES (5, 1, 'primihub', '11111', 'https://pic.imgdb.cn/item/6495df131ddac507cc80689f.png', '由密码学专家团队打造的开源隐私计算平台\r\nHelloGitHub 评分\r\n', '随着《数据安全法》和《个人信息保护法》的相继颁布,隐私计算技术在近两年迎来了前所未有的热度。该项目是由密码学专家团队打造的隐私计算平台,它开箱即用、安全可靠,支持隐匿查询、隐私求交、联合统计、数据资源管理等功能,实现了“数据可用不可见”,为数据安全流通保驾护航。', 1, '2023-06-30 18:58:01', 5, 1, '1111', 1, 55555);
|
||||
INSERT INTO `project` VALUES (6, 2, 'primihub', '11111', 'https://pic.imgdb.cn/item/6495df131ddac507cc80689f.png', '由密码学专家团队打造的开源隐私计算平台\r\nHelloGitHub 评分\r\n', '随着《数据安全法》和《个人信息保护法》的相继颁布,隐私计算技术在近两年迎来了前所未有的热度。该项目是由密码学专家团队打造的隐私计算平台,它开箱即用、安全可靠,支持隐匿查询、隐私求交、联合统计、数据资源管理等功能,实现了“数据可用不可见”,为数据安全流通保驾护航。', 1, '2023-06-30 18:58:01', 6, 1, '1111', 1, 666666);
|
||||
INSERT INTO `project` VALUES (7, 1, 'primihub', '11111', 'https://pic.imgdb.cn/item/6495df131ddac507cc80689f.png', '由密码学专家团队打造的开源隐私计算平台\r\nHelloGitHub 评分\r\n', '随着《数据安全法》和《个人信息保护法》的相继颁布,隐私计算技术在近两年迎来了前所未有的热度。该项目是由密码学专家团队打造的隐私计算平台,它开箱即用、安全可靠,支持隐匿查询、隐私求交、联合统计、数据资源管理等功能,实现了“数据可用不可见”,为数据安全流通保驾护航。', 1, '2023-06-30 18:58:01', 7, 1, '1111', 1, 7777777);
|
||||
INSERT INTO `project` VALUES (8, 2, 'primihub', '11111', 'https://pic.imgdb.cn/item/6495df131ddac507cc80689f.png', '由密码学专家团队打造的开源隐私计算平台\r\nHelloGitHub 评分\r\n', '随着《数据安全法》和《个人信息保护法》的相继颁布,隐私计算技术在近两年迎来了前所未有的热度。该项目是由密码学专家团队打造的隐私计算平台,它开箱即用、安全可靠,支持隐匿查询、隐私求交、联合统计、数据资源管理等功能,实现了“数据可用不可见”,为数据安全流通保驾护航。', 1, '2023-06-30 18:58:01', 8, 1, '1111', 1, 88888888);
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for project_category
|
||||
@@ -156,15 +163,20 @@ CREATE TABLE `project_category` (
|
||||
INDEX `projectId`(`projectId` ASC) USING BTREE,
|
||||
CONSTRAINT `categoryId` FOREIGN KEY (`categoryId`) REFERENCES `category` (`categoryId`) ON DELETE RESTRICT ON UPDATE RESTRICT,
|
||||
CONSTRAINT `projectId` FOREIGN KEY (`projectId`) REFERENCES `project` (`projectId`) ON DELETE RESTRICT ON UPDATE RESTRICT
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '项目标签中间表' ROW_FORMAT = DYNAMIC;
|
||||
) ENGINE = InnoDB AUTO_INCREMENT = 10 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '项目标签中间表' ROW_FORMAT = DYNAMIC;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of project_category
|
||||
-- ----------------------------
|
||||
INSERT INTO `project_category` VALUES (1, 1, 1);
|
||||
INSERT INTO `project_category` VALUES (2, 2, 1);
|
||||
INSERT INTO `project_category` VALUES (2, 2, 2);
|
||||
INSERT INTO `project_category` VALUES (3, 3, 3);
|
||||
INSERT INTO `project_category` VALUES (4, 1, 2);
|
||||
INSERT INTO `project_category` VALUES (4, 4, 4);
|
||||
INSERT INTO `project_category` VALUES (5, 5, 5);
|
||||
INSERT INTO `project_category` VALUES (6, 6, 6);
|
||||
INSERT INTO `project_category` VALUES (7, 7, 7);
|
||||
INSERT INTO `project_category` VALUES (8, 8, 8);
|
||||
INSERT INTO `project_category` VALUES (9, 2, 1);
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for user
|
||||
@@ -185,6 +197,7 @@ CREATE TABLE `user` (
|
||||
-- ----------------------------
|
||||
-- Records of user
|
||||
-- ----------------------------
|
||||
INSERT INTO `user` VALUES (1, '666', '666', '2023-06-29 22:43:22', 1, 1, '666;777;33;测试;hhh;rrr;12e;', NULL);
|
||||
INSERT INTO `user` VALUES (1, '666', '666', '2023-06-29 22:43:22', 1, 1, '11111;C++;C项目;github;', 1);
|
||||
INSERT INTO `user` VALUES (2, '111', '111', '2023-06-29 22:43:22', 1, 1, '', 2);
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
|
@@ -201,7 +201,7 @@ public class UserDao {
|
||||
Connection conn = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
ResultSet rs = null;
|
||||
String sql = "SELECT * FROM `user` ,`article` WHERE `user`.userId = `article`.userId AND `user`.userName = ?";
|
||||
String sql = "SELECT * FROM `user` ,`article` WHERE `user`.userId = `article`.userId AND `user`.userName = ? and isValid = 1";
|
||||
int Value = 0;
|
||||
int projectNum = 0;
|
||||
try{
|
||||
|
@@ -24,7 +24,7 @@ public class articleDao {
|
||||
Connection conn = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
ResultSet rs = null;
|
||||
String sql = "SELECT * FROM `article` ORDER BY publishTime DESC;";
|
||||
String sql = "SELECT * FROM `article` where isValid = 1 ORDER BY publishTime DESC;";
|
||||
ArrayList<com.hellogithub.entity.articleEntity> articleEntities = new ArrayList<articleEntity>();
|
||||
try {
|
||||
conn = JdbcUtils.getConnection();
|
||||
@@ -62,7 +62,7 @@ public class articleDao {
|
||||
Connection conn = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
ResultSet rs = null;
|
||||
String sql = "SELECT * FROM `article` ORDER BY readCount DESC";
|
||||
String sql = "SELECT * FROM `article` where isValid = 1 ORDER BY readCount DESC";
|
||||
ArrayList<com.hellogithub.entity.articleEntity> articleEntities = new ArrayList<articleEntity>();
|
||||
try {
|
||||
conn = JdbcUtils.getConnection();
|
||||
|
@@ -19,7 +19,7 @@ public class categoryDao {
|
||||
try {
|
||||
Connection conn = JdbcUtils.getConnection();
|
||||
QueryRunner runner = new QueryRunner();
|
||||
String sql = "select * from category ";
|
||||
String sql = "select * from category where isValid = 1";
|
||||
categoryEntity = runner.query(conn, sql, new BeanListHandler<>(categoryEntity.class));
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
@@ -33,7 +33,7 @@ public class categoryDao {
|
||||
try {
|
||||
Connection conn = JdbcUtils.getConnection();
|
||||
QueryRunner runner = new QueryRunner();
|
||||
String sql = "select * from category where categoryId=?";
|
||||
String sql = "select * from category where categoryId=? and isValid = 1";
|
||||
categoryEntity = runner.query(conn, sql, new BeanHandler<>(categoryEntity.class),id);
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
|
29
src/com/hellogithub/dao/commentDao.java
Normal file
29
src/com/hellogithub/dao/commentDao.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package com.hellogithub.dao;
|
||||
|
||||
import com.hellogithub.entity.categoryEntity;
|
||||
import com.hellogithub.entity.commentEntity;
|
||||
import com.hellogithub.utils.JdbcUtils;
|
||||
import org.apache.commons.dbutils.QueryRunner;
|
||||
import org.apache.commons.dbutils.handlers.BeanListHandler;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
public class commentDao {
|
||||
|
||||
//显示评论
|
||||
public List<commentEntity> selectByProjectId(String id){
|
||||
List<commentEntity> commentEntityList ;
|
||||
try {
|
||||
Connection conn = JdbcUtils.getConnection();
|
||||
QueryRunner runner = new QueryRunner();
|
||||
String sql = "select * from comment where projectId = ? and isValid = 1";
|
||||
commentEntityList = runner.query(conn, sql,new BeanListHandler<>(commentEntity.class),id);
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return commentEntityList;
|
||||
}
|
||||
}
|
@@ -1,5 +1,6 @@
|
||||
package com.hellogithub.dao;
|
||||
|
||||
import com.hellogithub.entity.categoryEntity;
|
||||
import com.hellogithub.entity.projectEntity;
|
||||
import com.hellogithub.utils.JdbcUtils;
|
||||
import org.apache.commons.dbutils.QueryRunner;
|
||||
@@ -187,4 +188,37 @@ public class projectDao {
|
||||
}
|
||||
return projectEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据项目ID增加观看量
|
||||
*/
|
||||
public int addProjectLookcount(String id ) {
|
||||
int num;
|
||||
try {
|
||||
Connection conn = JdbcUtils.getConnection();
|
||||
QueryRunner runner = new QueryRunner();
|
||||
String sql = "UPDATE project SET lookcount = lookcount+1 WHERE projectId= ?";
|
||||
num = runner.update(conn, sql,id);
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return num;
|
||||
}
|
||||
/**
|
||||
* 返回标签
|
||||
*/
|
||||
public List<categoryEntity> retProjectLabel(String id ) {
|
||||
List<categoryEntity> categoryEntityList ;
|
||||
try {
|
||||
Connection conn = JdbcUtils.getConnection();
|
||||
QueryRunner runner = new QueryRunner();
|
||||
String sql = "select categoryName from category where isValid = 1 and categoryId in( select categoryId from project_category where projectId = ? and isValid = 1)";
|
||||
categoryEntityList = runner.query(conn, sql,new BeanListHandler<>(categoryEntity.class),id);
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return categoryEntityList;
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package com.hellogithub.entity;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class commentEntity {
|
||||
int commentId;
|
||||
@@ -8,7 +7,7 @@ public class commentEntity {
|
||||
int projectId;
|
||||
String content;
|
||||
int isUsed;
|
||||
Date commentTime;
|
||||
String commentTime;
|
||||
int isValid;
|
||||
|
||||
public int getCommentId() {
|
||||
@@ -51,11 +50,11 @@ public class commentEntity {
|
||||
this.isUsed = isUsed;
|
||||
}
|
||||
|
||||
public Date getCommentTime() {
|
||||
public String getCommentTime() {
|
||||
return commentTime;
|
||||
}
|
||||
|
||||
public void setCommentTime(Date commentTime) {
|
||||
public void setCommentTime(String commentTime) {
|
||||
this.commentTime = commentTime;
|
||||
}
|
||||
|
||||
@@ -66,4 +65,14 @@ public class commentEntity {
|
||||
public void setIsValid(int isValid) {
|
||||
this.isValid = isValid;
|
||||
}
|
||||
|
||||
int star;
|
||||
|
||||
public int getStar() {
|
||||
return star;
|
||||
}
|
||||
|
||||
public void setStar(int star) {
|
||||
this.star = star;
|
||||
}
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@ public class userEntity {
|
||||
private String userName;
|
||||
private String userPassword;
|
||||
|
||||
private Date creatTime;
|
||||
private String creatTime;
|
||||
|
||||
private Integer isValid;
|
||||
|
||||
@@ -41,7 +41,7 @@ public class userEntity {
|
||||
this.userPassword = userPassword;
|
||||
}
|
||||
|
||||
public userEntity(Integer userId, String userName, String userPassword, Date creatTime, Integer isValid, Integer projectNum, String searchHistory, Integer contributionValue) {
|
||||
public userEntity(Integer userId, String userName, String userPassword, String creatTime, Integer isValid, Integer projectNum, String searchHistory, Integer contributionValue) {
|
||||
this.userId = userId;
|
||||
this.userName = userName;
|
||||
this.userPassword = userPassword;
|
||||
@@ -76,11 +76,11 @@ public class userEntity {
|
||||
this.userPassword = userPassword;
|
||||
}
|
||||
|
||||
public Date getCreatTime() {
|
||||
public String getCreatTime() {
|
||||
return creatTime;
|
||||
}
|
||||
|
||||
public void setCreatTime(Date creatTime) {
|
||||
public void setCreatTime(String creatTime) {
|
||||
this.creatTime = creatTime;
|
||||
}
|
||||
|
||||
|
@@ -62,4 +62,6 @@ public class UserService {
|
||||
* @return
|
||||
*/
|
||||
public int contributionValueReturn(String name){return userDao.contributionValueReturn(name);}
|
||||
|
||||
public int addLabel(String username,String str){return userDao.addLabel(username,str);}
|
||||
}
|
||||
|
39
src/com/hellogithub/service/commentService.java
Normal file
39
src/com/hellogithub/service/commentService.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package com.hellogithub.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.hellogithub.dao.UserDao;
|
||||
import com.hellogithub.dao.commentDao;
|
||||
import com.hellogithub.entity.commentEntity;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class commentService {
|
||||
private commentDao commentDao =new commentDao();
|
||||
private UserDao userDao = new UserDao();
|
||||
//显示所有评论
|
||||
public String selectByProjectId(String id){
|
||||
List<commentEntity> commentEntityList;
|
||||
Map<String,String> dataMap = new HashMap<>();
|
||||
Map<String,Map<String,String>> dataMap2 = new HashMap<>();
|
||||
commentEntityList = commentDao.selectByProjectId(id);
|
||||
for(int i=0;i<commentEntityList.size();i++)
|
||||
{
|
||||
commentEntity commentEntity = commentEntityList.get(i);
|
||||
dataMap = new HashMap<>();
|
||||
int userid = commentEntity.getUserId();
|
||||
String username = userDao.selectNameById(userid);
|
||||
String time = commentEntity.getCommentTime();
|
||||
String content = commentEntity.getContent();
|
||||
int star = commentEntity.getStar();
|
||||
dataMap.put("username",username);
|
||||
dataMap.put("time",time);
|
||||
dataMap.put("content",content);
|
||||
dataMap.put("star",String.valueOf(star));
|
||||
dataMap2.put(String.valueOf(i),dataMap);
|
||||
}
|
||||
return JSONArray.toJSONString(dataMap2);
|
||||
}
|
||||
}
|
@@ -1,11 +1,17 @@
|
||||
package com.hellogithub.service;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.hellogithub.dao.categoryDao;
|
||||
import com.hellogithub.dao.projectDao;
|
||||
import com.hellogithub.entity.categoryEntity;
|
||||
import com.hellogithub.entity.projectEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class projectService {
|
||||
@@ -123,4 +129,20 @@ public class projectService {
|
||||
projectEntity.setCategoryName(categoryEntity.getCategoryName());
|
||||
return projectEntity;
|
||||
}
|
||||
public int addProjectLookcount(String id ){
|
||||
return projectDao.addProjectLookcount(id);
|
||||
}
|
||||
public String retProjectLabel(String id ){
|
||||
Map<String,List<String>> dataMap = new HashMap<>();
|
||||
List<String> strs=new ArrayList<>();
|
||||
List<categoryEntity> categoryEntityList = projectDao.retProjectLabel(id);
|
||||
for(int i=0;i<categoryEntityList.size();i++)
|
||||
{
|
||||
categoryEntity categoryEntity=categoryEntityList.get(i);
|
||||
strs.add(categoryEntity.getCategoryName());
|
||||
|
||||
}
|
||||
dataMap.put("CategoryName",strs);
|
||||
return JSONArray.toJSONString(dataMap);
|
||||
}
|
||||
}
|
@@ -69,9 +69,9 @@ public class UserLoginServlet extends HttpServlet {
|
||||
if ("true".equals(rememberPassword)) {
|
||||
// 如果有记住密码则 将密码保存在cookie中
|
||||
Cookie userNameCookie = new Cookie("userName", userName);
|
||||
Cookie userPwdCookie = new Cookie("userPwd", userPwd);
|
||||
// Cookie userPwdCookie = new Cookie("userPwd", userPwd);
|
||||
resp.addCookie(userNameCookie);
|
||||
resp.addCookie(userPwdCookie);
|
||||
// resp.addCookie(userPwdCookie);
|
||||
}
|
||||
// 能够db中查询到对象 登录成功了 将用户数据存放在session中
|
||||
session = req.getSession();
|
||||
|
@@ -3,6 +3,7 @@ package com.hellogithub.servlet;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.hellogithub.entity.projectEntity;
|
||||
import com.hellogithub.entity.userEntity;
|
||||
import com.hellogithub.service.UserService;
|
||||
import com.hellogithub.service.projectService;
|
||||
import jakarta.servlet.ServletConfig;
|
||||
import jakarta.servlet.ServletException;
|
||||
@@ -19,6 +20,7 @@ import java.util.List;
|
||||
@WebServlet("/selectByInput")
|
||||
public class selectByInputServlet extends HttpServlet {
|
||||
private com.hellogithub.service.projectService projectService=new projectService();
|
||||
private UserService userService = new UserService();
|
||||
@Override
|
||||
public void init(ServletConfig config) throws ServletException {
|
||||
|
||||
@@ -41,7 +43,7 @@ public class selectByInputServlet extends HttpServlet {
|
||||
resp.setHeader("Access-Control-Max-Age", "3600");
|
||||
resp.setHeader("Access-Control-Allow-Headers", "access-control-allow-origin, authority, content-type, version-info, X-Requested-With");
|
||||
resp.setContentType("application/json;charset=UTF-8");
|
||||
//返回最新期刊数字
|
||||
//添加搜索历史
|
||||
PrintWriter writer = resp.getWriter();
|
||||
String str = req.getParameter("xxxxx");
|
||||
List<projectEntity> projectEntityList = projectService.selectByInput(str);
|
||||
@@ -51,24 +53,35 @@ public class selectByInputServlet extends HttpServlet {
|
||||
userEntity=(userEntity)session.getAttribute("user");
|
||||
if(userEntity == null)
|
||||
{
|
||||
|
||||
if(projectEntityList.size() == 0 ){
|
||||
setResultError("查询结果为空",writer);
|
||||
}
|
||||
else{
|
||||
String jsonString = JSONObject.toJSONString(projectEntityList);
|
||||
setResultOK("success",writer);
|
||||
writer.println(jsonString);
|
||||
writer.close();
|
||||
setResultOK("success",writer);
|
||||
}
|
||||
}
|
||||
else{
|
||||
String username = userEntity.getUserName();
|
||||
int num = userService.addLabel(username,str);
|
||||
|
||||
|
||||
if(projectEntityList.size() == 0 ){
|
||||
setResultError("查询结果为空",writer);
|
||||
}
|
||||
else{
|
||||
String jsonString = JSONObject.toJSONString(projectEntityList);
|
||||
setResultOK("success",writer);
|
||||
writer.println(jsonString);
|
||||
writer.close();
|
||||
setResultOK("success",writer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(projectEntityList.size() == 0 ){
|
||||
setResultError("查询结果为空",writer);
|
||||
}
|
||||
else{
|
||||
String jsonString = JSONObject.toJSONString(projectEntityList);
|
||||
setResultOK("success",writer);
|
||||
writer.println(jsonString);
|
||||
writer.close();
|
||||
setResultOK("success",writer);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
public void setResult(Integer code, String msg, PrintWriter writer) {
|
||||
|
63
src/com/hellogithub/servlet/selectCommentByProServlet.java
Normal file
63
src/com/hellogithub/servlet/selectCommentByProServlet.java
Normal file
@@ -0,0 +1,63 @@
|
||||
package com.hellogithub.servlet;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.hellogithub.service.commentService;
|
||||
import jakarta.servlet.ServletConfig;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.annotation.WebServlet;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.HashMap;
|
||||
|
||||
@WebServlet("/selectCommentByPro")
|
||||
public class selectCommentByProServlet extends HttpServlet {
|
||||
private commentService commentService = new commentService();
|
||||
@Override
|
||||
public void init(ServletConfig config) throws ServletException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
doPost(req, resp);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
resp.setCharacterEncoding("UTF-8");
|
||||
resp.setContentType("text/html; charset=utf-8");
|
||||
// 设置响应头允许ajax跨域访问
|
||||
String curOrigin = req.getHeader("Origin");
|
||||
resp.setHeader("Access-Control-Allow-Origin", curOrigin == null ? "true" : curOrigin);
|
||||
resp.setHeader("Access-Control-Allow-Credentials", "true");
|
||||
resp.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, HEAD");
|
||||
resp.setHeader("Access-Control-Max-Age", "3600");
|
||||
resp.setHeader("Access-Control-Allow-Headers", "access-control-allow-origin, authority, content-type, version-info, X-Requested-With");
|
||||
resp.setContentType("application/json;charset=UTF-8");
|
||||
//按照分类检索
|
||||
String id = req.getParameter("id");
|
||||
PrintWriter writer = resp.getWriter();
|
||||
writer.println(commentService.selectByProjectId(id));
|
||||
writer.close();
|
||||
}
|
||||
public void setResult(Integer code, String msg, PrintWriter writer) {
|
||||
HashMap<String, Object> result = new HashMap<>();
|
||||
result.put("code", code);
|
||||
result.put("msg", msg);
|
||||
String jsonString = JSONObject.toJSONString(result);
|
||||
writer.println(jsonString);
|
||||
writer.close();
|
||||
}
|
||||
|
||||
public void setResultError(String msg, PrintWriter writer) {
|
||||
setResult(500, msg, writer);
|
||||
}
|
||||
|
||||
public void setResultOK(String msg, PrintWriter writer) {
|
||||
setResult(200, msg, writer);
|
||||
}
|
||||
}
|
@@ -1,5 +1,6 @@
|
||||
package com.hellogithub.servlet;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.hellogithub.service.projectService;
|
||||
import jakarta.servlet.ServletConfig;
|
||||
@@ -37,11 +38,17 @@ public class selectProByIdServlet extends HttpServlet {
|
||||
resp.setHeader("Access-Control-Max-Age", "3600");
|
||||
resp.setHeader("Access-Control-Allow-Headers", "access-control-allow-origin, authority, content-type, version-info, X-Requested-With");
|
||||
resp.setContentType("application/json;charset=UTF-8");
|
||||
//按照分类返回期刊
|
||||
String id = req.getParameter("xxxxxxx");
|
||||
|
||||
String id = req.getParameter("id");
|
||||
int num = projectService.addProjectLookcount(id);
|
||||
PrintWriter writer = resp.getWriter();
|
||||
String jsonString = JSONObject.toJSONString(projectService.selectProById(id));
|
||||
writer.println(jsonString);
|
||||
String dataMap = projectService.retProjectLabel(id);
|
||||
JSONObject jsonObject = JSON.parseObject(dataMap);
|
||||
jsonObject.put("project",projectService.selectProById(id));
|
||||
writer.println(JSONObject.toJSONString(jsonObject));
|
||||
if(num == 0 ){
|
||||
setResult(200, "观看量增加失败", writer);
|
||||
}
|
||||
writer.close();
|
||||
}
|
||||
public void setResult(Integer code, String msg, PrintWriter writer) {
|
||||
|
Reference in New Issue
Block a user