package com.servlet;
import com.bean.UserBean;
import com.bean.pageBean;
import com.dao.UserChange;
import com.dao.UserListDao;
import com.dao.UserAdd;
import com.dao.UserSelect;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.service.UserListService;
import com.service.UserService;
import com.util.JsonConvert;
import com.util.TokenUtils;
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;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
@WebServlet("/users/*")
public class users extends HttpServlet {
@Override//查询用户
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String token = req.getHeader("authorization");
req.setCharacterEncoding("utf8");
resp.setCharacterEncoding("utf8");
PrintWriter out = resp.getWriter();
JsonObject jsonObject = new JsonObject();
String uri = req.getRequestURI();
String query;
int pagenum;
int pagesize;
if(!TokenUtils.verify(token)){
jsonObject.addProperty("success","no");
out.println(jsonObject);
}else if(!uri.equals("/users")){
try {
find(req,resp);
} catch (SQLException e) {
e.printStackTrace();
}
}else{
query = req.getParameter("query");
pagenum = Integer.parseInt(req.getParameter("pagenum"));
pagesize = Integer.parseInt(req.getParameter("pagesize"));
pageBean page = new pageBean();
page.setPagenum(pagenum);
page.setPagesize(pagesize);
page.setQuery(query);
try {
JsonArray userlist = UserListService.getUserList(page);
int total = UserListDao.getTotal(page);
JsonObject result = new JsonObject();
result.add("userlist",userlist);
result.addProperty("total",total);
out.println(result);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
@Override//改电话号
protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
PrintWriter out = resp.getWriter();
JsonObject meta = new JsonObject();
JsonObject object = new JsonObject();
JsonObject result = new JsonObject();
JsonObject data = new JsonObject();
String token = req.getHeader("authorization");
if(!TokenUtils.verify(token)){
object.addProperty("success","no");
out.println(object);
}else{
String uri = req.getRequestURI();
int id = Integer.parseInt(uri.substring(uri.lastIndexOf("/")+1));
object = JsonConvert.JsonChange(req);
UserBean user = new UserBean();
user.setId(id);
user.setPhone(object.get("mobile").getAsInt());
try {
UserService uService = new UserService();
uService.updatePhone(user);
user = uService.getUser(id);
data.addProperty("id",user.getId());
data.addProperty("username",user.getUsername());
data.addProperty("mobile",user.getPhone());
meta.addProperty("msg","yes");
meta.addProperty("status","200");
result.add("data",data);
result.add("meta",meta);
} catch (SQLException e) {
meta.addProperty("msg","no");
meta.addProperty("status","500");
result.add("data",null);
result.add("meta",meta);
e.printStackTrace();
}
out.println(result);
}
}
@Override//添加用户
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String token = req.getHeader("authorization");
req.setCharacterEncoding("utf8");
resp.setCharacterEncoding("utf8");
PrintWriter out = resp.getWriter();
JsonObject jsonResult = new JsonObject();
if(!TokenUtils.verify(token)){
jsonResult.addProperty("success","no");
out.println(jsonResult);
}else{
jsonResult = JsonConvert.JsonChange(req);
UserBean user = new UserBean();
user.setUsername(jsonResult.get("username").getAsString());
user.setPassword(jsonResult.get("password").getAsString());
user.setPhone(jsonResult.get("phone").getAsInt());
LocalDateTime now = LocalDateTime.now();
String time = now.format(DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"));
user.setCreateTime(time);
try {
new UserService().add(user);
jsonResult.addProperty("success","yes");
} catch (SQLException e) {
jsonResult.addProperty("success","no");
e.printStackTrace();
}
out.println(jsonResult);
}
}
//根据id找用户
protected void find(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException, SQLException {
req.setCharacterEncoding("utf8");
resp.setCharacterEncoding("utf8");
PrintWriter out = resp.getWriter();
JsonObject meta = new JsonObject();
JsonObject result = new JsonObject();
JsonObject data = new JsonObject();
String uri = req.getRequestURI();
int id = Integer.parseInt(uri.substring(uri.lastIndexOf("/")+1));
UserBean user = new UserService().getUser(id);
data.addProperty("id",user.getId());
data.addProperty("username",user.getUsername());
data.addProperty("mobile",String.valueOf(user.getPhone()));
meta.addProperty("msg","ok");
meta.addProperty("status",200);
result.add("data",data);
result.add("meta",meta);
out.println(result);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
一体化实践课程设计javaweb电商后台管理系统源码+项目文档+汇报PPT 一体化实践课程设计javaweb电商后台管理系统源码+项目文档+汇报PPT一体化实践课程设计javaweb电商后台管理系统源码+项目文档+汇报PPT一体化实践课程设计javaweb电商后台管理系统源码+项目文档+汇报PPT一体化实践课程设计javaweb电商后台管理系统源码+项目文档+汇报PPT一体化实践课程设计javaweb电商后台管理系统源码+项目文档+汇报PPT一体化实践课程设计javaweb电商后台管理系统源码+项目文档+汇报PPT一体化实践课程设计javaweb电商后台管理系统源码+项目文档+汇报PPT一体化实践课程设计javaweb电商后台管理系统源码+项目文档+汇报PPT一体化实践课程设计javaweb电商后台管理系统源码+项目文档+汇报PPT一体化实践课程设计javaweb电商后台管理系统源码+项目文档+汇报PPT
资源推荐
资源详情
资源评论
收起资源包目录
一体化实践课程设计.zip (62个子文件)
javaweb-master
src
main
resources
log4j.properties 324B
java
com
bean
OrderBean.java 934B
UserBean.java 838B
GoodsBean.java 2KB
pageBean.java 702B
dao
UserSelect.java 770B
UserListDao.java 2KB
UserChange.java 525B
OrderDelete.java 511B
OrderChange.java 1KB
OrderListDao.java 2KB
GoodsListDao.java 2KB
UserAdd.java 655B
GoodsDelete.java 457B
OrderAdd.java 694B
GoodsAdd.java 842B
userDelete.java 520B
MysqlLoginDao.java 762B
servlet
deleteUser.java 1KB
goods.java 5KB
orders.java 4KB
orderchange.java 3KB
deleteOrder.java 1KB
users.java 6KB
loginTest.java 2KB
service
LoginServiceMysql.java 471B
UserService.java 629B
GoodsListService.java 1KB
UserListService.java 1KB
GoodsService.java 436B
OrderListService.java 1KB
OrderService.java 613B
util
JsonConvert.java 731B
TokenUtils.java 2KB
JDBCConnect.java 1KB
webapp
css
app.4afbde5f.css 2KB
chunk-vendors.a16c4353.css 210KB
vue
components
users.vue 15KB
welcome.vue 751B
add.vue 6KB
order.vue 15KB
data.vue 2KB
login.vue 7KB
home.vue 7KB
List.vue 6KB
main.js 783B
router
index.js 1KB
App.vue 321B
plugins
element.js 1KB
assets
css
global.css 336B
img.png 6KB
logo.png 7KB
fonts
element-icons.732389de.ttf 55KB
element-icons.535877f5.woff 28KB
img
img.e0591e60.png 6KB
js
chunk-vendors.174b277f.js.map 9.66MB
app.925081d8.js 36KB
chunk-vendors.174b277f.js 1.94MB
app.925081d8.js.map 137KB
index.html 883B
favicon.ico 4KB
第五组 梁宇恒 电商后台管理系统.zip 62.12MB
共 62 条
- 1
程序员张小妍
- 粉丝: 1w+
- 资源: 3474
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页