基于javaweb+mysql的jsp+servlet二手自行车商城系统(java+jsp+bootstrap+servlet+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的JSP+Servlet二手自行车商城系统(java+jsp+bootstrap+servlet+mysql)
项目介绍
本项目分为前后台,分为管理员与普通用户两种角色,管理员登录后台,普通用户登录前台;
用户角色包含以下功能:
用户登录,修改个人信息,查看首页,查看商品详情,加入购物车,提交订单,查看我的订单等功能。
管理员角色包含以下功能:
管理员登录,订单管理,客户信息管理,二手自行车管理,类目管理等功能。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.数据库:MySql 5.7版本; 6.是否Maven项目:否;
技术栈
JSP+CSS+jQuery+bootstrap+mysql+servlet
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中src/utils/DBUtil.java配置文件中的数据库配置改为自己的配置; 4. 运行项目,输入localhost:8080/jsp_ershou_zxc/ 登录 注:tomcat中配置项目路径必须为jsp_ershou_zxc,否则会有异常; 用户账号/密码:user/123456 管理员账号/密码:admin/admin
String filePath = "/statics/image/photos/" + user.getId();
String pathRoot = fileCheck.checkGoodFolderExist(filePath);
String fileName = user.getId()
+ randomString.getRandomString(10);
String contentType = photo.getContentType();
String imageName = contentType.substring(contentType
.indexOf("/") + 1);
String name = fileName + "." + imageName;
photo.transferTo(new File(pathRoot + name));
String photoUrl = filePath + "/" + name;
user.setPhotoUrl(photoUrl);
} else {
public class GoodController {
private final GoodService goodService;
private final TypeService typeService;
private final ReviewService reviewService;
private final UserService userService;
private final ImageService imageService;
private final CollectService collectService;
private static String message = "";
@Autowired
public GoodController(GoodService goodService, TypeService typeService,
ReviewService reviewService, UserService userService,
ImageService imageService, CollectService collectService) {
this.goodService = goodService;
image.setName(name);
image.setUrl(filePath + "/" + name);
imageService.insertImage(image);
} else {
System.out.println("文件为空!");
return "redirect:/goods/goodInfo?goodId=" + goodId;
@RequestMapping(value = "/goods/userGoods", method = RequestMethod.GET)
public String getUserGoods(ModelMap model,
@RequestParam(value = "userId", required = false) Integer userId) {
User user = userService.getUserById(userId);
List<Good> userGoods = goodService.getGoodStatusByUserId(userId);
List<Good> goods = goodService.getAllGoods(0, 4);
model.addAttribute("user", user);
.getNewPassword() + code).getBytes());
Boolean success = userService.updatePassword(md5Pass, code,
password.getUserId());
if (success) {
return ResponseEntity.ok(true);
} else {
return ResponseEntity.ok("密码修改失败!");
} else {
return ResponseEntity.ok("原密码输入不正确!");
商品管理控制层:
if (replyId != null) {
if (reviewService.updateReplyStatus(1, replyId) == 1) {
Integer goodId = reviewService.getGoodIdByReviewId(reviewId);
return "redirect:/goods/goodInfo?goodId=" + goodId;
return "redirect:/user/userProfile";
@RequestMapping(value = "/userEdit", method = RequestMethod.GET)
public String getUserEdit(ModelMap model,
@RequestParam(value = "userId", required = false) Integer userId,
HttpSession session) {
User sessionUser = (User) session.getAttribute("user");
if (sessionUser == null) {
return "redirect:/";
User user = userService.getUserById(userId);
List<Order> sellGoods = orderService.getOrderBySellerId(user.getId());
good.setPhotoUrl("/statics/image/goods/default/nophoto.png");
if (goodService.insertGood(good) != 1) {
System.out.println("插入物品失败!");
model.addAttribute("goods", goods);
model.addAttribute("good", good);
model.addAttribute("firstTypes", firstTypes);
return "goods/publishGood";
@RequestMapping(value = "/goods/publishGood/uploadImage", method = RequestMethod.POST)
public String uploadImage(
HttpSession session,
@RequestParam(value = "goodId", required = false) Integer goodId,
password.getUserId());
if (success) {
return ResponseEntity.ok(true);
} else {
return ResponseEntity.ok("密码修改失败!");
} else {
return ResponseEntity.ok("原密码输入不正确!");
商品管理控制层:
@Controller
public class GoodController {
private final GoodService goodService;
private final TypeService typeService;
@RequestMapping(value = "/", method = RequestMethod.GET)
public String getHomeGoods(
ModelMap model,
@RequestParam(required = false, defaultValue = "") String searchText,
@RequestParam(required = false) Integer secondTypeId,
@RequestParam(required = false, defaultValue = "0") int offset,
@RequestParam(required = false, defaultValue = "40") int limit) {
List<Good> goods = goodService.getGoodsBySearchAndType(searchText,
secondTypeId, offset, limit);
double goodsNum = goodService.getGoodsBySearchAndTypeCount(searchText,
secondTypeId);
List<FirstType> firstTypes = typeService.getAllFirstType();
for (FirstType firstType : firstTypes) {
@RequestMapping(value = "userProfile", method = RequestMethod.GET)
public String getMyProfile(ModelMap model, HttpSession session) {
User user = (User) session.getAttribute("user");
if (user == null) {
return "redirect:/";
List<Collect> collects = collectService
.getCollectByUserId(user.getId());
for (Collect collect : collects) {
collect.setGood(goodService.getGoodById(collect.getGoodId()));
List<Good> goods = goodService.getGoodByUserId(user.getId());
List<Order> orders = orderService.getOrderByCustomerId(user.getId());
String pathRoot = fileCheck.checkGoodFolderExist(filePath);
String name;
if (!mainFile.isEmpty()) {
String contentType = mainFile.getContentType();
String fileName = goodId + randomString.getRandomString(10);
String imageName = contentType
.substring(contentType.indexOf("/") + 1);
name = fileName + "." + imageName;
mainFile.transferTo(new File(pathRoot + name));
String photoUrl = filePath + "/" + name;
goodService.updateGoodPhotoUrl(photoUrl, goodId);
.getNewPassword() + code).getBytes());
Boolean success = userService.updatePassword(md5Pass, code,
password.getUserId());
if (success) {
return ResponseEntity.ok(true);
} else {
return ResponseEntity.ok("密码修改失败!");
} else {
return ResponseEntity.ok("原密码输入不正确!");
商品管理控制层:
@Controller
public class GoodController {
private final GoodService goodService;
return "redirect:/user/userProfile";
} else {
status = "修改失败!";
model.addAttribute("user", user);
model.addAttribute("status", status);
return "user/userEdit";
System.out.println(user.getMobile());
System.out.println(status);
model.addAttribute("user", user);
model.addAttribute("status", status);
return "user/userEdit";
@RequestMapping(value = "/password/edit", method = RequestMethod.POST)
public ResponseEntity editPassword(@RequestBody Password password) {
return "goods/error";
Integer collect = 1;
User user = (User) httpSession.getAttribute("user");
if (user == null) {
collect = 0;
} else {
if (collectService.getCollect(goodId, user.getId())) {
collect = 2;
List<Image> images = imageService.getImageByGoodId(goodId);
User goodUser = userService.getUserById(goodInfo.getUserId());
goodInfo.setGoodUser(userService.getUserById(goodInfo.getUserId()));
goodInfo.setGoodSecondType(typeService.getSecondTypeById(goodInfo
if (reviewService.insertReply(reply) == 1) {
message = "回复成功!";
return "redirect:/goods/goodInfo?goodId=" + goodId;
} else {
message = "回复失败!";
return "redirect:/goods/goodInfo?goodId=" + goodId;
} else {
Review review = new Review();
review.setGoodId(goodId);
review.setFromUser(fromUser);
review.setFromUserId(fromUserId);
review.setToUserId(toUserId);
review.setText(reviewText);
if (collectService.getCollect(goodId, user.getId())) {
collect = 2;
List<Image> images = imageService.getImageByGoodId(goodId);
User goodUser = userService.getUserById(goodInfo.getUserId());
goodInfo.setGoodUser(userService.getUserById(goodInfo.getUserId()));
goodInfo.setGoodSecondType(typeService.getSecondTypeById(goodInfo
.getSecondTypeId()));
List<Review> reviews = reviewService.gerReviewByGoodId(goodId);
for (Review review : reviews) {
review.setReplys(reviewService.gerReplyByReviewId(review.getId()));
List<Good> goods = goodService.getRECGoods(goodInfo.getSecondTypeId(),
goodInfo.getId());
CollectService collectService) {
this.goodService = goodService;
this.orderService = orderService;
this.reviewService = reviewService;
this.userService = userService;
this.collectService = collectService;
@RequestMapping(value = "userProfile", method = RequestMethod.GET)
public String getMyProfile(ModelMap model, HttpSession session) {
User user = (User) session.getAttribute("user");
if (user == null) {
return "redirect:/";
System.out.println("reviewId" + reviewId);
if (reviewService.updateReviewStatus(1, reviewId) == 1) {
return "redirect:/goods/goodInfo?goodId=" + goodId;
return "redirect:/user/userProfile";
@RequestMapping(value = "/reply", method = RequestMethod.GET)
public String getReplyInfo(
@RequestParam(required = false) Integer reviewId,
@RequestParam(required = false) Integer replyId) {
if (replyId != null) {
if (reviewService.updateReplyStatus(1, replyId) == 1) {