对user有效值设置
This commit is contained in:
@@ -161,4 +161,17 @@ public class AdminDao {
|
|||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int updateisValid(int id,int isvalid)
|
||||||
|
{
|
||||||
|
int num ;
|
||||||
|
try {
|
||||||
|
Connection conn = JdbcUtils.getConnection();
|
||||||
|
QueryRunner runner = new QueryRunner();
|
||||||
|
String sql="UPDATE user SET isValid = ? WHERE userId = ?";
|
||||||
|
num = runner.update(conn, sql, isvalid,id);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return num;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -24,4 +24,6 @@ public class AdminService {
|
|||||||
public int adminRegister(String adminName,String pwd){
|
public int adminRegister(String adminName,String pwd){
|
||||||
return adminDao.adminRegister(adminName,pwd);
|
return adminDao.adminRegister(adminName,pwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int updateisValid(int id,int isvalid) {return adminDao.updateisValid(id,isvalid);}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,67 @@
|
|||||||
|
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;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
@WebServlet("/updateisValid")
|
||||||
|
public class updateisValidServlet 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();
|
||||||
|
int id = Integer.parseInt(req.getParameter("userId"));
|
||||||
|
int isvalid = Integer.parseInt(req.getParameter("isValid"));
|
||||||
|
int num = adminService.updateisValid(id,isvalid);
|
||||||
|
if(num<=0){
|
||||||
|
setResultError("失败!", writer);
|
||||||
|
writer.close();
|
||||||
|
return;
|
||||||
|
}else{
|
||||||
|
setResultOK("成功!", writer);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user