作者:计算机编程-吉哥
简介:专业从事JavaWeb程序开发,微信小程序开发,定制化项目、 源码、代码讲解、文档撰写、ppt制作。做自己喜欢的事,生活就是快乐的。
心愿:点赞 收藏 ⭐评论
文末获取源码联系精彩专栏推荐订阅 不然下次找不到哟~
Java毕业设计项目~热门选题推荐《1000套》
springboot、mybatisplus、vue、elementui、html、css、js、mysql、jdk1.8
11张
idea、navicat
管理员、用户
1、首页
3、确认下单
4、收货地址
CREATE TABLE `address` (
`id` int(20) NOT NULL AUTO_INCREMENT COMMENT '主键 ',
`yonghu_id` int(20) NOT NULL COMMENT '创建用户',
`address_name` varchar(200) NOT NULL COMMENT '收货人 ',
`address_phone` varchar(200) NOT NULL COMMENT '电话 ',
`address_dizhi` varchar(200) NOT NULL COMMENT '地址 ',
`isdefault_types` int(11) NOT NULL COMMENT '是否默认地址 ',
`insert_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间 show3',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8 COMMENT='收货地址';
CREATE TABLE `cart` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
`yonghu_id` int(11) DEFAULT NULL COMMENT '所属用户',
`goods_id` int(11) DEFAULT NULL COMMENT '商品',
`buy_number` int(11) DEFAULT NULL COMMENT '购买数量',
`create_time` timestamp NULL DEFAULT NULL COMMENT '添加时间',
`update_time` timestamp NULL DEFAULT NULL COMMENT '更新时间',
`insert_time` timestamp NULL DEFAULT NULL COMMENT '创建时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=32 DEFAULT CHARSET=utf8 COMMENT='购物车';
CREATE TABLE `config` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
`name` varchar(100) NOT NULL COMMENT '配置参数名称',
`value` varchar(100) DEFAULT NULL COMMENT '配置参数值',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='配置文件';
CREATE TABLE `dictionary` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
`dic_code` varchar(200) DEFAULT NULL COMMENT '字段',
`dic_name` varchar(200) DEFAULT NULL COMMENT '字段名',
`code_index` int(11) DEFAULT NULL COMMENT '编码',
`index_name` varchar(200) DEFAULT NULL COMMENT '编码名字 Search111 ',
`super_id` int(11) DEFAULT NULL COMMENT '父字段id',
`beizhu` varchar(200) DEFAULT NULL COMMENT '备注',
`create_time` timestamp NULL DEFAULT NULL COMMENT '创建时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=74 DEFAULT CHARSET=utf8 COMMENT='字典表';
CREATE TABLE `goods_commentback` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
`goods_id` int(11) DEFAULT NULL COMMENT '商品',
`yonghu_id` int(11) DEFAULT NULL COMMENT '用户',
`goods_commentback_text` text COMMENT '评价内容',
`reply_text` text COMMENT '回复内容',
`insert_time` timestamp NULL DEFAULT NULL COMMENT '评价时间',
`update_time` timestamp NULL DEFAULT NULL COMMENT '回复时间',
`create_time` timestamp NULL DEFAULT NULL COMMENT '创建时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8 COMMENT='商品评价';
CREATE TABLE `goods_order` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
`goods_order_uuid_number` varchar(200) DEFAULT NULL COMMENT '订单号',
`address_id` int(11) DEFAULT NULL COMMENT '收获地址 ',
`goods_id` int(11) DEFAULT NULL COMMENT '商品',
`yonghu_id` int(11) DEFAULT NULL COMMENT '用户',
`buy_number` int(200) DEFAULT NULL COMMENT '购买的数量',
`goods_order_true_price` decimal(10,2) DEFAULT NULL COMMENT '实付价格 ',
`goods_order_types` int(11) DEFAULT NULL COMMENT '订单类型',
`goods_order_payment_types` int(11) DEFAULT NULL COMMENT '支付类型',
`insert_time` timestamp NULL DEFAULT NULL COMMENT '订单创建时间',
`create_time` timestamp NULL DEFAULT NULL COMMENT '创建时间 show3',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COMMENT='商品订单';
CREATE TABLE `news` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键 ',
`news_name` varchar(200) DEFAULT NULL COMMENT '新闻名称 Search111 ',
`news_photo` varchar(200) DEFAULT NULL COMMENT '新闻图片 ',
`news_types` int(11) NOT NULL COMMENT '新闻类型 ',
`insert_time` timestamp NULL DEFAULT NULL COMMENT '新闻发布时间 ',
`news_content` text COMMENT '新闻详情 ',
`create_time` timestamp NULL DEFAULT NULL COMMENT '创建时间 show1 show2 nameShow',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8 COMMENT='新闻信息';
CREATE TABLE `token` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
`userid` bigint(20) NOT NULL COMMENT '用户id',
`username` varchar(100) NOT NULL COMMENT '用户名',
`tablename` varchar(100) DEFAULT NULL COMMENT '表名',
`role` varchar(100) DEFAULT NULL COMMENT '角色',
`token` varchar(200) NOT NULL COMMENT '密码',
`addtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '新增时间',
`expiratedtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '过期时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='token表';
CREATE TABLE `users` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键',
`username` varchar(100) NOT NULL COMMENT '用户名',
`password` varchar(100) NOT NULL COMMENT '密码',
`role` varchar(100) DEFAULT '管理员' COMMENT '角色',
`addtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '新增时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='用户表';
CREATE TABLE `yonghu` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
`username` varchar(200) DEFAULT NULL COMMENT '账户',
`password` varchar(200) DEFAULT NULL COMMENT '密码',
`yonghu_name` varchar(200) DEFAULT NULL COMMENT '用户姓名 Search111 ',
`yonghu_photo` varchar(255) DEFAULT NULL COMMENT '头像',
`yonghu_phone` varchar(200) DEFAULT NULL COMMENT '用户手机号',
`yonghu_id_number` varchar(200) DEFAULT NULL COMMENT '用户身份证号 ',
`sex_types` int(11) DEFAULT NULL COMMENT '性别 Search111 ',
`new_money` decimal(10,2) DEFAULT NULL COMMENT '余额 ',
`yonghu_delete` int(11) DEFAULT '1' COMMENT '假删',
`create_time` timestamp NULL DEFAULT NULL COMMENT '创建时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COMMENT='用户';
package com.controller;
import java.io.File;
import java.math.BigDecimal;
import java.net.URL;
import java.text.SimpleDateFormat;
import com.alibaba.fastjson.JSONObject;
import java.util.*;
import org.springframework.beans.BeanUtils;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.ContextLoader;
import javax.servlet.ServletContext;
import com.service.TokenService;
import com.utils.*;
import java.lang.reflect.InvocationTargetException;
import com.service.DictionaryService;
import org.apache.commons.lang3.StringUtils;
import com.annotation.IgnoreAuth;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.entity.*;
import com.entity.view.*;
import com.service.*;
import com.utils.PageUtils;
import com.utils.R;
import com.alibaba.fastjson.*;
/**
* 商品信息
* 后端接口
* @author 计算机编程-吉哥
*/
@RestController
@Controller
@RequestMapping("/goods")
public class GoodsController {
private static final Logger logger = LoggerFactory.getLogger(GoodsController.class);
@Autowired
private GoodsService goodsService;
@Autowired
private TokenService tokenService;
@Autowired
private DictionaryService dictionaryService;
//级联表service
@Autowired
private YonghuService yonghuService;
/**
* 后端列表
*/
@RequestMapping("/page")
public R page(@RequestParam Map params, HttpServletRequest request){
logger.debug("page方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
String role = String.valueOf(request.getSession().getAttribute("role"));
if(StringUtil.isEmpty(role))
return R.error(511,"权限为空");
else if("用户".equals(role))
params.put("yonghuId",request.getSession().getAttribute("userId"));
params.put("goodsDeleteStart",1);params.put("goodsDeleteEnd",1);
if(params.get("orderBy")==null || params.get("orderBy")==""){
params.put("orderBy","id");
}
PageUtils page = goodsService.queryPage(params);
//字典表数据转换
List list =(List)page.getList();
for(GoodsView c:list){
//修改对应字典表字段
dictionaryService.dictionaryConvert(c, request);
}
return R.ok().put("data", page);
}
/**
* 后端详情
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id, HttpServletRequest request){
logger.debug("info方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
GoodsEntity goods = goodsService.selectById(id);
if(goods !=null){
//entity转view
GoodsView view = new GoodsView();
BeanUtils.copyProperties( goods , view );//把实体数据重构到view中
//修改对应字典表字段
dictionaryService.dictionaryConvert(view, request);
return R.ok().put("data", view);
}else {
return R.error(511,"查不到数据");
}
}
/**
* 后端保存
*/
@RequestMapping("/save")
public R save(@RequestBody GoodsEntity goods, HttpServletRequest request){
logger.debug("save方法:,,Controller:{},,goods:{}",this.getClass().getName(),goods.toString());
String role = String.valueOf(request.getSession().getAttribute("role"));
if(StringUtil.isEmpty(role))
return R.error(511,"权限为空");
Wrapper queryWrapper = new EntityWrapper()
.eq("goods_name", goods.getGoodsName())
.eq("goods_types", goods.getGoodsTypes())
.eq("goods_kucun_number", goods.getGoodsKucunNumber())
.eq("goods_clicknum", goods.getGoodsClicknum())
.eq("shangxia_types", goods.getShangxiaTypes())
.eq("goods_delete", goods.getGoodsDelete())
;
logger.info("sql语句:"+queryWrapper.getSqlSegment());
GoodsEntity goodsEntity = goodsService.selectOne(queryWrapper);
if(goodsEntity==null){
goods.setGoodsClicknum(1);
goods.setShangxiaTypes(1);
goods.setGoodsDelete(1);
goods.setCreateTime(new Date());
goodsService.insert(goods);
return R.ok();
}else {
return R.error(511,"表中有相同数据");
}
}
/**
* 后端修改
*/
@RequestMapping("/update")
public R update(@RequestBody GoodsEntity goods, HttpServletRequest request){
logger.debug("update方法:,,Controller:{},,goods:{}",this.getClass().getName(),goods.toString());
String role = String.valueOf(request.getSession().getAttribute("role"));
// if(StringUtil.isEmpty(role))
// return R.error(511,"权限为空");
//根据字段查询是否有相同数据
Wrapper queryWrapper = new EntityWrapper()
.notIn("id",goods.getId())
.andNew()
.eq("goods_name", goods.getGoodsName())
.eq("goods_types", goods.getGoodsTypes())
.eq("goods_kucun_number", goods.getGoodsKucunNumber())
.eq("goods_clicknum", goods.getGoodsClicknum())
.eq("shangxia_types", goods.getShangxiaTypes())
.eq("goods_delete", goods.getGoodsDelete())
;
logger.info("sql语句:"+queryWrapper.getSqlSegment());
GoodsEntity goodsEntity = goodsService.selectOne(queryWrapper);
if("".equals(goods.getGoodsPhoto()) || "null".equals(goods.getGoodsPhoto())){
goods.setGoodsPhoto(null);
}
if(goodsEntity==null){
// String role = String.valueOf(request.getSession().getAttribute("role"));
// if("".equals(role)){
// goods.set
// }
goodsService.updateById(goods);//根据id更新
return R.ok();
}else {
return R.error(511,"表中有相同数据");
}
}
/**
* 删除
*/
@RequestMapping("/delete")
public R delete(@RequestBody Integer[] ids){
logger.debug("delete:,,Controller:{},,ids:{}",this.getClass().getName(),ids.toString());
ArrayList list = new ArrayList<>();
for(Integer id:ids){
GoodsEntity goodsEntity = new GoodsEntity();
goodsEntity.setId(id);
goodsEntity.setGoodsDelete(2);
list.add(goodsEntity);
}
if(list != null && list.size() >0){
goodsService.updateBatchById(list);
}
return R.ok();
}
/**
* 批量上传
*/
@RequestMapping("/batchInsert")
public R save( String fileName){
logger.debug("batchInsert方法:,,Controller:{},,fileName:{}",this.getClass().getName(),fileName);
try {
List goodsList = new ArrayList<>();//上传的东西
Map> seachFields= new HashMap<>();//要查询的字段
Date date = new Date();
int lastIndexOf = fileName.lastIndexOf(".");
if(lastIndexOf == -1){
return R.error(511,"该文件没有后缀");
}else{
String suffix = fileName.substring(lastIndexOf);
if(!".xls".equals(suffix)){
return R.error(511,"只支持后缀为xls的excel文件");
}else{
URL resource = this.getClass().getClassLoader().getResource("static/upload/" + fileName);//获取文件路径
File file = new File(resource.getFile());
if(!file.exists()){
return R.error(511,"找不到上传文件,请联系管理员");
}else{
List> dataList = PoiUtil.poiImport(file.getPath());//读取xls文件
dataList.remove(0);//删除第一行,因为第一行是提示
for(List data:dataList){
//循环
GoodsEntity goodsEntity = new GoodsEntity();
goodsList.add(goodsEntity);
}
//查询是否重复
goodsService.insertBatch(goodsList);
return R.ok();
}
}
}
}catch (Exception e){
return R.error(511,"批量插入数据异常,请联系管理员");
}
}
/**
* 前端列表
*/
@IgnoreAuth
@RequestMapping("/list")
public R list(@RequestParam Map params, HttpServletRequest request){
logger.debug("list方法:,,Controller:{},,params:{}",this.getClass().getName(),JSONObject.toJSONString(params));
// 没有指定排序字段就默认id倒序
if(StringUtil.isEmpty(String.valueOf(params.get("orderBy")))){
params.put("orderBy","id");
}
PageUtils page = goodsService.queryPage(params);
//字典表数据转换
List list =(List)page.getList();
for(GoodsView c:list)
dictionaryService.dictionaryConvert(c, request); //修改对应字典表字段
return R.ok().put("data", page);
}
/**
* 前端详情
*/
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id, HttpServletRequest request){
logger.debug("detail方法:,,Controller:{},,id:{}",this.getClass().getName(),id);
GoodsEntity goods = goodsService.selectById(id);
if(goods !=null){
//点击数量加1
goods.setGoodsClicknum(goods.getGoodsClicknum()+1);
goodsService.updateById(goods);
//entity转view
GoodsView view = new GoodsView();
BeanUtils.copyProperties( goods , view );//把实体数据重构到view中
//修改对应字典表字段
dictionaryService.dictionaryConvert(view, request);
return R.ok().put("data", view);
}else {
return R.error(511,"查不到数据");
}
}
/**
* 前端保存
*/
@RequestMapping("/add")
public R add(@RequestBody GoodsEntity goods, HttpServletRequest request){
logger.debug("add方法:,,Controller:{},,goods:{}",this.getClass().getName(),goods.toString());
Wrapper queryWrapper = new EntityWrapper()
.eq("goods_name", goods.getGoodsName())
.eq("goods_types", goods.getGoodsTypes())
.eq("goods_kucun_number", goods.getGoodsKucunNumber())
.eq("goods_clicknum", goods.getGoodsClicknum())
.eq("shangxia_types", goods.getShangxiaTypes())
.eq("goods_delete", goods.getGoodsDelete())
;
logger.info("sql语句:"+queryWrapper.getSqlSegment());
GoodsEntity goodsEntity = goodsService.selectOne(queryWrapper);
if(goodsEntity==null){
goods.setGoodsDelete(1);
goods.setCreateTime(new Date());
// String role = String.valueOf(request.getSession().getAttribute("role"));
// if("".equals(role)){
// goods.set
// }
goodsService.insert(goods);
return R.ok();
}else {
return R.error(511,"表中有相同数据");
}
}
}
更多项目推荐:计算机毕业设计项目
如果大家有任何疑虑,请在下方咨询或评论