diff --git a/src/com/hellogithub/dao/AdminDao.java b/src/com/hellogithub/dao/AdminDao.java index 28e88ef..f3c356f 100644 --- a/src/com/hellogithub/dao/AdminDao.java +++ b/src/com/hellogithub/dao/AdminDao.java @@ -119,7 +119,7 @@ public class AdminDao { * * */ - public List selectAllCategory() + public List selectAllAdmin() { List adminEntityList = null ; try { @@ -133,7 +133,7 @@ public class AdminDao { return adminEntityList; } - public int updateCategoryDetail(int adminId , int isValid , String adminName, String adminPassword,String loginTime ) + public int updateAdminDetail(int adminId , int isValid , String adminName, String adminPassword,String loginTime ) { int num ; try { diff --git a/src/com/hellogithub/dao/commentDao.java b/src/com/hellogithub/dao/commentDao.java index bcfa25b..c97cb2a 100644 --- a/src/com/hellogithub/dao/commentDao.java +++ b/src/com/hellogithub/dao/commentDao.java @@ -128,7 +128,7 @@ public class commentDao { try { Connection conn = JdbcUtils.getConnection(); QueryRunner runner = new QueryRunner(); - String sql="update project set userId = ? , projectId = ? , content = ? ,isUsed =?, commentTime=?, isValid=?,star=?,likeNum=?where commentId =? "; + String sql="update comment set userId = ? , projectId = ? , content = ? ,isUsed = ?, commentTime= ?, isValid= ?,star= ?,likeNum= ? where commentId = ? ;"; num = runner.update(conn,sql,userId, projectId , content , isUsed, commentTime, isValid, star, likeNum ,commentId); } catch (SQLException e) { throw new RuntimeException(e); @@ -142,7 +142,7 @@ public class commentDao { try { Connection conn = JdbcUtils.getConnection(); QueryRunner runner = new QueryRunner(); - String sql="delete from project where commentId = ?"; + String sql="delete from comment where commentId = ?"; num = runner.update(conn,sql,id); } catch (SQLException e) { throw new RuntimeException(e); diff --git a/src/com/hellogithub/entity/adminEntity.java b/src/com/hellogithub/entity/adminEntity.java index 4955ddb..8cc4838 100644 --- a/src/com/hellogithub/entity/adminEntity.java +++ b/src/com/hellogithub/entity/adminEntity.java @@ -6,9 +6,52 @@ public class adminEntity { String adminPassword; int isValid; + String loginTime; + public adminEntity(String adminName, String adminPassword) { this.adminName = adminName; this.adminPassword = adminPassword; } + public int getAdminId() { + return adminId; + } + + public void setAdminId(int adminId) { + this.adminId = adminId; + } + + public String getAdminName() { + return adminName; + } + + public void setAdminName(String adminName) { + this.adminName = adminName; + } + + public String getAdminPassword() { + return adminPassword; + } + + public void setAdminPassword(String adminPassword) { + this.adminPassword = adminPassword; + } + + public int getIsValid() { + return isValid; + } + + public void setIsValid(int isValid) { + this.isValid = isValid; + } + + public String getLoginTime() { + return loginTime; + } + + public void setLoginTime(String loginTime) { + this.loginTime = loginTime; + } + public adminEntity() { + } } diff --git a/src/com/hellogithub/service/AdminService.java b/src/com/hellogithub/service/AdminService.java index e023cc5..db87b90 100644 --- a/src/com/hellogithub/service/AdminService.java +++ b/src/com/hellogithub/service/AdminService.java @@ -4,6 +4,8 @@ import com.hellogithub.dao.AdminDao; import com.hellogithub.entity.adminEntity; import com.hellogithub.entity.userEntity; +import java.util.List; + public class AdminService { AdminDao adminDao=new AdminDao(); @@ -24,6 +26,8 @@ public class AdminService { public int adminRegister(String adminName,String pwd){ return adminDao.adminRegister(adminName,pwd); } + public List selectAllAdmin(){return adminDao.selectAllAdmin(); } + public int updateisValid_user(int id,int isvalid) {return adminDao.updateisValid_user(id,isvalid);} public int updateisValid_project(int id,int isvalid) {return adminDao.updateisValid_project(id,isvalid);} @@ -31,4 +35,11 @@ public class AdminService { public int updateisValid_category(int id,int isvalid) {return adminDao.updateisValid_category(id,isvalid);} public int updateisValid_article(int id,int isvalid) {return adminDao.updateisValid_article(id,isvalid);} public int updateisValid_admin(int id,int isvalid) {return adminDao.updateisValid_admin(id,isvalid);} + + + public int deleteAdmin (int id ){ return adminDao.deleteAdmin(id);} + + public int updateAdminDetail(int adminId , int isValid , String adminName, String adminPassword,String loginTime ) + { return adminDao.updateAdminDetail(adminId,isValid,adminName,adminPassword,loginTime); + } } diff --git a/src/com/hellogithub/servlet/DownLoadServlet.java b/src/com/hellogithub/servlet/DownLoadServlet.java deleted file mode 100644 index b10c31a..0000000 --- a/src/com/hellogithub/servlet/DownLoadServlet.java +++ /dev/null @@ -1,118 +0,0 @@ -package com.hellogithub.servlet; - -import com.alibaba.fastjson.JSONObject; -import com.hellogithub.service.projectService; - -import javax.servlet.ServletException; -import javax.servlet.annotation.WebServlet; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.*; -import java.net.URLEncoder; -import java.util.HashMap; -import java.util.UUID; - -@WebServlet("/DownLoad") -public class DownLoadServlet extends HttpServlet { - private projectService projectService = new projectService(); - - public void doGet(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - response.reset(); - response.setContentType("application/x-msdownload;charset=utf-8"); - //得到要下载的文件名 - String projectId = request.getParameter("id"); - String address = projectService.selectProById(projectId).getFileAddress(); - String[] liss = address.split("\\\\"); - String fileName = liss[liss.length - 1]; - //本地需要进行转码,linux服务器使用就会出现下载乱码 - //fileName = new String(fileName.getBytes("iso8859-1"),"UTF-8"); -// System.out.print("转码后"+fileName); - //上传的文件都是保存在/WEB-INF/upload目录下的子目录当中 - String fileSaveRootPath = this.getServletContext().getRealPath(File.separator+"WEB-INF"+File.separator+"upload").replace("\\out\\artifacts\\helloGithub_war_exploded\\WEB-INF\\upload","\\web\\projectFile");; - //通过文件名找出文件的所在目录 - //String path = findFileSavePathByFileName(fileName,fileSaveRootPath); -// String path = "/WEB-INF/upload"; - //得到要下载的文件 - File file = new File(fileSaveRootPath + File.separator + fileName); - //File file = new File(fileName); - // 浏览器请求响应转码防止乱码 - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); - //如果文件不存在 - if (!file.exists()) { - request.setAttribute("message", "wrong"); - request.getRequestDispatcher("/message.jsp").forward(request, response); - return; - } - //处理文件名 - String realname = fileName.substring(fileName.indexOf("_") + 1); -// System.out.println(realname); - //设置响应头,控制浏览器下载该文件 - response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8")); - //读取要下载的文件,保存到文件输入流 - FileInputStream in = new FileInputStream(fileSaveRootPath + File.separator + fileName); - - //创建输出流 - OutputStream out = response.getOutputStream(); - - //创建缓冲区 - byte buffer[] = new byte[1024]; - int len = 100; - //循环将输入流中的内容读取到缓冲区当中 - while ((len = in.read(buffer)) > 0) { - //输出缓冲区的内容到浏览器,实现文件下载 - out.write(buffer, 0, len); - } - //关闭文件输入流 - in.close(); - //关闭输出流 - out.close(); -// setResultOK("下载成功",writer); - } - - /** - * @param filename 要下载的文件名 - * @param saveRootPath 上传文件保存的根目录,也就是/WEB-INF/upload目录 - * @return 要下载的文件的存储目录 - * @Method: findFileSavePathByFileName - * @Description: 通过文件名和存储上传文件根目录找出要下载的文件的所在路径 - * @Anthor: - */ - public String findFileSavePathByFileName(String filename, String saveRootPath) { -// int hashcode = filename.hashCode(); -// int dir1 = hashcode&0xf; //0--15 -// int dir2 = (hashcode&0xf0)>>4; //0-15 - //String dir = saveRootPath + "\\" + dir1 + "\\" + dir2; //upload\2\3 upload\3\5 - String dir = saveRootPath; - File file = new File(dir); - if (!file.exists()) { - //创建目录 - file.mkdirs(); - } - return dir; - } - - public void doPost(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - doGet(request, response); - } - - public void setResult(Integer code, String msg, PrintWriter writer) { - HashMap 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); - } -} \ No newline at end of file diff --git a/src/com/hellogithub/servlet/systemAdmin/deleteAdminServlet.java b/src/com/hellogithub/servlet/systemAdmin/deleteAdminServlet.java new file mode 100644 index 0000000..3573877 --- /dev/null +++ b/src/com/hellogithub/servlet/systemAdmin/deleteAdminServlet.java @@ -0,0 +1,45 @@ +package com.hellogithub.servlet.systemAdmin; + +import com.alibaba.fastjson.JSONObject; +import com.hellogithub.service.AdminService; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; +@WebServlet("/deleteAdmin") +public class deleteAdminServlet extends HttpServlet { + private AdminService adminService = new AdminService(); + @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 adminId = req.getParameter("adminId"); + + PrintWriter writer = resp.getWriter(); + int num = adminService.deleteAdmin(Integer.parseInt(adminId)); + if(num == 0) + { + writer.println("wrong"); + + } + writer.close(); + } +} diff --git a/src/com/hellogithub/servlet/systemAdmin/selectAdminServlet.java b/src/com/hellogithub/servlet/systemAdmin/selectAdminServlet.java new file mode 100644 index 0000000..425a2da --- /dev/null +++ b/src/com/hellogithub/servlet/systemAdmin/selectAdminServlet.java @@ -0,0 +1,40 @@ +package com.hellogithub.servlet.systemAdmin; + +import com.alibaba.fastjson.JSONObject; +import com.hellogithub.service.AdminService; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import javax.servlet.annotation.WebServlet; +import java.io.IOException; +import java.io.PrintWriter; +@WebServlet("/selectAdmin") +public class selectAdminServlet extends HttpServlet { + private AdminService adminService = new AdminService(); + @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"); + // + + PrintWriter writer = resp.getWriter(); + String jsonString = JSONObject.toJSONString(adminService.selectAllAdmin()); + writer.println(jsonString); + writer.close(); + } +} diff --git a/src/com/hellogithub/servlet/systemAdmin/updateAdminServlet.java b/src/com/hellogithub/servlet/systemAdmin/updateAdminServlet.java new file mode 100644 index 0000000..7ab4551 --- /dev/null +++ b/src/com/hellogithub/servlet/systemAdmin/updateAdminServlet.java @@ -0,0 +1,49 @@ +package com.hellogithub.servlet.systemAdmin; + +import com.alibaba.fastjson.JSONObject; +import com.hellogithub.service.AdminService; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; +@WebServlet("/updateAdmin") +public class updateAdminServlet extends HttpServlet { + + private AdminService adminService = new AdminService(); + @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"); + // + int adminId= Integer.parseInt(req.getParameter("adminId")); + String adminName=req.getParameter("adminName"); + int isValid= Integer.parseInt(req.getParameter("isValid")); + String adminPwd=req.getParameter("adminPwd"); + String loginTime=req.getParameter("loginTime"); + PrintWriter writer = resp.getWriter(); + int num = adminService.updateAdminDetail(adminId,isValid,adminName,adminPwd,loginTime); + if( num == 0 ) + { + writer.println("wrong"); + } + writer.close(); + + } +} diff --git a/web/uploadFile/c695a7e8-635c-438f-ac57-928c9f476033_8.jpg b/web/uploadFile/c695a7e8-635c-438f-ac57-928c9f476033_8.jpg new file mode 100644 index 0000000..a87398b Binary files /dev/null and b/web/uploadFile/c695a7e8-635c-438f-ac57-928c9f476033_8.jpg differ