基于javaweb+mysql的ssm二手交易平台二手商城二手物品(前台、后台)(java+ssm+javabean+jsp+ssm+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
前台用户:注册、登录、个人信息修改、查询商品、发布和修改商品、收藏、购买、评价等……
后台管理员:登录、分类管理、物品管理、订单管理、用户管理等……
前台用户:
后台管理员:
技术框架
JavaBean MVC JSP SSM(Spring SpringMVC MyBatis) MySQL JavaScript CSS Bootstrap……
基于javaweb+mysql的SSM二手交易平台二手商城二手物品(前台、后台)(java+ssm+javabean+jsp+ssm+mysql)
@Controller
public class HomeController {
private final UserService userService;
@Autowired
public HomeController(UserService userService) {
this.userService = userService;
}
@RequestMapping(value = "/login", method = RequestMethod.GET)
public String loginPage(ModelMap mode, HttpServletRequest request) {
String preURL = request.getHeader("Referer");
mode.addAttribute("preURL", preURL);
return "home/login";
}
@RequestMapping(value = "/login", method = RequestMethod.POST)
public String loginSubmit(
ModelMap model,
@RequestParam(value = "preURL", required = false, defaultValue = "") String preURL,
@RequestParam(value = "email", required = false) String email,
@RequestParam(value = "password", required = false) String password,
HttpSession session) {
User user = userService.getUserByEmail(email);
String message;
if (user != null) {
String mdsPass = password;
if (!mdsPass.equals(user.getPassword())) {
message = "用户密码错误!";
} else {
public ResponseEntity updateUserStatus(@PathVariable Integer statusId,
@PathVariable Integer userId){
Boolean success = userService.updateUserStatus(statusId, userId);
if (success){
List<User> 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<User> userList = userService.getAllUser();
return ResponseEntity.ok(userList);
}
return ResponseEntity.ok(success);
}
}
@Controller
public class OrderController {
private final GoodService goodService;
private final OrderService orderService;
@Autowired
public OrderController(GoodService goodService, OrderService orderService) {
@Controller
public class HomeController {
private final UserService userService;
@Autowired
public HomeController(UserService userService) {
this.userService = userService;
}
@RequestMapping(value = "/login", method = RequestMethod.GET)
public String loginPage(ModelMap mode, HttpServletRequest request) {
String preURL = request.getHeader("Referer");
mode.addAttribute("preURL", preURL);
return "home/login";
}
@RequestMapping(value = "/login", method = RequestMethod.POST)
public String loginSubmit(
ModelMap model,
@RequestParam(value = "preURL", required = false, defaultValue = "") String preURL,
@RequestParam(value = "email", required = false) String email,
@RequestParam(value = "password", required = false) String password,
HttpSession session) {
User user = userService.getUserByEmail(email);
String message;
if (user != null) {
String mdsPass = password;
if (!mdsPass.equals(user.getPassword())) {
message = "用户密码错误!";
} else {
if (user.getStatusId() == 4) {
session.setAttribute("user", user);
if (preURL.equals("")) {
return "redirect:/";
} else {
@RequestParam(required = false) Integer reviewId,
@RequestParam(required = false) Integer replyId) {
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());
List<Review> reviews = reviewService.gerReviewByToUserId(user.getId());
List<Reply> replies = reviewService.gerReplyByToUserId(user.getId());
model.addAttribute("user", user);
model.addAttribute("sellGoods", sellGoods);
model.addAttribute("reviews", reviews);
model.addAttribute("replies", replies);
return "user/userEdit";
}
@RequestMapping(value = "/userEdit", method = RequestMethod.POST)
public String postUserEdit(ModelMap model, @Valid User user,
HttpSession session,
@RequestParam(value = "photo", required = false) MultipartFile photo)
throws IOException {
String status;
Boolean insertSuccess;
User sessionUser = (User) session.getAttribute("user");
user.setId(sessionUser.getId());
InfoCheck infoCheck = new InfoCheck();
if (!infoCheck.isMobile(user.getMobile())) {
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<Order> 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<Order> orders = orderService.getOtherOrderBySellerId(
sessionUser.getId(), orderId);
model.addAttribute("orderInfo", orderInfo);
model.addAttribute("orders", orders);
System.out.println("sellerInfo.size:" + orders.size());
return "user/sellerInfo";
}
@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 = session.getServletContext().getRealPath(filePath);
File pathRootFile = new File(pathRoot);
//创建目录
if(!pathRootFile.exists()) {
pathRootFile.mkdirs();
}
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) {
model.addAttribute("orders", orders);
model.addAttribute("reviews", reviews);
model.addAttribute("replies", replies);
model.addAttribute("sellGoods", sellGoods);
return "user/userProfile";
}
@RequestMapping(value = "/review", method = RequestMethod.GET)
public String getReviewInfo(@RequestParam(required = false) Integer goodId,
@RequestParam(required = false) Integer reviewId) {
System.out.println("reviewId" + reviewId);
if (reviewId != null) {
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) {
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());
List<Review> reviews = reviewService.gerReviewByToUserId(user.getId());
List<Reply> replies = reviewService.gerReplyByToUserId(user.getId());
model.addAttribute("user", user);
model.addAttribute("sellGoods", sellGoods);
model.addAttribute("reviews", reviews);
model.addAttribute("replies", replies);
return "user/userEdit";
}
@RequestMapping(value = "/userEdit", method = RequestMethod.POST)
public String postUserEdit(ModelMap model, @Valid User user,
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());
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 {
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<Order> 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);
.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());
List<Review> reviews = reviewService.gerReviewByToUserId(user.getId());
List<Reply> replies = reviewService.gerReplyByToUserId(user.getId());
List<Order> sellGoods = orderService.getOrderBySellerId(user.getId());
model.addAttribute("collects", collects);
model.addAttribute("goods", goods);
model.addAttribute("orders", orders);
model.addAttribute("reviews", reviews);
model.addAttribute("replies", replies);
model.addAttribute("sellGoods", sellGoods);
return "user/userProfile";
}
@RequestMapping(value = "/review", method = RequestMethod.GET)
public String getReviewInfo(@RequestParam(required = false) Integer goodId,
@RequestParam(required = false) Integer reviewId) {
System.out.println("reviewId" + reviewId);
if (reviewId != null) {
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) {
Integer goodId = reviewService.getGoodIdByReviewId(reviewId);
return "redirect:/goods/goodInfo?goodId=" + goodId;
}
}
return "redirect:/user/userProfile";
}
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 = session.getServletContext().getRealPath(filePath);
File pathRootFile = new File(pathRoot);
//创建目录
if(!pathRootFile.exists()) {
pathRootFile.mkdirs();
}
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);
.getId() + " " + user.getId());
status = "此手机号码已使用!";
} else if (userService.getUserByEmail(user.getEmail()).getId() != user
.getId()) {
status = "此邮箱已使用!";
} else {
if (!photo.isEmpty()) {
RandomString randomString = new RandomString();
FileCheck fileCheck = new FileCheck();
String filePath = "/statics/image/photos/";
String pathRoot = session.getServletContext().getRealPath(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 {
String photoUrl = userService.getUserById(user.getId())
.getPhotoUrl();
user.setPhotoUrl(photoUrl);
}
insertSuccess = userService.updateUser(user);
if (insertSuccess) {
session.removeAttribute("user");
session.setAttribute("user", user);
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) {
User user = userService.getUserById(password.getUserId());
String oldPass = DigestUtils
.md5DigestAsHex((password.getOldPassword() + user.getCode())
@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<Good> goods = goodService.getGoodsBySearchAndType(searchText,
secondTypeId, offset, limit);
double goodsNum = goodService.getGoodsBySearchAndTypeCount(searchText,
secondTypeId);
List<FirstType> 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);
if (success) {
List<FirstType> firstTypeList = typeService.getAllFirstType();
if (firstTypeList == null) {
return ResponseEntity.ok("isNull");
}
return ResponseEntity.ok(firstTypeList);
}
}
return ResponseEntity.ok(success);
}
@RequestMapping(value = "/secondType/create", method = RequestMethod.POST)
public ResponseEntity createSecondType(@RequestBody SecondType secondType) {
Integer thisFirstTypeId = secondType.getFirstTypeId();
Boolean success = typeService.createSecondType(secondType);
if (success) {
List<SecondType> secondTypeList = typeService
.getSecondTypeByFirstTypeId(thisFirstTypeId);
return ResponseEntity.ok(secondTypeList);
}
return ResponseEntity.ok(success);
}
@RequestMapping(value = "/firstType/create", method = RequestMethod.POST)
public ResponseEntity createSecondType(@RequestBody FirstType firstType) {
Boolean success = typeService.createFirstType(firstType);
if (success) {
List<FirstType> firstTypeList = typeService.getAllFirstType();
return ResponseEntity.ok(firstTypeList);
}
return ResponseEntity.ok(success);
}
}
@Controller
@RequestMapping(value = "/collect")
public class CollectController {
@RequestMapping(value = "/collect")
public class CollectController {
private final CollectService collectService;
private final GoodService goodService;
@Autowired
public CollectController(CollectService collectService, GoodService goodService) {
this.collectService = collectService;
this.goodService = goodService;
}
@RequestMapping(value = "/insert", method = RequestMethod.POST)
public ResponseEntity insertCollect(@RequestBody Collect collect){
return ResponseEntity.ok(collectService.insertCollect(collect));
}
@RequestMapping(value = "/delete/{collectId}&{userId}", method = RequestMethod.GET)
public ResponseEntity deleteCollect(@PathVariable Integer collectId,
@PathVariable Integer userId){
Boolean success = collectService.deleteCollect(collectId);
if (success){
List<Collect> collects = collectService.getCollectByUserId(userId);
for (Collect collect : collects){
collect.setGood(goodService.getGoodById(collect.getGoodId()));
}
return ResponseEntity.ok(collects);
}
return ResponseEntity.ok(success);
}
}
public class ExceptionHandler implements HandlerExceptionResolver {
@Override
public ModelAndView resolveException(HttpServletRequest request,
HttpServletResponse response, Object handler, Exception ex) {
ex.printStackTrace();
System.out.println();
try {
request.getRequestDispatcher("/WEB-INF/views/home/error.jsp")
.forward(request, response);
} catch (ServletException e) {
e.printStackTrace();
return "redirect:/";
}
User user = userService.getUserById(userId);
List<Order> sellGoods = orderService.getOrderBySellerId(user.getId());
List<Review> reviews = reviewService.gerReviewByToUserId(user.getId());
List<Reply> replies = reviewService.gerReplyByToUserId(user.getId());
model.addAttribute("user", user);
model.addAttribute("sellGoods", sellGoods);
model.addAttribute("reviews", reviews);
model.addAttribute("replies", replies);
return "user/userEdit";
}
@RequestMapping(value = "/userEdit", method = RequestMethod.POST)
public String postUserEdit(ModelMap model, @Valid User user,
HttpSession session,
@RequestParam(value = "photo", required = false) MultipartFile photo)
throws IOException {
String status;
Boolean insertSuccess;
User sessionUser = (User) session.getAttribute("user");
user.setId(sessionUser.getId());
InfoCheck infoCheck = new InfoCheck();
if (!infoCheck.isMobile(user.getMobile())) {
status = "请输入正确的手机号!";
} else if (!infoCheck.isEmail(user.getEmail())) {
status = "请输入正确的邮箱!";
} else if (userService.getUserByMobile(user.getMobile()).getId() != user
.getId()) {
System.out.println(userService.getUserByMobile(user.getMobile())
.getId() + " " + user.getId());
status = "此手机号码已使用!";
} else if (userService.getUserByEmail(user.getEmail()).getId() != user
.getId()) {
status = "此邮箱已使用!";
} else {
if (!photo.isEmpty()) {
RandomString randomString = new RandomString();
FileCheck fileCheck = new FileCheck();
String filePath = "/statics/image/photos/";
String pathRoot = session.getServletContext().getRealPath(filePath);
@RequestMapping(value = "/firstType/create", method = RequestMethod.POST)
public ResponseEntity createSecondType(@RequestBody FirstType firstType) {
Boolean success = typeService.createFirstType(firstType);
if (success) {
List<FirstType> firstTypeList = typeService.getAllFirstType();
return ResponseEntity.ok(firstTypeList);
}
return ResponseEntity.ok(success);
}
}
@Controller
@RequestMapping(value = "/collect")
public class CollectController {
private final CollectService collectService;
private final GoodService goodService;
@Autowired
public CollectController(CollectService collectService, GoodService goodService) {
this.collectService = collectService;
this.goodService = goodService;
}
@RequestMapping(value = "/insert", method = RequestMethod.POST)
public ResponseEntity insertCollect(@RequestBody Collect collect){
return ResponseEntity.ok(collectService.insertCollect(collect));
}
@RequestMapping(value = "/delete/{collectId}&{userId}", method = RequestMethod.GET)
public ResponseEntity deleteCollect(@PathVariable Integer collectId,
@PathVariable Integer userId){
Boolean success = collectService.deleteCollect(collectId);
if (success){
List<Collect> collects = collectService.getCollectByUserId(userId);
for (Collect collect : collects){
collect.setGood(goodService.getGoodById(collect.getGoodId()));
}