作者主页:夜未央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
- package com.shop.controller;
-
- import javax.servlet.http.HttpServletRequest;
-
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.Model;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestParam;
-
- import com.shop.Utils.PageBean;
- import com.shop.po.Product;
- import com.shop.service.ProductService;
-
- @Controller
- public class CategorySecondController {
- @Autowired
- private ProductService productService;
- //根据一级目录查找二级目录下面的商品(使用延迟加载但是这里不知为啥使用起来出错了)
- @RequestMapping("/findCategorySecond")
- public String findCategorySecond(HttpServletRequest request,@RequestParam int cid,Model model,@RequestParam int page) throws Exception {
- request.getSession().setAttribute("cid",cid);
- PageBean
proPageBean = productService.findProductyBycid(cid,page); - model.addAttribute("pageBean",proPageBean);
- return "category";
- }
-
- // 根据csid来分页查询商品
- @RequestMapping("/findCategorySecond1")
- public String findCategorySecond1(@RequestParam int csid,Model model,@RequestParam int page){
- PageBean
proPageBean = productService.finbProductByCsid(csid,page); - model.addAttribute("pageBean",proPageBean);
- return "category";
- }
- }
- package com.shop.controller;
-
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.image.BufferedImage;
- import java.io.IOException;
- import java.util.Random;
-
- import javax.imageio.ImageIO;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
-
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestMapping;
-
- @Controller
- public class checkImgController {
- @RequestMapping("checkImg")
- public void checkImg(HttpServletRequest request ,HttpServletResponse response) throws IOException {
-
- int width = 120;
- int height = 30;
-
- // 步骤一 绘制一张内存中图片
- BufferedImage bufferedImage = new BufferedImage(width, height,
- BufferedImage.TYPE_INT_RGB);
-
- // 步骤二 图片绘制背景颜色 ---通过绘图对象
- Graphics graphics = bufferedImage.getGraphics();// 得到画图对象 --- 画笔
- // 绘制任何图形之前 都必须指定一个颜色
- graphics.setColor(getRandColor(200, 250));
- graphics.fillRect(0, 0, width, height);
-
- // 步骤三 绘制边框
- graphics.setColor(Color.WHITE);
- graphics.drawRect(0, 0, width - 1, height - 1);
-
- // 步骤四 四个随机数字
- Graphics2D graphics2d = (Graphics2D) graphics;
- // 设置输出字体
- graphics2d.setFont(new Font("宋体", Font.BOLD, 18));
-
- // String words
- // ="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
- 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";
- Random random = new Random();// 生成随机数
- // 定义StringBuffer
- StringBuffer sb = new StringBuffer();
- // 定义x坐标
- int x = 10;
- for (int i = 0; i < 4; i++) {
- // 随机颜色
- graphics2d.setColor(new Color(20 + random.nextInt(110), 20 + random
- .nextInt(110), 20 + random.nextInt(110)));
- // 旋转 -30 --- 30度
- int jiaodu = random.nextInt(60) - 30;
- // 换算弧度
- double theta = jiaodu * Math.PI / 180;
-
- // 生成一个随机数字
- int index = random.nextInt(words.length()); // 生成随机数 0 到 length - 1
- // 获得字母数字
- char c = words.charAt(index);
- sb.append(c);
- // 将c 输出到图片
- graphics2d.rotate(theta, x, 20);
- graphics2d.drawString(String.valueOf(c), x, 20);
- graphics2d.rotate(-theta, x, 20);
- x += 30;
- }
-
- // 将生成的字母存入到session中
- request.getSession().setAttribute("checkcode", sb.toString());
- System.out.println(sb.toString());
- // 步骤五 绘制干扰线
- graphics.setColor(getRandColor(160, 200));
- int x1;
- int x2;
- int y1;
- int y2;
- for (int i = 0; i < 30; i++) {
- x1 = random.nextInt(width);
- x2 = random.nextInt(12);
- y1 = random.nextInt(height);
- y2 = random.nextInt(12);
- graphics.drawLine(x1, y1, x1 + x2, x2 + y2);
- }
-
- // 将上面图片输出到浏览器 ImageIO
- graphics.dispose();// 释放资源
- ImageIO.write(bufferedImage, "jpg", response.getOutputStream());
- }
-
- private Color getRandColor(int fc, int bc) {
- // 取其随机颜色
- Random random = new Random();
- if (fc > 255) {
- fc = 255;
- }
- if (bc > 255) {
- bc = 255;
- }
- int r = fc + random.nextInt(bc - fc);
- int g = fc + random.nextInt(bc - fc);
- int b = fc + random.nextInt(bc - fc);
- return new Color(r, g, b);
- }
- }
- package com.shop.controller;
-
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
-
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.Model;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestParam;
-
- import com.shop.exception.zdyException;
- import com.shop.po.Adminuser;
- import com.shop.po.User;
- import com.shop.service.UserService;
-
- @Controller
- public class loginController {
-
- @Autowired
- private UserService userService;
-
- @RequestMapping("login")
- public String login() {
- return "login";
- }
-
- // 用户登录
- @RequestMapping("/userLogin")
- public String userLogin(HttpServletRequest request,
- @RequestParam String checkImg, User user, Model model)
- throws zdyException, Exception {
- String sessionCode = (String) request.getSession().getAttribute(
- "checkcode");
- if (!sessionCode.equalsIgnoreCase(checkImg)) {
- //model.addAttribute("message", "验证码输入错误请重新注册");
- //throw new zdyException("验证码输入错误请重新注册");
- request.getSession().setAttribute("message", "验证码输入错误请重新注册");
- return "redirect:login.action";
- }
- User loginUser = userService.loginFindByUnameAndPwd(user.getUsername(),
- user.getPassword());
- if (loginUser == null) {
- //model.addAttribute("message", "密码输入错误请重新登陆");
- request.getSession().setAttribute("message", "密码输入错误请重新登陆");
- //throw new zdyException("密码输入错误请重新登陆");
- return "redirect:login.action";
- }
- request.getSession().setAttribute("loginUser", loginUser);
- request.getSession().removeAttribute("message");
- return "redirect:index.action";
- }
-
- // 用户退出
- @RequestMapping("userLogout")
- public String userLogout(HttpServletRequest request,
- HttpServletResponse response, Model model) {
- request.getSession().removeAttribute("loginUser");
- response.setHeader("content-type", "text/html;charset=UTF-8");
- response.setHeader("refresh", "5;url=/shop/index.action");
- model.addAttribute("message", "退出成功,系统将在5秒之后跳转到首页......");
- return "msg";
- }
-
- //进入管理员页面
- @RequestMapping("/admin")
- public String AdminIndex(){
- return "admin/index";
- }
- //admin/adminUser_login.action
- //adminUser_login管理员登录
- @RequestMapping("/admin/adminUser_login")
- public String adminUser_login(HttpServletRequest request,Model model,@RequestParam String username,@RequestParam String password) throws Exception{
- Adminuser adminuserLogin = userService.adminUser_login(username,password);
- System.out.println(username);
- System.out.println(password);
- if(adminuserLogin == null){
- model.addAttribute("message", "改用户未被授予管理员身份!");
- return "admin/index";
- }
- request.getSession().setAttribute("adminuserLogin", adminuserLogin);
- // model.addAttribute("adminuserLogin", adminuserLogin);
- return "admin/home";
- }
-
- }
- package com.shop.controller;
-
- import java.util.Date;
- import java.util.Map;
- import java.util.Map.Entry;
-
- import javax.servlet.http.HttpServletRequest;
-
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.Model;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestParam;
-
- import com.shop.Utils.PageBean;
- import com.shop.po.Cart;
- import com.shop.po.CartItem;
- import com.shop.po.Orderitem;
- import com.shop.po.Orders;
- import com.shop.po.User;
- import com.shop.service.OrderService;
-
-
- @Controller
- public class orderController {
- @Autowired
- private OrderService orderService;
-
- @RequestMapping("/toOrder")
- public String toOrder(HttpServletRequest request,Model model) throws Exception {
- Orders orders = new Orders();
- Cart cart = (Cart) request.getSession().getAttribute("cart");
- User loginUser = (User) request.getSession().getAttribute("loginUser");
- if(loginUser==null){
- model.addAttribute("message", "对不起您还没有登录");
- return "msg";
- }
- // 0表示没有付款、1表示已付款即将发货 2表示确认收货 3表示交易成功
- orders.setState(0);
- orders.setOrderTime(new Date());
- orders.setUid(loginUser.getUid());
- orders.setMoney(cart.getTotale());
-
- orderService.toOrder(orders);
-
- Map
cartItems = cart.getCartItem(); - for (Entry
entry : cartItems.entrySet()) { - CartItem cartItem = entry.getValue();
- Orderitem orderitem = new Orderitem();
- orderitem.setProduct(cartItem.getProduct());
- orderitem.setCount(cartItem.getCount());
- orderitem.setPid(cartItem.getProduct().getPid());
- orderitem.setSubtotal(cartItem.getSubtotle());
- orderitem.setOid(orders.getOid());
- orders.getOiList().add(orderitem);
- orderService.toOrderItem(orderitem);
- }
- cart.clearCart();
- request.getSession().setAttribute("orders", orders);
- return "order";
- }
-
- // 为定单付款
- @RequestMapping("/payOrder")
- public String payOrder(Orders orders,@RequestParam String receiveInfo,@RequestParam String phoNum,@RequestParam String accepter) throws Exception {
- orders.setReceiveinfo(receiveInfo);
- orders.setPhonum(phoNum);
- orders.setAccepter(accepter);
- orderService.payOrder(orders);
- return "redirect:myOrder.action?page=1";
- }
- //payOrderAganin
- @RequestMapping("/payOrderAganin")
- public String payOrderAganin(@RequestParam int oid,HttpServletRequest request){
- Orders noPayOrder = orderService.findOrderByOid(oid);
- request.getSession().setAttribute("orders", noPayOrder);
- return "order";
- }
- // 查询myOrder
- @RequestMapping("/myOrder")
- public String myOrder(@RequestParam int page, Model model,
- HttpServletRequest request) throws Exception {
- User loginUser = (User) request.getSession().getAttribute("loginUser");
- PageBean
pageBean = orderService.findOrderByUidAndPage(page,loginUser.getUid()); - model.addAttribute("pageBean", pageBean);
- return "orderList";
- }
-
- // 确认收货
- @RequestMapping("/updateState")
- public String updateState(@RequestParam int oid ) throws Exception {
- orderService.updateOrderStatus(oid, 3);
- return "redirect:myOrder.action?page=1";
- }
- }
如果也想学习本系统,下面领取。关注并回复:081ssm