基于javaweb的校园二手市场系统(java+ssm+mysql+tomcat)

基于javaweb的校园二手市场系统(java+ssm+mysql+tomcat)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

20220519001546

20220519001548

20220519001549

20220519001550

20220519001551

20220519001552

基于javaweb的校园二手市场系统(java+SSM+mysql+maven+tomcat)

一、项目简述( +IW文档)

功能:本系统分用户前台和管理员后台。 本系统用例模型有三种,分别是游客、注册用户和系统管 理员。下面分别对这三个角色的功能进行描述: 1) 诞 游客是未注册的用户,他们可以浏览物物品,可以搜索物 品,如需购买物品,必须先注册成为网站用户。游客主要 功触吓: a.浏览物品 b.搜索物品 c.注册成为网站用户 2) 注册用户 注册用户是经过网站合法认证的用户,登录网站后可以浏 览物品、搜索物品、发布物品、关注物品、购买物品和查 看个人中心。 3) 系统管理员 系统管理员主要负责系统的后台管理工作,主要功能如 下: 用户管理,商品管理等等。

二、项目运行

环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe ( IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)

项目技术: JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等。

管理员控制层:

@Controller

@RequestMapping(value = “admin”)

public class AdminController {

private final UserService userService;

private final GoodService goodService;

private final TypeService typeService;

private final OrderService orderService;

@Autowired

public AdminController(UserService userService, GoodService goodService, TypeService typeService, OrderService orderService) {

this.userService = userService;

this.goodService = goodService;

this.typeService = typeService;

this.orderService = orderService;

@RequestMapping(value = “/adminLogin”, method = RequestMethod.GET)

public String getAdminLogin(){

return “admin/adminLogin”;

@RequestMapping(value = “/adminLogin”, method = RequestMethod.POST)

public String postAdminLogin(ModelMap model,

@RequestParam(value = “email”, required = false) String email,

@RequestParam(value = “password”, required = false) String password,

HttpSession session) {

User admin = userService.getUserByEmail(email);

String message;

if (admin != null){

String mdsPass = DigestUtils.md5DigestAsHex((password + admin.getCode()).getBytes());

// if (!mdsPass .equals(admin.getPassword())){

// message = “用户密码错误!”;

// }

if (!password .equals(admin.getPassword())){

message = “用户密码错误!”;

} else if (admin.getRoleId() != 101){

message = “用户没有权限访问!”;

} else {

session.setAttribute(“admin”,admin);

return “redirect:/admin/adminPage”;

} else {

message = “用户不存在!”;

model.addAttribute(“message”, message);

return “admin/adminLogin”;

@RequestMapping(value = “/adminLogout”, method = RequestMethod.GET)

public String adminLogout(@RequestParam(required = false, defaultValue = “false” )String adminLogout, HttpSession session){

if (adminLogout.equals(“true”)){

session.removeAttribute(“admin”);

// adminLogout = “false”;

return “redirect:/”;

@RequestMapping(value = “/adminPage”, method = RequestMethod.GET)

public String getAdminPage(ModelMap model,

HttpSession session){

User admin = (User) session.getAttribute(“admin”);

if (admin == null){

return “redirect:/admin/adminLogin”;

List goodList = goodService.getAllGoodList();

for (Good good : goodList) {

good.setGoodUser(userService.getUserById(good.getUserId()));

good.setGoodSecondType(typeService.getSecondTypeById(good.getSecondTypeId()));

List userList = userService.getAllUser();

List firstTypeList = typeService.getAllFirstType();

List orderList = orderService.getOrderList();

model.addAttribute(“goodList”, goodList);

model.addAttribute(“userList”, userList);

model.addAttribute(“firstTypeList”, firstTypeList);

model.addAttribute(“orderList”, orderList);

return “admin/adminPage”;

@RequestMapping(value = “/user/update/status/{statusId}&{userId}”, method = RequestMethod.GET)

public ResponseEntity updateUserStatus(@PathVariable Integer statusId,

@PathVariable Integer userId){

Boolean success = userService.updateUserStatus(statusId, userId);

if (success){

List userList = userService.getAllUser();

return ResponseEntity.ok(userList);

return ResponseEntity.ok(success);

@RequestMapping(value = “/user/delete/{userId}”, method = RequestMethod.GET)

public ResponseEntity deleteUser(@PathVariable Integer userId){

Boolean success = userService.deleteUser(userId);

if (success){

List userList = userService.getAllUser();

return ResponseEntity.ok(userList);

return ResponseEntity.ok(success);

商品控制层:

@Controller

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;

this.typeService = typeService;

this.reviewService = reviewService;

this.userService = userService;

this.imageService = imageService;

this.collectService = collectService;

@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 goods = goodService.getGoodsBySearchAndType(searchText,

secondTypeId, offset, limit);

double goodsNum = goodService.getGoodsBySearchAndTypeCount(searchText,

secondTypeId);

List firstTypes = typeService.getAllFirstType();

for (FirstType firstType : firstTypes) {

firstType.setSecondType(typeService

.getSecondTypeByFirstTypeId(firstType.getId()));

model.addAttribute(“firstTypes”, firstTypes);

model.addAttribute(“goods”, goods);

model.addAttribute(“pages”, Math.ceil(goodsNum / limit));

model.addAttribute(“goodsNum”, goodsNum);

model.addAttribute(“offset”, offset);

model.addAttribute(“limit”, limit);

return “home/homeGoods”;

@RequestMapping(value = “/goods/goodInfo”, method = RequestMethod.GET)

public String getGoodInfo(ModelMap model, HttpSession httpSession,

@RequestParam(required = false) Integer goodId) {

Good goodInfo = goodService.getGoodById(goodId);

if (goodInfo == null) {

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 images = imageService.getImageByGoodId(goodId);

User goodUser = userService.getUserById(goodInfo.getUserId());

goodInfo.setGoodUser(userService.getUserById(goodInfo.getUserId()));

goodInfo.setGoodSecondType(typeService.getSecondTypeById(goodInfo

.getSecondTypeId()));

List reviews = reviewService.gerReviewByGoodId(goodId);

for (Review review : reviews) {

review.setReplys(reviewService.gerReplyByReviewId(review.getId()));

List goods = goodService.getRECGoods(goodInfo.getSecondTypeId(),

goodInfo.getId());

model.addAttribute(“message”, message);

model.addAttribute(“reviews”, reviews);

model.addAttribute(“goodInfo”, goodInfo);

model.addAttribute(“images”, images);

model.addAttribute(“goodUser”, goodUser);

model.addAttribute(“goods”, goods);

model.addAttribute(“collect”, collect);

message = “”;

return “goods/goodInfo”;

@RequestMapping(value = “/goods/goodInfo”, method = RequestMethod.POST)

public String putReview(

@RequestParam(value = “goodId”, required = false) Integer goodId,

@RequestParam(value = “reviewId”, required = false) Integer reviewId,

@RequestParam(value = “fromUserId”, required = false) Integer fromUserId,

@RequestParam(value = “toUserId”, required = false) Integer toUserId,

@RequestParam(value = “fromUser”, required = false) String fromUser,

@RequestParam(value = “toUser”, required = false) String toUser,

@RequestParam(value = “replyText”, required = false, defaultValue = “”) String replyText,

@RequestParam(value = “reviewText”, required = false, defaultValue = “”) String reviewText) {

if (reviewText.equals(“”)) {

if (replyText.equals(“”)) {

message = “内容不能为空!”;

return “redirect:/goods/goodInfo?goodId=” + goodId;

} else {

Reply reply = new Reply();

reply.setReviewId(reviewId);

reply.setFromUser(fromUser);

reply.setFromUserId(fromUserId);

reply.setToUser(toUser);

reply.setToUserId(toUserId);

reply.setText(replyText);

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 (reviewService.insertReview(review) == 1) {

message = “评论成功!”;

return “redirect:/goods/goodInfo?goodId=” + goodId;

} else {

message = “评论失败!”;

return “redirect:/goods/goodInfo?goodId=” + goodId;

@RequestMapping(value = “/goods/publishGood”, method = RequestMethod.GET)

public String getPublishGood(ModelMap model, HttpSession session) {

User user = (User) session.getAttribute(“user”);

if (user == null) {

return “redirect:/”;

Good good = new Good();

List firstTypes = typeService.getAllFirstType();

List goods = goodService.getAllGoods(0, 5);

model.addAttribute(“goods”, goods);

model.addAttribute(“good”, good);

model.addAttribute(“firstTypes”, firstTypes);

return “goods/publishGood”;

@RequestMapping(value = “/goods/publishGood”, method = RequestMethod.POST)

public String getGoodId(ModelMap model, HttpSession session,

@Valid Good good) {

List firstTypes = typeService.getAllFirstType();

User user = (User) session.getAttribute(“user”);

List goods = goodService.getAllGoods(0, 5);

good.setUserId(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,

@RequestParam(value = “mainFile”, required = false) MultipartFile mainFile,

@RequestParam(value = “file”, required = false) MultipartFile[] file)

throws IOException {

User user = (User) session.getAttribute(“user”);

FileCheck fileCheck = new FileCheck();

RandomString randomString = new RandomString();

String filePath = “/statics/image/goods/” + user.getId() + “/” + goodId;

String pathRoot = fileCheck.checkGoodFolderExist(filePath);

String name;

if (!mainFile.isEmpty()) {

String fileName = goodId + randomString.getRandomString(10);

String contentType = mainFile.getContentType();

String imageName = contentType

.substring(contentType.indexOf(“/”) + 1);

name = fileName + “.” + imageName;

mainFile.transferTo(new File(pathRoot + name));

String photoUrl = filePath + “/” + name;

goodService.updateGoodPhotoUrl(photoUrl, goodId);

for (MultipartFile mf : file) {

if (!mf.isEmpty()) {

// 生成uuid作为文件名称

String fileName = goodId + randomString.getRandomString(10);

// 获得文件类型(可以判断如果不是图片,禁止上传)

String contentType = mf.getContentType();

// 获得文件后缀名称

String imageName = contentType.substring(contentType

.indexOf(“/”) + 1);

name = fileName + “.” + imageName;

System.out.println(“name:” + name);

mf.transferTo(new File(pathRoot + name));

Image image = new Image();

image.setGoodId(goodId);

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 userGoods = goodService.getGoodStatusByUserId(userId);

List goods = goodService.getAllGoods(0, 4);

model.addAttribute(“user”, user);

model.addAttribute(“userGoods”, userGoods);

model.addAttribute(“goods”, goods);

return “goods/userGood”;

@RequestMapping(value = “/goods/userGoodEdit”, method = RequestMethod.GET)

public String getUserGoodEdit(ModelMap model,

@RequestParam(value = “goodId”, required = false) Integer goodId,

HttpSession session) {

User user = (User) session.getAttribute(“user”);

if (user == null) {

return “redirect:/”;

Good good = goodService.getGoodById(goodId);

List firstTypes = typeService.getAllFirstType();

List goods = goodService.getAllGoods(0, 5);

List goodImages = imageService.getImageByGoodId(goodId);

model.addAttribute(“goods”, goods);

model.addAttribute(“good”, good);

model.addAttribute(“goodImages”, goodImages);

model.addAttribute(“firstTypes”, firstTypes);

return “goods/userGoodEdit”;

@RequestMapping(value = “/goods/userGoodEdit”, method = RequestMethod.POST)

public String postGoodEdit(ModelMap model, HttpSession session,

@Valid Good good) {

List firstTypes = typeService.getAllFirstType();

User user = (User) session.getAttribute(“user”);

if (user == null) {

return “redirect:/”;

List goods = goodService.getAllGoods(0, 5);

if (!(goodService.updateGood(good) > 0)) {

System.out.println(“修改物品失败!”);

List goodImages = imageService.getImageByGoodId(good.getId());

model.addAttribute(“goods”, goods);

model.addAttribute(“good”, good);

model.addAttribute(“goodImages”, goodImages);

model.addAttribute(“firstTypes”, firstTypes);

return “goods/userGoodEdit”;

@RequestMapping(value = “/goods/userGoodEdit/updateImage”, method = RequestMethod.POST)

public String updateImage(

HttpSession session,

@RequestParam(value = “goodId”, required = false) Integer goodId,

@RequestParam(value = “mainFile”, required = false) MultipartFile mainFile,

@RequestParam(value = “file”, required = false) MultipartFile[] file)

throws IOException {

User user = (User) session.getAttribute(“user”);

FileCheck fileCheck = new FileCheck();

imageService.deleteImage(goodId);

RandomString randomString = new RandomString();

String filePath = “/statics/image/goods/” + user.getId() + “/” + goodId;

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);

for (MultipartFile mf : file) {

if (!mf.isEmpty()) {

String contentType = mf.getContentType();

String fileName = goodId + randomString.getRandomString(10);

String imageName = contentType.substring(contentType

.indexOf(“/”) + 1);

name = fileName + “.” + imageName;

System.out.println(“name:” + name);

mf.transferTo(new File(pathRoot + name));

Image image = new Image();

image.setGoodId(goodId);

image.setName(name);

image.setUrl(filePath + “/” + name);

imageService.insertImage(image);

return “redirect:/goods/goodInfo?goodId=” + goodId;

@RequestMapping(value = “/goods/userGoodEdit/delete/{goodId}”, method = RequestMethod.GET)

public ResponseEntity deleteGood(@PathVariable Integer goodId) {

Boolean success;

success = goodService.deleteGood(goodId) > 0;

return ResponseEntity.ok(success);

@RequestMapping(value = “/goods/userGoodEdit/updateGoodStatus/{goodId}”, method = RequestMethod.GET)

public ResponseEntity updateGoodStatus(@PathVariable Integer goodId) {

Boolean success;

success = goodService.updateGoodStatusId(0, goodId) > 0;

return ResponseEntity.ok(success);

@RequestMapping(value = “/admin/goods/allGoods”, method = RequestMethod.GET)

public ResponseEntity adminGetAllGoods() {

List goodList = goodService.getAllGoodList();

for (Good good : goodList) {

good.setGoodUser(userService.getUserById(good.getUserId()));

good.setGoodSecondType(typeService.getSecondTypeById(good

.getSecondTypeId()));

return ResponseEntity.ok(goodList);

订单控制层:

@Controller

public class OrderController {

private final GoodService goodService;

private final OrderService orderService;

@Autowired

public OrderController(GoodService goodService, OrderService orderService) {

this.goodService = goodService;

this.orderService = orderService;

@RequestMapping(value = “/user/orderInfo”, method = RequestMethod.GET)

public String getOrderInfo(ModelMap model,

@RequestParam(value = “orderId”, required = false) Integer orderId,

HttpSession session) {

User sessionUser = (User) session.getAttribute(“user”);

if (sessionUser == null) {

return “redirect:/”;

Order orderInfo = orderService.getOrderById(orderId);

List orders = orderService.getOtherOrderByCustomerId(

sessionUser.getId(), orderId);

model.addAttribute(“orderInfo”, orderInfo);

model.addAttribute(“orders”, orders);

return “user/orderInfo”;

@RequestMapping(value = “/user/sellerInfo”, method = RequestMethod.GET)

public String getSellerInfo(ModelMap model,

@RequestParam(value = “orderId”, required = false) Integer orderId,

HttpSession session) {

User sessionUser = (User) session.getAttribute(“user”);

if (sessionUser == null) {

return “redirect:/”;

Order orderInfo = orderService.getOrderById(orderId);

List orders = orderService.getOtherOrderBySellerId(

sessionUser.getId(), orderId);

model.addAttribute(“orderInfo”, orderInfo);

model.addAttribute(“orders”, orders);

System.out.println(“sellerInfo.size:” + orders.size());

return “user/sellerInfo”;

@RequestMapping(value = “/user/order/delete/{orderId}”, method = RequestMethod.GET)

public ResponseEntity deleteOrderById(@PathVariable Integer orderId) {

Boolean success;

success = orderService.deleteOrderById(orderId) > 0;

return ResponseEntity.ok(success);

@RequestMapping(value = “/user/sellerOrder/delete/{orderId}&{goodId}”, method = RequestMethod.GET)

public ResponseEntity deleteSellerOrderById(@PathVariable Integer orderId,

@PathVariable Integer goodId) {

Boolean success;

success = goodService.updateGoodStatusId(1, goodId) > 0;

if (success) {

success = orderService.deleteOrderById(orderId) > 0;

return ResponseEntity.ok(success);

@RequestMapping(value = “/user/order/update/status/{orderId}&{statusId}”, method = RequestMethod.GET)

public ResponseEntity updateOrderStatus(@PathVariable Integer orderId,

@PathVariable Integer statusId) {

Boolean success = orderService.updateStatus(statusId, orderId) > 0;

if (success) {

Order order = orderService.getOrderById(orderId);

return ResponseEntity.ok(order);

return ResponseEntity.ok(success);

@RequestMapping(value = “/user/order/create”, method = RequestMethod.POST)

public ResponseEntity createOrder(@RequestBody Order order) {

Boolean success = orderService.insertOrder(order) > 0;

if (success) {

success = goodService.updateGoodStatusId(0, order.getGoodId()) > 0;

if (success) {

return ResponseEntity.ok(order.getId());

} else {

orderService.deleteOrderById(order.getId());

return ResponseEntity.ok(success);

return ResponseEntity.ok(success);

@RequestMapping(value = “/user/order/allOrder”, method = RequestMethod.GET)

public ResponseEntity getAllOrders() {

List orderList = orderService.getOrderList();

return ResponseEntity.ok(orderList);


系统主要面向于大学校园网用户,依托校园网提供给这些用户一个发布和交流二手商品信息的平台。在大学校园里,存在着很多的二手商品,但是由于信息资源的不流通以及传统二手商品信息交流方式的笨拙,导致了很多仍然具有一定价值或者具有非常价值的二手商品的囤积,乃至被当作废弃物处理。现在通过校园网进入到本系统,可以方便快捷的发布和交流任何二手商品的信息,并且可以通过留言方式进行深一步的交流。由于每个大学的校园网都基本篇布校园的每一个地方,因此,只要宣传得当,理论上来说,每一个人都可以让他所发布的信息让全校所了解,争取到了信息资源的最大化利用。 系统完成的主要功能有:用户设置功能、发布信息功能、信息管理功能、搜索信息功能,留言功能,及系统管理功能,具体业务功能包括如下: 用户注册:学生可利用自已学号进行注册,注册实现实名制。 用户登录:只有登录用户才能进行信息发布。管理员登录后可以进行系统管理。 发布信息:普通用户和管理员登录后都可以发布信息。 修改信息:普通用户可以修改自己发布的信息,管理员可以修改所有信息。 删除信息:普通用户可以删除自己发布的信息,管理员可以删除所有信息。 浏览信息:游客、普通用户和管理员可以浏览所有发布的信息。 搜索信息:游客、普通用户和管理员可以用关键字搜索所有发布的信息。普通用户可以搜索自己发布的所有信息。 发表留言:普通用户和管理员登录后都可以对发布信息进行留言。 查看留言:游客、普通用户和管理员都可以查看发布信息的留言。 删除留言:管理员可以删除留言。 添加二手指南:管理员可以添加二手指南。 查看二手指南:游客、普通用户和管理员都可以查看二手指南。 修改二手指南:管理员可以修改二手指南。 删除二手指南:管理员可以删除二手指南。 3.1.2 系统界面要求 由于系统主要面向大学生,系统界面要求不能过古板,要能体现大学校园的自由,创新。系统界面设计应体现人性化,界面清晰简捷,操作简单流畅,提高管理效果。不需要任何专业培训,不需要配备专门的电脑操作人员,无电脑知识一样运用自如。关键在于系统的框架式设计简单明晰。 3.2 概要设计 3.2.1 系统体系结构设计 本系统是一个典型的三层应用——浏览器通过Web服务器实现对数据库的各种操作。图3-1 展示了整个系统的体系结构。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值