增加注释
This commit is contained in:
@@ -112,31 +112,38 @@ public class UserDao {
|
|||||||
JdbcUtils.closeConnection(resultSet, preparedStatement, connection);
|
JdbcUtils.closeConnection(resultSet, preparedStatement, connection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
public int dedletePieceLabel(int userID,String str){
|
*
|
||||||
|
* 根据用户名和选取标签进行删除
|
||||||
|
* */
|
||||||
|
public int dedletePieceLabel(String name,String str){
|
||||||
String label;
|
String label;
|
||||||
int num;
|
int num;
|
||||||
try {
|
try {
|
||||||
Connection conn = JdbcUtils.getConnection();
|
Connection conn = JdbcUtils.getConnection();
|
||||||
QueryRunner runner = new QueryRunner();
|
QueryRunner runner = new QueryRunner();
|
||||||
String sql = "select searchHistory from user where userId=?";
|
String sql = "select searchHistory from user where userName=?";
|
||||||
label = runner.query(conn, sql, new BeanHandler<>(String.class),userID);
|
label = runner.query(conn, sql, new BeanHandler<>(String.class),name);
|
||||||
label=label.replace(str,"");
|
label=label.replace(str,"");
|
||||||
sql="UPDATE user SET searchHistory = ? WHERE userId= ?";
|
sql="UPDATE user SET searchHistory = ? WHERE userName= ?";
|
||||||
num = runner.update(conn,sql,label,userID);
|
num = runner.update(conn,sql,label,name);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
public String selectLabel(int userID){
|
/*
|
||||||
|
*
|
||||||
|
* 根据用户名返回搜索历史
|
||||||
|
* */
|
||||||
|
public String selectLabel(String name){
|
||||||
String label;
|
String label;
|
||||||
try {
|
try {
|
||||||
Connection conn = JdbcUtils.getConnection();
|
Connection conn = JdbcUtils.getConnection();
|
||||||
QueryRunner runner = new QueryRunner();
|
QueryRunner runner = new QueryRunner();
|
||||||
String sql = "select searchHistory from user where userId=?";
|
String sql = "select searchHistory from user where userName=?";
|
||||||
label = runner.query(conn, sql, new BeanHandler<>(String.class),userID);
|
label = runner.query(conn, sql, new BeanHandler<>(String.class),name);
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@@ -145,14 +152,18 @@ public class UserDao {
|
|||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int dedleteAllLabel(int userID){
|
/*
|
||||||
|
*
|
||||||
|
* 根据用户名和选取标签进行删除
|
||||||
|
* */
|
||||||
|
public int dedleteAllLabel(String name){
|
||||||
String label="";
|
String label="";
|
||||||
int num;
|
int num;
|
||||||
try {
|
try {
|
||||||
Connection conn = JdbcUtils.getConnection();
|
Connection conn = JdbcUtils.getConnection();
|
||||||
QueryRunner runner = new QueryRunner();
|
QueryRunner runner = new QueryRunner();
|
||||||
String sql="UPDATE user SET searchHistory = ? WHERE userId= ?";
|
String sql="UPDATE user SET searchHistory = ? WHERE userName= ?";
|
||||||
num = runner.update(conn,sql,label,userID);
|
num = runner.update(conn,sql,label,name);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
@@ -13,7 +13,11 @@ import java.util.List;
|
|||||||
public class projectDao {
|
public class projectDao {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按照期刊号查询
|
||||||
|
*
|
||||||
|
* @param num
|
||||||
|
*/
|
||||||
public List<projectEntity> retTerm(String num) {
|
public List<projectEntity> retTerm(String num) {
|
||||||
List<projectEntity> projectEntityList;
|
List<projectEntity> projectEntityList;
|
||||||
try {
|
try {
|
||||||
@@ -27,7 +31,11 @@ public class projectDao {
|
|||||||
}
|
}
|
||||||
return projectEntityList;
|
return projectEntityList;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 返回最新期刊数字
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
public int latestNum() {
|
public int latestNum() {
|
||||||
projectEntity projectEntity;
|
projectEntity projectEntity;
|
||||||
try {
|
try {
|
||||||
@@ -41,7 +49,11 @@ public class projectDao {
|
|||||||
}
|
}
|
||||||
return projectEntity.getPeriodicals();
|
return projectEntity.getPeriodicals();
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 返回最所有项目总数
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
public int countAll() {
|
public int countAll() {
|
||||||
int count;
|
int count;
|
||||||
try {
|
try {
|
||||||
@@ -55,7 +67,11 @@ public class projectDao {
|
|||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 按照分类检索项目
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
public List<projectEntity> retCate(int num) {
|
public List<projectEntity> retCate(int num) {
|
||||||
List<projectEntity> projectEntityList;
|
List<projectEntity> projectEntityList;
|
||||||
|
@@ -31,7 +31,20 @@ public class UserService {
|
|||||||
public userEntity findByUserName(String userName) {
|
public userEntity findByUserName(String userName) {
|
||||||
return userDao.findByUserName(userName);
|
return userDao.findByUserName(userName);
|
||||||
}
|
}
|
||||||
public int dedletePieceLabel(int userID,String str){ return userDao.dedletePieceLabel(userID, str);}
|
/**
|
||||||
public String selectLabel(int userID){return userDao.selectLabel(userID);}
|
* 根据用户名和选取标签进行删除
|
||||||
public int dedleteAllLabel(int userID){return userDao.dedleteAllLabel(userID);}
|
* @param name
|
||||||
|
* @param str
|
||||||
|
* */
|
||||||
|
public int dedletePieceLabel(String name,String str){ return userDao.dedletePieceLabel(name, str);}
|
||||||
|
/**
|
||||||
|
* 根据用户名返回搜索历史
|
||||||
|
* @param name
|
||||||
|
* */
|
||||||
|
public String selectLabel(String name){return userDao.selectLabel(name);}
|
||||||
|
/**
|
||||||
|
* 根据用户名和选取标签进行删除
|
||||||
|
* @param name
|
||||||
|
* */
|
||||||
|
public int dedleteAllLabel(String name){return userDao.dedleteAllLabel(name);}
|
||||||
}
|
}
|
||||||
|
@@ -8,9 +8,28 @@ import java.util.List;
|
|||||||
|
|
||||||
public class projectService {
|
public class projectService {
|
||||||
private projectDao projectDao=new projectDao();
|
private projectDao projectDao=new projectDao();
|
||||||
|
/**
|
||||||
|
* 按照期刊号查询
|
||||||
|
*
|
||||||
|
* @param num
|
||||||
|
*/
|
||||||
public List<projectEntity> retTerm(String num){return projectDao.retTerm(num);}
|
public List<projectEntity> retTerm(String num){return projectDao.retTerm(num);}
|
||||||
|
/**
|
||||||
|
* 返回最新期刊数字
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
public int latestNum() {return projectDao.latestNum();}
|
public int latestNum() {return projectDao.latestNum();}
|
||||||
|
/**
|
||||||
|
* 返回最所有项目总数
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
public int countAll() {return projectDao.countAll();}
|
public int countAll() {return projectDao.countAll();}
|
||||||
|
/**
|
||||||
|
* 按照分类检索项目
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
public List<projectEntity> retCate(int num){return projectDao.retCate(num);}
|
public List<projectEntity> retCate(int num){return projectDao.retCate(num);}
|
||||||
}
|
}
|
||||||
|
@@ -6,6 +6,7 @@ import jakarta.servlet.ServletException;
|
|||||||
import jakarta.servlet.http.HttpServlet;
|
import jakarta.servlet.http.HttpServlet;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import jakarta.servlet.http.HttpSession;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
@@ -20,10 +21,23 @@ public class deleteAllLabelServlet extends HttpServlet {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
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");
|
||||||
|
|
||||||
PrintWriter writer = resp.getWriter();
|
PrintWriter writer = resp.getWriter();
|
||||||
String id = req.getParameter("xxxxx");
|
HttpSession session = req.getSession();
|
||||||
int num = userService.dedleteAllLabel(Integer.parseInt(id));
|
String name = (String)session.getAttribute("username");
|
||||||
|
|
||||||
|
//返回处理行数,如果为零则代表处理零条结果
|
||||||
|
int num = userService.dedleteAllLabel(name);
|
||||||
if(num == 0 ){
|
if(num == 0 ){
|
||||||
setResultError("删除失败",writer);
|
setResultError("删除失败",writer);
|
||||||
}else{
|
}else{
|
||||||
|
@@ -6,6 +6,7 @@ import jakarta.servlet.ServletException;
|
|||||||
import jakarta.servlet.http.HttpServlet;
|
import jakarta.servlet.http.HttpServlet;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import jakarta.servlet.http.HttpSession;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
@@ -20,10 +21,24 @@ public class deletelabelServlet extends HttpServlet {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
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");
|
||||||
PrintWriter writer = resp.getWriter();
|
PrintWriter writer = resp.getWriter();
|
||||||
String id = req.getParameter("xxxxx");
|
|
||||||
|
HttpSession session = req.getSession();
|
||||||
|
String name = (String)session.getAttribute("username");
|
||||||
String str = req.getParameter("xxxxx");
|
String str = req.getParameter("xxxxx");
|
||||||
int num = userService.dedletePieceLabel(Integer.parseInt(id),str);
|
|
||||||
|
int num = userService.dedletePieceLabel(name,str);
|
||||||
|
//返回处理行数,如果为零则代表处理零条结果
|
||||||
if(num == 0 ){
|
if(num == 0 ){
|
||||||
setResultError("删除失败",writer);
|
setResultError("删除失败",writer);
|
||||||
}else{
|
}else{
|
||||||
|
@@ -11,6 +11,9 @@ import jakarta.servlet.http.HttpServletResponse;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
|
||||||
@WebServlet("/latest")
|
@WebServlet("/latest")
|
||||||
public class latestServlet extends HttpServlet {
|
public class latestServlet extends HttpServlet {
|
||||||
private com.hellogithub.service.projectService projectService=new projectService();
|
private com.hellogithub.service.projectService projectService=new projectService();
|
||||||
@@ -36,10 +39,28 @@ public class latestServlet extends HttpServlet {
|
|||||||
resp.setHeader("Access-Control-Max-Age", "3600");
|
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.setHeader("Access-Control-Allow-Headers", "access-control-allow-origin, authority, content-type, version-info, X-Requested-With");
|
||||||
resp.setContentType("application/json;charset=UTF-8");
|
resp.setContentType("application/json;charset=UTF-8");
|
||||||
|
//返回最新期刊数字
|
||||||
PrintWriter writer = resp.getWriter();
|
PrintWriter writer = resp.getWriter();
|
||||||
String jsonString = JSONObject.toJSONString(projectService.latestNum());
|
String jsonString = JSONObject.toJSONString(projectService.latestNum());
|
||||||
|
setResultOK("success",writer);
|
||||||
writer.println(jsonString);
|
writer.println(jsonString);
|
||||||
writer.close();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -10,6 +10,8 @@ import jakarta.servlet.http.HttpServletRequest;
|
|||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
@WebServlet("/selectCate")
|
@WebServlet("/selectCate")
|
||||||
public class selectCateServlet extends HttpServlet {
|
public class selectCateServlet extends HttpServlet {
|
||||||
private projectService projectService=new projectService();
|
private projectService projectService=new projectService();
|
||||||
@@ -35,11 +37,29 @@ public class selectCateServlet extends HttpServlet {
|
|||||||
resp.setHeader("Access-Control-Max-Age", "3600");
|
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.setHeader("Access-Control-Allow-Headers", "access-control-allow-origin, authority, content-type, version-info, X-Requested-With");
|
||||||
resp.setContentType("application/json;charset=UTF-8");
|
resp.setContentType("application/json;charset=UTF-8");
|
||||||
|
//按照分类检索
|
||||||
String num = req.getParameter("xxxxxxx");
|
String num = req.getParameter("xxxxxxx");
|
||||||
PrintWriter writer = resp.getWriter();
|
PrintWriter writer = resp.getWriter();
|
||||||
String jsonString = JSONObject.toJSONString(projectService.retTerm(String.valueOf(num)));
|
String jsonString = JSONObject.toJSONString(projectService.retCate(Integer.valueOf(num)));
|
||||||
|
setResultOK("success",writer);
|
||||||
writer.println(jsonString);
|
writer.println(jsonString);
|
||||||
writer.close();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,6 +11,8 @@ import jakarta.servlet.http.HttpServletResponse;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
@WebServlet("/selectTerm")
|
@WebServlet("/selectTerm")
|
||||||
public class selectTermServlet extends HttpServlet {
|
public class selectTermServlet extends HttpServlet {
|
||||||
private projectService projectService=new projectService();
|
private projectService projectService=new projectService();
|
||||||
@@ -36,11 +38,29 @@ public class selectTermServlet extends HttpServlet {
|
|||||||
resp.setHeader("Access-Control-Max-Age", "3600");
|
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.setHeader("Access-Control-Allow-Headers", "access-control-allow-origin, authority, content-type, version-info, X-Requested-With");
|
||||||
resp.setContentType("application/json;charset=UTF-8");
|
resp.setContentType("application/json;charset=UTF-8");
|
||||||
|
//按照分类返回期刊
|
||||||
String num = req.getParameter("xxxxxxx");
|
String num = req.getParameter("xxxxxxx");
|
||||||
PrintWriter writer = resp.getWriter();
|
PrintWriter writer = resp.getWriter();
|
||||||
String jsonString = JSONObject.toJSONString(projectService.retTerm(num));
|
String jsonString = JSONObject.toJSONString(projectService.retTerm(num));
|
||||||
|
setResultOK("success",writer);
|
||||||
writer.println(jsonString);
|
writer.println(jsonString);
|
||||||
writer.close();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -29,11 +29,12 @@ public class selectUserLabelServlet extends HttpServlet {
|
|||||||
resp.setHeader("Access-Control-Allow-Headers", "access-control-allow-origin, authority, content-type, version-info, X-Requested-With");
|
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");
|
resp.setContentType("application/json;charset=UTF-8");
|
||||||
|
|
||||||
|
//返回所有的历史记录
|
||||||
PrintWriter writer = resp.getWriter();
|
PrintWriter writer = resp.getWriter();
|
||||||
String id = req.getParameter("xxxxx");
|
String name = req.getParameter("xxxxx");
|
||||||
String jsonString = JSONObject.toJSONString(userService.selectLabel(Integer.parseInt(id)));
|
String jsonString = JSONObject.toJSONString(userService.selectLabel(name));
|
||||||
writer.println(jsonString);
|
writer.println(jsonString);
|
||||||
|
setResultOK("success",writer);
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user