目录
1.项目简介 1
2.数据库设计 3
2.1表结构 3
2.2ER图 7
3.项目实现 7
3.1项目配置 7
3.2工具类 9
3.3业务代码 15
3.4前端视图代码编写 18
4.项目展示 20
4.1前端部分 20
4.2后台管理 23
5.总结 27
1.项目简介
用户主要分为管理员和用户端
管理员: 管理员可以对后台数据进行管理、拥有最高权限、具体权限有登录后进行首页轮播图的配置管理、商品的配置、新品家具商城的配置管理、、家具商城分类管理配置、家具商城详情商品管理、用户管理、订单管理以及、修改密码等操作。
客户端用户:用户输入家具商城网站系统地址、可以浏览家具商城信息、需要查看详情或其他购买加入购物车等操作需要用户进行登录、,没有账号的用户可以进行注册操作、输入相关注册信息完成注册后登录。登录完成后可以进行商品的购买、商品查询、加入购物车、修改收货地址等一系列操作。
技术栈
主要技术实现:spring、 springboot、 mybatis 、 jquery 、 md5 、bootstarp.js tomcat、富文本编译器、拦截器等
用户需求分析:
功能模块
前端用户
(1) 用户注册和登录登录功能:
①用户的注册功能 : 访问网站的人根据网站的提示注册自己的账户
②用户的登录功能 : 用户可以输入用户名和密码进行登录操作,当没有该账户的时 候,提示错误,用户必须通过注册完成或者从数据库中获取才能进行会员权限级别的操 作。登录成功之后可以购买商品,查询订单的详细信息
(2) 、个人信息的管理:
①用户信息的修改操作,其中包括会员名、密码、性别、联系方式 e-mail 和个人介 绍等用户信息的修改操作。但是会员邮箱是绑定账号的,会员邮箱不能进行更改操作。
②订单管理操作:订单只能查询和删除操作,不能有修改操作,修改操作是属于管理员的权限。
③用户退出操作:当点击用户退出时,就会退出当前用户的登录状态,恢复到游客 状态。
(3) 、商品的操作:
①搜索商品操作: 当在 Search 栏输入想搜索的家居用品时, 会使用模糊查询, 搜索 出客户想到查询的家居用品。
②商品列表展示:
③商品详细信息展示:
(4) 、购物车的管理操作:
①显示商品信息:当我们一进入购物车页面,就会显示出商品的详细信息,以及购 物车界面的功能信息。
②修改商品的数量:用户可以自己输入不同数量的商品,当商品的数量变动时,商 品的库存就会相应的减少,也会根据商品的数量得到购买这一种商品的金额小计。
③删除购物车中的商品:
④购物流程变动:
(5) 、订单管理操作:
①订单生成:进入结算中心,会提示用户已经登录成功并来到结算中心,然后在提 交订单的时候生成了一份订单,会显示在确认订单页面。
②确认订单:当点击确认订单的时候会进入支付页面,那里会真正的付款操作。
③订单查询:在我的订单页面会显示订单的详细信息,我们可以查询我们想要的订 单信息。
④订单管理:在我的订单页面会显示所有订单的信息,可以在那里删除订单,查询 订单等。
后台管理员
系统的后台是专门为管理家居商城系统的人员设计的,功能如下:
(1) 、超级管理员:拥有管理该系统的最大权限,他有两个特有的功能
①数据字典:可以对后台的不同分类的分类列表具有增删改查的操作。
②角色管理:本文转载自http://www.biyezuopin.vip/onews.asp?id=14718将拥有不同权限的管理员分成不同的角色,每个不同角色有自己的权限,不能执行越权操作
(2) 、商品分类的管理:
①添加编辑分类:点击添加按钮,会跳转到分类添加页面,需要编写分类名称,分类描述信息。
2.删除分类:当点击删除按钮时,会弹出一个提醒框,当点击确定,删除分类,点击取消,保持原来不变。
(3) 、商品管理功能:
①查询商品 : 查询所有商品列表, 还有通过商品的名称、 商品的类别和价格区间查询
②添加修改商品 : 点击添加商品会转到添加商品页面, 需要提供商品名称、 商品图片、商 5 6 品类别、商品价格、库存数量、商品描述等内容。
④删除商品:删除商品。
package com.luo.shop.controller;
import com.luo.shop.pojo.*;
import com.luo.shop.service.*;
import com.luo.shop.util.CpachaUtil;
import com.sun.org.apache.xml.internal.resolver.helpers.PublicId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;
@Controller
public class SystemController {
@Autowired
private AddressService addressService;
@Autowired
private CategoryService categoryService;
@Autowired
private GoodsService goodsService;
@Autowired
private CommentService commentService;
@Autowired
private CartService cartService;
@Autowired
private UserService userService;
//验证码 cpachaType:用来区分验证码的类型,传字符串
@GetMapping("/cpacha")
public void verificationCode(@RequestParam(name = "v", required = false, defaultValue = "4") Integer vcodeLen,
@RequestParam(name = "w", required = false, defaultValue = "110") Integer width,
@RequestParam(name = "h", required = false, defaultValue = "30") Integer height,
@RequestParam(name = "type") String cpachaType,
HttpSession session,
HttpServletResponse response
) {
CpachaUtil cpachaUtil = new CpachaUtil(vcodeLen, width, height);
String generatorVCode = cpachaUtil.generatorVCode();
session.setAttribute(cpachaType, generatorVCode);
BufferedImage image = cpachaUtil.generatorRotateVCodeImage(generatorVCode, true);
try {
ImageIO.write(image, "gif", response.getOutputStream());
} catch (IOException e) {
e.printStackTrace();
}
}
@GetMapping("reg")
public String getRegPage(){ //注册页面
return "reg";
}
@GetMapping("login")
public String getLoginPage(HttpSession session,@RequestParam(required = false) String url,Model model){ //登录页面
model.addAttribute("url",url);
session.setAttribute("portalUser",null);
return "login";
}
@GetMapping("/")
public String getIndexPage(HttpSession session,Model model){ //首页
session.getServletContext().setAttribute("categorys",categoryService.selectAll());
model.addAttribute("url","/");
return "index";
}
@GetMapping("address")
public String getAddressPage(HttpSession session){ //用户发货地址页面
User user = (User)session.getAttribute("portalUser");
session.setAttribute("address",addressService.queryByUid(user.getId()).get(0));
return "address";
}
@GetMapping("mygrxx")
public String getMygrxxPage(){ //用户个人中心页面
return "mygrxx";
}
@GetMapping("remima")
public String getRemimaPage(){ //修改密码页面
return "remima";
}
@GetMapping("oppophone") //oppo手机页面
public String getOppoPhonePage(
Model model,
@RequestParam(value = "createtime",required = false) Boolean createtime,
@RequestParam(value = "price",required = false) Boolean price
){
model.addAttribute("goods",goodsService.queryByCid((long) 7,createtime,price));
model.addAttribute("url","/oppophone");
return "oppo_phone";
}
@GetMapping("prodetail")
public String getProDetailPage(Long id,Model model,HttpSession session){ //商品详情页面
Goods goods = goodsService.queryByid(id);
Category category = categoryService.queryById(goods.getCid());
model.addAttribute("goods",goods);
model.addAttribute("category",category);
model.addAttribute("comments",commentService.queryByGid(id));
User user = (User)session.getAttribute("portalUser");
if (user!=null){
session.setAttribute("portalUser",userService.queryById(user.getId()));
}
List<Goods> goodsList = goodsService.queryByCid(category.getId(), true, null);
List<Goods> list = new ArrayList<Goods>();
for (Goods good : goodsList) {
if (good.getId()!=id){
if (list.size()<4){
list.add(good);
}else {
break;
}
}
}
model.addAttribute("goodsList",list);
model.addAttribute("url","/prodetail?id="+id);
return "proDetail";
}
@PostMapping("upload")
@ResponseBody
public Map<String,Object> upload(MultipartFile[] file, HttpServletRequest request){
//指定上传的图片类型
List<String> image_type = Arrays.asList("JPG","PNG","GIF","JPEG","BMP");
//初始化返回图片地址
String images = "";
//初始化返回参数
Map<String,Object> map=new HashMap<String,Object>();
//判断图片是否为空
if (file != null && file.length > 0) {
for (int i = 0; i < file.length; i++) {
// 获取文件名
String filename = file[i].getOriginalFilename();
//获取文件名的后缀
String name = filename.substring(filename.lastIndexOf(".") + 1, filename.length());
String s = UUID.randomUUID().toString();
//判断集合中是否含有该后缀名
boolean contains = image_type.contains(name.toUpperCase());
//如果没有含有,就返回
if (contains){
File filepath = new File("D:\\work\\ideaprojects\\gitAdmin\\shop\\upload\\"+s+"."+name);
try {
file[i].transferTo(filepath);
} catch (IOException e) {
e.printStackTrace();
}
images+="http://image.shop.com/"+s+"."+name+"~";
}
}
map.put("imags",images.substring(0,images.length()-1));
map.put("success","ok");
map.put("msg","上传成功");
}else{
map.put("msg","上传失败");
}
return map;
}
@GetMapping("order")
public String getOrderPage(@RequestParam(required = false) String id,HttpSession session,Model model){ //支付页面
List<Cart> list = new ArrayList<Cart>();
User user = (User)session.getAttribute("portalUser");
Double sum = new Double(0);
for (Cart cart : cartService.queryByGidUid(null, user.getId())) {
if (id.indexOf(",")==-1){
if (cart.getId()==Long.parseLong(id)){
sum+=cart.getOrderNumber()*cart.getGoods().getPrice();
list.add(cart);
}
}else{
String[] split = id.split(",");
for (String s : split) {
if(cart.getId()==Long.parseLong(s)){
sum+=cart.getOrderNumber()*cart.getGoods().getPrice();
list.add(cart);
}
}
}
}
model.addAttribute("cartList",list);
model.addAttribute("id",id);
model.addAttribute("sum",sum);
session.setAttribute("portalUser",userService.queryById(user.getId()));
return "order";
}
@GetMapping("ok")
public String getOkPage(){ //支付成功页面
return "ok";
}
@GetMapping("myorderq")
public String getMyOrederq(@RequestParam(required = false) String title,Model model,HttpSession session){ //我的订单页面
User user = (User)session.getAttribute("portalUser");
List<Cart> list = cartService.queryByGidUid(null, user.getId());
if (title==null){
model.addAttribute("cartsList",list);
}else{
List<Cart> resultList = new ArrayList<Cart>();
for (Cart cart : list) {
if (cart.getGoods().getTitle().indexOf(title)!=-1){
resultList.add(cart);
}
}
model.addAttribute("cartsList",resultList);
}
return "myorderq";
}
@GetMapping("orderxq") //订单详情页面
public String orderxq(Long id,Model model,HttpSession session){
User user = (User)session.getAttribute("portalUser");
for (Cart cart : cartService.queryByGidUid(null, user.getId())) {
if (cart.getId()==id){
model.addAttribute("cart",cart);
}
}
return "orderxq";
}
@GetMapping("myprod") //评价晒单页面
public String myprod(Model model,HttpSession session){
User user = (User)session.getAttribute("portalUser");
model.addAttribute("carts",cartService.queryByGidUid(null,user.getId()));
return "myprod";
}
@GetMapping("wuliu") //查看物流页面
public String wuliu(){
return "wuliu";
}
@GetMapping("cart") //购物车页面
public String cart(Model model,HttpSession session){
User user = (User)session.getAttribute("portalUser");
List<Cart> list = new ArrayList<Cart>();
for (Cart cart : cartService.queryByGidUid(null, user.getId())) {
if (cart.getIsPayment()==false){
list.add(cart);
}
}
model.addAttribute("carts",list);
return "cart";
}
@GetMapping("mygxin")
public String mygxin(Model model,HttpSession session){ //个人中心页面
Integer isPayment =0;
Integer isComment = 0;
Integer isReceiving = 0;
User user = (User)session.getAttribute("portalUser");
List<Cart> list = new ArrayList<Cart>();
for (Cart cart : cartService.queryByGidUid(null, user.getId())) {
if (cart.getIsPayment()==false){
isPayment++;
}else{
if (cart.getIsReceiving()==false){
isReceiving++;
}else{
if(cart.getIsComment()==false){
isComment++;
}
}
}
}
model.addAttribute("isPayment",isPayment);
model.addAttribute("isComment",isComment);
model.addAttribute("isReceiving",isReceiving);
model.addAttribute("carts",list);
return "mygxin";
}
@GetMapping("search") //搜索页面
public String search(
Model model,
@RequestParam(required = false) String title,
@RequestParam(value = "createtime",required = false) Boolean createtime,
@RequestParam(value = "price",required = false) Boolean price
){
List<Goods> list = new ArrayList<Goods>();
for (Goods goods : goodsService.queryByCid(null, createtime, price)) {
if (goods.getTitle().indexOf(title)!=-1){
list.add(goods);
}
}
model.addAttribute("goods",list);
model.addAttribute("title",title);
model.addAttribute("url","/search?title="+title);
return "search";
}
}