package com.shop.servlet;
import com.shop.entity.User;
import com.shop.utils.DBUtils;
import com.shop.utils.GsonUtil;
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.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@WebServlet(urlPatterns = "/car")
public class CarServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
resp.setCharacterEncoding("UTF-8");
String method = req.getParameter("method");
if ("update".equals(method)) {
update(req, resp);
} else if ("list".equals(method)) {
list(req, resp);
}
}
private void update(HttpServletRequest request, HttpServletResponse response) {
String idStr = request.getParameter("id");
Integer id = null;
if (idStr != null && !"".equals(idStr)) {
id = Integer.valueOf(idStr);
}
String shopName = request.getParameter("shopName");
BigDecimal price = null;
if (request.getParameter("price")!= null) {
price = new BigDecimal(request.getParameter("price"));
}
String shuliang = request.getParameter("shuliang");
String img = request.getParameter("img");
// 更新
if (id != null) {
DBUtils.executeUpdate("update car set shuliang = ? where id = ?", Arrays.asList(shuliang, id));
DBUtils.executeUpdate("delete from car where shuliang = 0", new ArrayList<>());
try {
response.getWriter().write("success");
} catch (IOException e) {
e.printStackTrace();
}
} else {
Integer userId = Integer.valueOf(request.getParameter("userId"));
List<Map<String, Object>> maps = DBUtils.executeQuery("select * from car where shopName = ? and userId = ?",
Arrays.asList(shopName, userId));
if (maps != null && maps.size() > 0) {
DBUtils.executeUpdate("update car set shuliang = shuliang + 1 where userId = ? and shopName = ?", Arrays.asList(userId, shopName));
} else {
DBUtils.executeUpdate("insert into car(shopName, price, shuliang, img, userId) value(?,?,?,?,?)",
Arrays.asList(shopName, price, shuliang, img, userId));
try {
response.getWriter().write("success");
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
private void list(HttpServletRequest request, HttpServletResponse response) {
Integer userId = Integer.valueOf(request.getParameter("userId"));
List<Map<String, Object>> maps = DBUtils.executeQuery("select * from car where userId = ?", Arrays.asList(userId));
try {
response.getWriter().write(GsonUtil.getResponseString(maps));
} catch (IOException e) {
e.printStackTrace();
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Javaweb期末大作业游戏购物网站
共85个文件
jpg:37个
class:7个
java:7个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 158 浏览量
2024-05-21
21:57:09
上传
评论
收藏 53.07MB RAR 举报
温馨提示
Javaweb期末大作业游戏购物网站
资源推荐
资源详情
资源评论
收起资源包目录
Javaweb期末大作业游戏购物网站.rar (85个子文件)
Javaweb期末大作业游戏购物网站
shop2-front
jQuery
jquery-3.6.0.min.js 87KB
留言板.html 6KB
个人中心.css 2KB
注册.html 3KB
.idea
shop2-front.iml 344B
workspace.xml 3KB
misc.xml 177B
modules.xml 281B
.gitignore 250B
img
特别优惠
图片4.jpg 32KB
图片3.jpg 41KB
图片1.jpg 159KB
图片2.jpg 161KB
付款码.png 82KB
只狼:影逝二度
只狼4.jpg 402KB
只狼3.jpg 1.01MB
只狼2.jpg 915KB
只狼1.jpg 93KB
视频.webm 43.33MB
游戏分类
动作
2.jpg 15KB
1.jpg 15KB
3.jpg 16KB
4.jpg 25KB
生存
2.jpg 27KB
1.jpg 24KB
3.jpg 13KB
4.jpg 25KB
冒险
2.jpg 24KB
1.jpg 20KB
3.jpg 27KB
4.jpg 13KB
模拟
2.jpg 16KB
1.jpg 17KB
3.jpg 19KB
4.jpg 24KB
刺客信条:英灵殿
英灵殿4.jpg 216KB
英灵殿1.jpg 70KB
英灵殿3.jpg 340KB
英灵殿2.jpg 282KB
头像.jpg 20KB
荒野大镖客
大镖客3.jpg 58KB
大镖客2.jpg 30KB
大镖客4.jpg 56KB
大镖客1.jpg 204KB
尼尔:机械纪元
尼尔1.jpg 442KB
尼尔2.jpg 532KB
尼尔3.jpg 182KB
尼尔4.jpg 305KB
个人中心.html 4KB
购物车.css 2KB
主页.css 3KB
购物车.html 9KB
登录.css 2KB
主页.html 17KB
登录.html 3KB
留言板.css 2KB
shop.sql 2KB
shop
.classpath 727B
.settings
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.jdt.core.prefs 364B
.jsdtscope 567B
org.eclipse.wst.common.component 464B
org.eclipse.wst.common.project.facet.core.xml 305B
org.eclipse.wst.jsdt.ui.superType.container 49B
src
jdbc.properties 168B
com
shop
servlet
UserServlet.java 3KB
CarServlet.java 3KB
utils
GsonUtil.java 390B
DBUtils.java 2KB
filter
CrossOrignFilter.java 1KB
entity
Car.java 1KB
User.java 2KB
build
classes
jdbc.properties 168B
com
shop
servlet
CarServlet.class 3KB
UserServlet.class 3KB
utils
GsonUtil.class 886B
DBUtils.class 3KB
filter
CrossOrignFilter.class 2KB
entity
User.class 2KB
Car.class 2KB
WebContent
WEB-INF
lib
mysql-connector-java-8.0.16.jar 2.19MB
gson-2.8.5.jar 236KB
druid-1.1.0.jar 2.16MB
META-INF
MANIFEST.MF 39B
.project 904B
共 85 条
- 1
资源评论
a辰龙a
- 粉丝: 2819
- 资源: 59
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功