• Java项目: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+jQuery+Ajax

    使用说明

    1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
    2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
    3. 将项目中jdbc.properties配置文件中的数据库配置改为自己的配置;

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

    用户账号/密码: user/123456
    管理员账号/密码:admin/admin

    运行截图

    前台界面

     

     

     

     

     

     后台界面

     

     

     

     

     

    相关代码 

    CategorySecondController

    1. package com.shop.controller;
    2. import javax.servlet.http.HttpServletRequest;
    3. import org.springframework.beans.factory.annotation.Autowired;
    4. import org.springframework.stereotype.Controller;
    5. import org.springframework.ui.Model;
    6. import org.springframework.web.bind.annotation.RequestMapping;
    7. import org.springframework.web.bind.annotation.RequestParam;
    8. import com.shop.Utils.PageBean;
    9. import com.shop.po.Product;
    10. import com.shop.service.ProductService;
    11. @Controller
    12. public class CategorySecondController {
    13. @Autowired
    14. private ProductService productService;
    15. //根据一级目录查找二级目录下面的商品(使用延迟加载但是这里不知为啥使用起来出错了)
    16. @RequestMapping("/findCategorySecond")
    17. public String findCategorySecond(HttpServletRequest request,@RequestParam int cid,Model model,@RequestParam int page) throws Exception {
    18. request.getSession().setAttribute("cid",cid);
    19. PageBean proPageBean = productService.findProductyBycid(cid,page);
    20. model.addAttribute("pageBean",proPageBean);
    21. return "category";
    22. }
    23. // 根据csid来分页查询商品
    24. @RequestMapping("/findCategorySecond1")
    25. public String findCategorySecond1(@RequestParam int csid,Model model,@RequestParam int page){
    26. PageBean proPageBean = productService.finbProductByCsid(csid,page);
    27. model.addAttribute("pageBean",proPageBean);
    28. return "category";
    29. }
    30. }

    checkImgController

    1. package com.shop.controller;
    2. import java.awt.Color;
    3. import java.awt.Font;
    4. import java.awt.Graphics;
    5. import java.awt.Graphics2D;
    6. import java.awt.image.BufferedImage;
    7. import java.io.IOException;
    8. import java.util.Random;
    9. import javax.imageio.ImageIO;
    10. import javax.servlet.http.HttpServletRequest;
    11. import javax.servlet.http.HttpServletResponse;
    12. import org.springframework.stereotype.Controller;
    13. import org.springframework.web.bind.annotation.RequestMapping;
    14. @Controller
    15. public class checkImgController {
    16. @RequestMapping("checkImg")
    17. public void checkImg(HttpServletRequest request ,HttpServletResponse response) throws IOException {
    18. int width = 120;
    19. int height = 30;
    20. // 步骤一 绘制一张内存中图片
    21. BufferedImage bufferedImage = new BufferedImage(width, height,
    22. BufferedImage.TYPE_INT_RGB);
    23. // 步骤二 图片绘制背景颜色 ---通过绘图对象
    24. Graphics graphics = bufferedImage.getGraphics();// 得到画图对象 --- 画笔
    25. // 绘制任何图形之前 都必须指定一个颜色
    26. graphics.setColor(getRandColor(200, 250));
    27. graphics.fillRect(0, 0, width, height);
    28. // 步骤三 绘制边框
    29. graphics.setColor(Color.WHITE);
    30. graphics.drawRect(0, 0, width - 1, height - 1);
    31. // 步骤四 四个随机数字
    32. Graphics2D graphics2d = (Graphics2D) graphics;
    33. // 设置输出字体
    34. graphics2d.setFont(new Font("宋体", Font.BOLD, 18));
    35. // String words
    36. // ="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
    37. String words = "\u7684\u4e00\u4e86\u662f\u6211\u4e0d\u5728\u4eba\u4eec\u6709\u6765\u4ed6\u8fd9\u4e0a\u7740\u4e2a\u5730\u5230\u5927\u91cc\u8bf4\u5c31\u53bb\u5b50\u5f97\u4e5f\u548c\u90a3\u8981\u4e0b\u770b\u5929\u65f6\u8fc7\u51fa\u5c0f\u4e48\u8d77\u4f60\u90fd\u628a\u597d\u8fd8";
    38. Random random = new Random();// 生成随机数
    39. // 定义StringBuffer
    40. StringBuffer sb = new StringBuffer();
    41. // 定义x坐标
    42. int x = 10;
    43. for (int i = 0; i < 4; i++) {
    44. // 随机颜色
    45. graphics2d.setColor(new Color(20 + random.nextInt(110), 20 + random
    46. .nextInt(110), 20 + random.nextInt(110)));
    47. // 旋转 -30 --- 30度
    48. int jiaodu = random.nextInt(60) - 30;
    49. // 换算弧度
    50. double theta = jiaodu * Math.PI / 180;
    51. // 生成一个随机数字
    52. int index = random.nextInt(words.length()); // 生成随机数 0 到 length - 1
    53. // 获得字母数字
    54. char c = words.charAt(index);
    55. sb.append(c);
    56. // 将c 输出到图片
    57. graphics2d.rotate(theta, x, 20);
    58. graphics2d.drawString(String.valueOf(c), x, 20);
    59. graphics2d.rotate(-theta, x, 20);
    60. x += 30;
    61. }
    62. // 将生成的字母存入到session中
    63. request.getSession().setAttribute("checkcode", sb.toString());
    64. System.out.println(sb.toString());
    65. // 步骤五 绘制干扰线
    66. graphics.setColor(getRandColor(160, 200));
    67. int x1;
    68. int x2;
    69. int y1;
    70. int y2;
    71. for (int i = 0; i < 30; i++) {
    72. x1 = random.nextInt(width);
    73. x2 = random.nextInt(12);
    74. y1 = random.nextInt(height);
    75. y2 = random.nextInt(12);
    76. graphics.drawLine(x1, y1, x1 + x2, x2 + y2);
    77. }
    78. // 将上面图片输出到浏览器 ImageIO
    79. graphics.dispose();// 释放资源
    80. ImageIO.write(bufferedImage, "jpg", response.getOutputStream());
    81. }
    82. private Color getRandColor(int fc, int bc) {
    83. // 取其随机颜色
    84. Random random = new Random();
    85. if (fc > 255) {
    86. fc = 255;
    87. }
    88. if (bc > 255) {
    89. bc = 255;
    90. }
    91. int r = fc + random.nextInt(bc - fc);
    92. int g = fc + random.nextInt(bc - fc);
    93. int b = fc + random.nextInt(bc - fc);
    94. return new Color(r, g, b);
    95. }
    96. }

    loginController

    1. package com.shop.controller;
    2. import javax.servlet.http.HttpServletRequest;
    3. import javax.servlet.http.HttpServletResponse;
    4. import org.springframework.beans.factory.annotation.Autowired;
    5. import org.springframework.stereotype.Controller;
    6. import org.springframework.ui.Model;
    7. import org.springframework.web.bind.annotation.RequestMapping;
    8. import org.springframework.web.bind.annotation.RequestParam;
    9. import com.shop.exception.zdyException;
    10. import com.shop.po.Adminuser;
    11. import com.shop.po.User;
    12. import com.shop.service.UserService;
    13. @Controller
    14. public class loginController {
    15. @Autowired
    16. private UserService userService;
    17. @RequestMapping("login")
    18. public String login() {
    19. return "login";
    20. }
    21. // 用户登录
    22. @RequestMapping("/userLogin")
    23. public String userLogin(HttpServletRequest request,
    24. @RequestParam String checkImg, User user, Model model)
    25. throws zdyException, Exception {
    26. String sessionCode = (String) request.getSession().getAttribute(
    27. "checkcode");
    28. if (!sessionCode.equalsIgnoreCase(checkImg)) {
    29. //model.addAttribute("message", "验证码输入错误请重新注册");
    30. //throw new zdyException("验证码输入错误请重新注册");
    31. request.getSession().setAttribute("message", "验证码输入错误请重新注册");
    32. return "redirect:login.action";
    33. }
    34. User loginUser = userService.loginFindByUnameAndPwd(user.getUsername(),
    35. user.getPassword());
    36. if (loginUser == null) {
    37. //model.addAttribute("message", "密码输入错误请重新登陆");
    38. request.getSession().setAttribute("message", "密码输入错误请重新登陆");
    39. //throw new zdyException("密码输入错误请重新登陆");
    40. return "redirect:login.action";
    41. }
    42. request.getSession().setAttribute("loginUser", loginUser);
    43. request.getSession().removeAttribute("message");
    44. return "redirect:index.action";
    45. }
    46. // 用户退出
    47. @RequestMapping("userLogout")
    48. public String userLogout(HttpServletRequest request,
    49. HttpServletResponse response, Model model) {
    50. request.getSession().removeAttribute("loginUser");
    51. response.setHeader("content-type", "text/html;charset=UTF-8");
    52. response.setHeader("refresh", "5;url=/shop/index.action");
    53. model.addAttribute("message", "退出成功,系统将在5秒之后跳转到首页......");
    54. return "msg";
    55. }
    56. //进入管理员页面
    57. @RequestMapping("/admin")
    58. public String AdminIndex(){
    59. return "admin/index";
    60. }
    61. //admin/adminUser_login.action
    62. //adminUser_login管理员登录
    63. @RequestMapping("/admin/adminUser_login")
    64. public String adminUser_login(HttpServletRequest request,Model model,@RequestParam String username,@RequestParam String password) throws Exception{
    65. Adminuser adminuserLogin = userService.adminUser_login(username,password);
    66. System.out.println(username);
    67. System.out.println(password);
    68. if(adminuserLogin == null){
    69. model.addAttribute("message", "改用户未被授予管理员身份!");
    70. return "admin/index";
    71. }
    72. request.getSession().setAttribute("adminuserLogin", adminuserLogin);
    73. // model.addAttribute("adminuserLogin", adminuserLogin);
    74. return "admin/home";
    75. }
    76. }

    orderController

    1. package com.shop.controller;
    2. import java.util.Date;
    3. import java.util.Map;
    4. import java.util.Map.Entry;
    5. import javax.servlet.http.HttpServletRequest;
    6. import org.springframework.beans.factory.annotation.Autowired;
    7. import org.springframework.stereotype.Controller;
    8. import org.springframework.ui.Model;
    9. import org.springframework.web.bind.annotation.RequestMapping;
    10. import org.springframework.web.bind.annotation.RequestParam;
    11. import com.shop.Utils.PageBean;
    12. import com.shop.po.Cart;
    13. import com.shop.po.CartItem;
    14. import com.shop.po.Orderitem;
    15. import com.shop.po.Orders;
    16. import com.shop.po.User;
    17. import com.shop.service.OrderService;
    18. @Controller
    19. public class orderController {
    20. @Autowired
    21. private OrderService orderService;
    22. @RequestMapping("/toOrder")
    23. public String toOrder(HttpServletRequest request,Model model) throws Exception {
    24. Orders orders = new Orders();
    25. Cart cart = (Cart) request.getSession().getAttribute("cart");
    26. User loginUser = (User) request.getSession().getAttribute("loginUser");
    27. if(loginUser==null){
    28. model.addAttribute("message", "对不起您还没有登录");
    29. return "msg";
    30. }
    31. // 0表示没有付款、1表示已付款即将发货 2表示确认收货 3表示交易成功
    32. orders.setState(0);
    33. orders.setOrderTime(new Date());
    34. orders.setUid(loginUser.getUid());
    35. orders.setMoney(cart.getTotale());
    36. orderService.toOrder(orders);
    37. Map cartItems = cart.getCartItem();
    38. for (Entry entry : cartItems.entrySet()) {
    39. CartItem cartItem = entry.getValue();
    40. Orderitem orderitem = new Orderitem();
    41. orderitem.setProduct(cartItem.getProduct());
    42. orderitem.setCount(cartItem.getCount());
    43. orderitem.setPid(cartItem.getProduct().getPid());
    44. orderitem.setSubtotal(cartItem.getSubtotle());
    45. orderitem.setOid(orders.getOid());
    46. orders.getOiList().add(orderitem);
    47. orderService.toOrderItem(orderitem);
    48. }
    49. cart.clearCart();
    50. request.getSession().setAttribute("orders", orders);
    51. return "order";
    52. }
    53. // 为定单付款
    54. @RequestMapping("/payOrder")
    55. public String payOrder(Orders orders,@RequestParam String receiveInfo,@RequestParam String phoNum,@RequestParam String accepter) throws Exception {
    56. orders.setReceiveinfo(receiveInfo);
    57. orders.setPhonum(phoNum);
    58. orders.setAccepter(accepter);
    59. orderService.payOrder(orders);
    60. return "redirect:myOrder.action?page=1";
    61. }
    62. //payOrderAganin
    63. @RequestMapping("/payOrderAganin")
    64. public String payOrderAganin(@RequestParam int oid,HttpServletRequest request){
    65. Orders noPayOrder = orderService.findOrderByOid(oid);
    66. request.getSession().setAttribute("orders", noPayOrder);
    67. return "order";
    68. }
    69. // 查询myOrder
    70. @RequestMapping("/myOrder")
    71. public String myOrder(@RequestParam int page, Model model,
    72. HttpServletRequest request) throws Exception {
    73. User loginUser = (User) request.getSession().getAttribute("loginUser");
    74. PageBean pageBean = orderService.findOrderByUidAndPage(page,loginUser.getUid());
    75. model.addAttribute("pageBean", pageBean);
    76. return "orderList";
    77. }
    78. // 确认收货
    79. @RequestMapping("/updateState")
    80. public String updateState(@RequestParam int oid ) throws Exception {
    81. orderService.updateOrderStatus(oid, 3);
    82. return "redirect:myOrder.action?page=1";
    83. }
    84. }

    如果也想学习本系统,下面领取。关注并回复:081ssm 

  • 相关阅读:
    micronet ICCV2021
    GraphRAG学习小结(4)
    【Egg从基础到进阶】一:Egg项目初始化及基础入门
    谣言检测(RDCL)——《Towards Robust False Information Detection on Social Networks with Contrastive Learning》
    jQuery学习:自定义动画animate
    ASP.NET Core - 依赖注入(四)
    本地搭建http模拟服务
    外卖跑腿系统的关键功能和技术要点
    Sqlserver存储过程快速上手分享
    跨域和同源
  • 原文地址:https://blog.csdn.net/hanyunlong1989/article/details/126685226