• SSM二手交易网站


    作者主页:夜未央5788

     简介:Java领域优质创作者、Java项目、学习资料、技术互助

    文末获取源码

    项目介绍

    该项目分为前后台,前台普通用户角色,后台管理员角色。

    管理员主要功能如下:
    登陆,商品分类管理,商品管理,商品订单管理,用户管理等功能。

    用户角色主要功能如下:

    包含以下功能:查看所有商品,用户登陆注册,按照类别查看商品,发布商品,查看卖家主页,联系卖家,给商品留言,查看订单,修改查看个人资料等功能。

    环境需要

    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项目:是;

    技术栈

    1. 后端:Spring+SpringMVC+Mybatis

    2. 前端:JSP+BootStrap+jQuery

    使用说明

    1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;

    2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;

    若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;

    3. 将项目中mybatis.xml配置文件中的数据库配置改为自己的配置;

    4. 运行项目,输入localhost:8080/ssm_ershou_shop 登录

    运行截图

    前台界面

     

     

     

     

     

     

    后台界面

     

     

     

     

    相关代码

     管理员控制器

    1. @Controller
    2. @RequestMapping(value = "admin")
    3. public class AdminController {
    4. private final UserService userService;
    5. private final GoodService goodService;
    6. private final TypeService typeService;
    7. private final OrderService orderService;
    8. @Autowired
    9. public AdminController(UserService userService, GoodService goodService, TypeService typeService, OrderService orderService) {
    10. this.userService = userService;
    11. this.goodService = goodService;
    12. this.typeService = typeService;
    13. this.orderService = orderService;
    14. }
    15. @RequestMapping(value = "/adminLogin", method = RequestMethod.GET)
    16. public String getAdminLogin(){
    17. return "admin/adminLogin";
    18. }
    19. @RequestMapping(value = "/adminLogin", method = RequestMethod.POST)
    20. public String postAdminLogin(ModelMap model,
    21. @RequestParam(value = "email", required = false) String email,
    22. @RequestParam(value = "password", required = false) String password,
    23. HttpSession session) {
    24. User admin = userService.getUserByEmail(email);
    25. String message;
    26. if (admin != null){
    27. String mdsPass = DigestUtils.md5DigestAsHex((password + admin.getCode()).getBytes());
    28. // if (!mdsPass .equals(admin.getPassword())){
    29. // message = "用户密码错误!";
    30. // }
    31. if (!password .equals(admin.getPassword())){
    32. message = "用户密码错误!";
    33. } else if (admin.getRoleId() != 101){
    34. message = "用户没有权限访问!";
    35. } else {
    36. session.setAttribute("admin",admin);
    37. return "redirect:/admin/adminPage";
    38. }
    39. } else {
    40. message = "用户不存在!";
    41. }
    42. model.addAttribute("message", message);
    43. return "admin/adminLogin";
    44. }
    45. @RequestMapping(value = "/adminLogout", method = RequestMethod.GET)
    46. public String adminLogout(@RequestParam(required = false, defaultValue = "false" )String adminLogout, HttpSession session){
    47. if (adminLogout.equals("true")){
    48. session.removeAttribute("admin");
    49. }
    50. // adminLogout = "false";
    51. return "redirect:/";
    52. }
    53. @RequestMapping(value = "/adminPage", method = RequestMethod.GET)
    54. public String getAdminPage(ModelMap model,
    55. HttpSession session){
    56. User admin = (User) session.getAttribute("admin");
    57. if (admin == null){
    58. return "redirect:/admin/adminLogin";
    59. }
    60. List<Good> goodList = goodService.getAllGoodList();
    61. for (Good good : goodList) {
    62. good.setGoodUser(userService.getUserById(good.getUserId()));
    63. good.setGoodSecondType(typeService.getSecondTypeById(good.getSecondTypeId()));
    64. }
    65. List<User> userList = userService.getAllUser();
    66. List<FirstType> firstTypeList = typeService.getAllFirstType();
    67. List<Order> orderList = orderService.getOrderList();
    68. model.addAttribute("goodList", goodList);
    69. model.addAttribute("userList", userList);
    70. model.addAttribute("firstTypeList", firstTypeList);
    71. model.addAttribute("orderList", orderList);
    72. return "admin/adminPage";
    73. }
    74. @RequestMapping(value = "/user/update/status/{statusId}&{userId}", method = RequestMethod.GET)
    75. public ResponseEntity updateUserStatus(@PathVariable Integer statusId,
    76. @PathVariable Integer userId){
    77. Boolean success = userService.updateUserStatus(statusId, userId);
    78. if (success){
    79. List<User> userList = userService.getAllUser();
    80. return ResponseEntity.ok(userList);
    81. }
    82. return ResponseEntity.ok(success);
    83. }
    84. @RequestMapping(value = "/user/delete/{userId}", method = RequestMethod.GET)
    85. public ResponseEntity deleteUser(@PathVariable Integer userId){
    86. Boolean success = userService.deleteUser(userId);
    87. if (success){
    88. List<User> userList = userService.getAllUser();
    89. return ResponseEntity.ok(userList);
    90. }
    91. return ResponseEntity.ok(success);
    92. }
    93. }

    首页控制器

    1. @Controller
    2. public class HomeController {
    3. private final UserService userService;
    4. @Autowired
    5. public HomeController(UserService userService) {
    6. this.userService = userService;
    7. }
    8. @RequestMapping(value = "/login", method = RequestMethod.GET)
    9. public String loginPage(ModelMap mode, HttpServletRequest request) {
    10. String preURL = request.getHeader("Referer");
    11. mode.addAttribute("preURL", preURL);
    12. return "home/login";
    13. }
    14. @RequestMapping(value = "/login", method = RequestMethod.POST)
    15. public String loginSubmit(ModelMap model,
    16. @RequestParam(value = "preURL", required = false, defaultValue = "") String preURL,
    17. @RequestParam(value = "email", required = false) String email,
    18. @RequestParam(value = "password", required = false) String password,
    19. HttpSession session) {
    20. User user = userService.getUserByEmail(email);
    21. String message;
    22. if (user != null){
    23. String mdsPass = DigestUtils.md5DigestAsHex((password + user.getCode()).getBytes());
    24. if (!mdsPass .equals(user.getPassword())){
    25. message = "用户密码错误!";
    26. } else {
    27. if (user.getStatusId() == 4){
    28. session.setAttribute("user",user);
    29. if (preURL.equals("")){
    30. return "redirect:/";
    31. } else {
    32. return "redirect:" + preURL;
    33. }
    34. } else {
    35. message = "用户已失效!";
    36. }
    37. }
    38. } else {
    39. message = "用户不存在!";
    40. }
    41. model.addAttribute("message", message);
    42. return "home/login";
    43. }
    44. @RequestMapping(value = "/logout", method = RequestMethod.GET)
    45. public String logout(@RequestParam(required = false, defaultValue = "false" )String logout, HttpSession session){
    46. if (logout.equals("true")){
    47. session.removeAttribute("user");
    48. }
    49. return "redirect:/";
    50. }
    51. @RequestMapping(value = "/register", method = RequestMethod.GET)
    52. public String registerPage(ModelMap model) {
    53. User user = new User();
    54. model.addAttribute("user", user);
    55. return "home/register";
    56. }
    57. @RequestMapping(value = "/register", method = RequestMethod.POST)
    58. public String registerSuccess(ModelMap model,
    59. @Valid User user) {
    60. String status;
    61. Boolean insertSuccess;
    62. InfoCheck infoCheck = new InfoCheck();
    63. if (!infoCheck.isMobile(user.getMobile())){
    64. status = "请输入正确的手机号!";
    65. } else if (!infoCheck.isEmail(user.getEmail())){
    66. status = "请输入正确的邮箱!";
    67. } else if (userService.getUserByMobile(user.getMobile()) != null) {
    68. status = "此手机号码已使用!";
    69. } else if (userService.getUserByEmail(user.getEmail()) != null) {
    70. status = "此邮箱已使用!";
    71. } else if (user.getPassword2() == null){
    72. status = "请确认密码!";
    73. } else {
    74. RandomString randomString = new RandomString();
    75. user.setCode(randomString.getRandomString(5));
    76. String md5Pass = DigestUtils.md5DigestAsHex((user.getPassword() + user.getCode()).getBytes());
    77. user.setPassword(md5Pass);
    78. insertSuccess = userService.registerUser(user);
    79. if (insertSuccess){
    80. return "home/login";
    81. } else {
    82. status = "注册失败!";
    83. model.addAttribute("user", user);
    84. model.addAttribute("status", status);
    85. return "home/register";
    86. }
    87. }
    88. System.out.println(user.getMobile());
    89. System.out.println(status);
    90. model.addAttribute("user", user);
    91. model.addAttribute("status", status);
    92. return "home/register";
    93. }
    94. }

    如果也想学习本系统,下面领取。回复:88ssm 

  • 相关阅读:
    vue工程化vue-cli创建项目以及图形创建vue项目
    liunx的三个时间atime,mtime,ctime详细说明与使用场景
    在 Python 中计算两个 GPS 点之间的距离
    (十六)51单片机——红外遥控
    spring如何处理多数据源
    AI语音机器人的重点功能配置之话术
    第13章Linux实操篇-进程管理(重点)
    SpringCloud和SpringCloudAlibaba的区别
    JetBrains 使用邮箱进行学生认证
    《系列一》-- 1、容器最基本使用
  • 原文地址:https://blog.csdn.net/hanyunlong1989/article/details/125496915