Merge remote-tracking branch 'origin/master'
# Conflicts: # src/com/hellogithub/dao/commentDao.java
This commit is contained in:
@@ -119,7 +119,7 @@ public class AdminDao {
|
||||
*
|
||||
* */
|
||||
|
||||
public List<adminEntity> selectAllCategory()
|
||||
public List<adminEntity> selectAllAdmin()
|
||||
{
|
||||
List<adminEntity> 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 {
|
||||
|
@@ -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() {
|
||||
}
|
||||
}
|
||||
|
@@ -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<adminEntity> 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);
|
||||
}
|
||||
}
|
||||
|
@@ -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<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);
|
||||
}
|
||||
}
|
@@ -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();
|
||||
}
|
||||
}
|
@@ -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();
|
||||
}
|
||||
}
|
@@ -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();
|
||||
|
||||
}
|
||||
}
|
BIN
web/uploadFile/c695a7e8-635c-438f-ac57-928c9f476033_8.jpg
Normal file
BIN
web/uploadFile/c695a7e8-635c-438f-ac57-928c9f476033_8.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 67 KiB |
Reference in New Issue
Block a user