基于javaweb+mysql的springboot在线蛋糕销售商城(java+springboot+maven+mysql+thymeleaf+html+redis)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot在线蛋糕销售商城(java+springboot+maven+mysql+thymeleaf+html+redis)
一、项目简述
功能: 主页显示商品; 所有蛋糕商品展示,可进行商品搜索; 点击商品进入商品详情页,具有立即购买功能,可增减购买商品数量亦可手动输入,热销商品展示。 立即购买进入确认订单页面,可选择已经添加的地址,亦可新增地址。 可选择购买哪些商品,可删除不需要的商品。 点击结算进入确认订单页面,确认后提交订单。后台管理:(修改密码等),商品管理(商品批量添加、上下架等),订单管理。
二、项目运行
环境配置:
Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
项目技术:
JSP +Springboot+ SpringMVC + MyBatis + ThymeLeaf + FTP+ JavaScript + JQuery + Ajax + maven等等
* @param model
* @return
* @throws Exception
*/
@GetMapping("list.htm")
public String list(Model model)throws Exception{
List<RoleEntity> list = roleService.selectList(new EntityWrapper<>());
model.addAttribute("list",list);
return "role/list";
}
/**
* 保存
* @param id
* @param name
* @return
* @throws Exception
*/
@PostMapping("save.htm")
@ResponseBody
@ImLog(type = "角色",mark = "保存角色 {id} {name} {status}")
public Result save(String id,String name,Boolean status)throws Exception{
RoleEntity roleEntity = new RoleEntity();
roleEntity.setName(name);
roleEntity.setStatus(status);
if(StringUtils.isEmpty(id)){
roleEntity.setId(IdWorker.get32UUID());
roleEntity.setTime(new Date());
roleService.insert(roleEntity);
}else{
roleEntity.setId(id);
roleService.updateById(roleEntity);
}
return Result.success("保存成功");
}
/**
* 删除
* @param id
* @return
* @throws Exception
*/
@PostMapping("del.htm")
@ResponseBody
@ImLog(type = "角色",mark = "删除角色 {id}")
orderEntity.setId(orderId);
orderEntity.setCustomerId(userEntity.getId());
orderEntity.setStatus(1);
orderEntity.setTime(new Date());
CustomerAddressEntity customerAddressEntity = customerAddressService.selectById(addressId);
if (customerAddressEntity == null) {
return Result.error("请选择收货地址");
}
//验证库存是否足够
for (int i = 0; i < ids.length; i++) {
ShoppingGatEntity shoppingGatEntity = shoppingGatService.selectById(ids[i]);
ShopEntity shopEntity = shopService.selectById(shoppingGatEntity.getShopId());
if (shopEntity.getStock() == null || shopEntity.getStock() < shoppingGatEntity.getNum()) {
return Result.error(shopEntity.getName() + "库存不足");
}
}
orderEntity.setAddress(customerAddressEntity.getAddress());
orderEntity.setName(customerAddressEntity.getName());
orderEntity.setPhone(customerAddressEntity.getPhone());
orderService.insert(orderEntity);
String name = StrUtil.EMPTY;
for (int i = 0; i < ids.length; i++) {
ShoppingGatEntity shoppingGatEntity = shoppingGatService.selectById(ids[i]);
ShopEntity shopEntity = shopService.selectById(shoppingGatEntity.getShopId());
OrderShopEntity orderShopEntity = new OrderShopEntity();
orderShopEntity.setId(IdWorkerUtil.getId());
orderShopEntity.setPrice(new BigDecimal(prices[i]));
orderShopEntity.setNum(nums[i]);
orderShopEntity.setOrderId(orderEntity.getId());
orderShopEntity.setName(shopEntity.getName());
name = name.concat(shopEntity.getName() + "+");
orderShopEntity.setCover(shopEntity.getCover());
orderShopEntity.setShopId(shopEntity.getId());
orderShopEntity.setCustomerId(userEntity.getId());
orderShopService.insert(orderShopEntity);
shopEntity.setStock(shopEntity.getStock() - nums[i]);
shopService.updateById(shopEntity);
if (!StringUtils.isEmpty(shoppingGatEntity.getCid())) {
RoyaltyEntity royaltyEntity = new RoyaltyEntity();
royaltyEntity.setId(IdWorkerUtil.getId());
royaltyEntity.setCustomer(shoppingGatEntity.getCid());
royaltyEntity.setMark("订单下单抽取提成");
royaltyEntity.setTime(new Date());
royaltyEntity.setMoney(shopEntity.getRoyalty().multiply(new BigDecimal(shoppingGatEntity.getNum())));
royaltyService.insert(royaltyEntity);
/**
* 保存界面
* @param model
* @return
*/
@GetMapping("savePage.htm")
public String savePage(Model model){
return "childType/save";
}
/**
* 保存
* @param model
* @return
*/
@PostMapping("save.htm")
@ResponseBody
public Result savePage(Model model , ChildTypeEntity entity){
if(entity.getId()==null || entity.getId().equals("")){
entity.setId(IdWorker.get32UUID());
childTypeService.insert(entity);
}
return Result.success("用户保存成功");
}
}
/**
* 首页
*/
@Controller
public class HomeController {
@Autowired
private ShopTypeService shopTypeService;
String userId = jedis.get("WSY-USERID");
CustomerEntity customerEntity = customerService.selectById(userId);
customerEntity.setIntegral(integralInt);
customerService.updateById(customerEntity);
}
String orderId = jedis.get("WSY-ORDERID");
OrderEntity orderEntity = new OrderEntity();
orderEntity.setId(orderId);
orderEntity.setStatus(1);
orderService.updateById(orderEntity);
return "shoping/index";
}
}
@Controller
@RequestMapping("file")
public class ImgControllerNoCos {
public static final String FILE_PATH = System.getProperty("user.dir") + "\\src\\main\\resources\\static\\images\\";
static {
File file = new File(FILE_PATH);
file.mkdirs();
}
/**
* 文件上传返回code为200
* @param file
* @return
* @throws Exception
*/
@PostMapping("/upload")
@ResponseBody
for (String id : ids) {
list.add(id);
}
List<MenuEntity> menuEntities = menuService.selectBatchIds(list);
//删除原有权限
EntityWrapper entityWrapper = new EntityWrapper();
entityWrapper.eq(RoleMenuTable.ROLE_ID,roleId);
roleMenuService.delete(entityWrapper);
Set<String> set = new HashSet<>();
//循环添加新的权限
for (MenuEntity menuEntity : menuEntities) {
set.add(menuEntity.getPId());
}
for (String s : set) {
RoleMenuEntity roleMenuEntity = new RoleMenuEntity();
roleMenuEntity.setId(IdWorkerUtil.getId());
roleMenuEntity.setMenuId(s);
roleMenuEntity.setRoleId(roleId);
roleMenuService.insert(roleMenuEntity);
}
for (String s : list) {
RoleMenuEntity roleMenuEntity = new RoleMenuEntity();
roleMenuEntity.setId(IdWorkerUtil.getId());
roleMenuEntity.setMenuId(s);
roleMenuEntity.setRoleId(roleId);
roleMenuService.insert(roleMenuEntity);
}
return Result.success("权限保存成功");
}
}
OutputStream os=new FileOutputStream(file1.getPath());
//获取输入流 CommonsMultipartFile 中可以直接得到文件的流
InputStream is=file.getInputStream();
int temp;
//一个一个字节的读取并写入
while((temp=is.read())!=(-1))
{
os.write(temp);
}
os.flush();
os.close();
is.close();
InputStream inputStream = new FileInputStream(file1.getPath());
byte[] b = new byte[inputStream.available()];
inputStream.read(b);
} catch (FileNotFoundException e) {
e.printStackTrace();
return Result.error("上传文件失败");
}
return Result.success("/file/pic?pictureName="+fileName,"文件上传成功");
}
/**
* 获取本地图片
* @param pictureName //文件名
* @return
*/
@RequestMapping("/pic")
public void ShowImg(String pictureName, HttpServletRequest request, HttpServletResponse response) throws IOException {
//这里是存放图片的文件夹地址
FileInputStream fileIs=null;
OutputStream outStream = null;
try {
fileIs = new FileInputStream(FILE_PATH+"/"+pictureName);
//得到文件大小
int i=fileIs.available();
//准备一个字节数组存放二进制图片
byte data[]=new byte[i];
//读字节数组的数据
fileIs.read(data);
//设置返回的文件类型
response.setContentType("application/octet-stream;charset=UTF-8");
//得到向客户端输出二进制数据的对象
outStream=response.getOutputStream();
//输出数据
outStream.write(data);
outStream.flush();
} catch (Exception e) {
return;
}finally {
if(outStream!=null){
//关闭输出流
outStream.close();
//关闭输入流
public static final String FILE_PATH = System.getProperty("user.dir") + "\\src\\main\\resources\\static\\images\\";
static {
File file = new File(FILE_PATH);
file.mkdirs();
}
/**
* 文件上传返回code为200
* @param file
* @return
* @throws Exception
*/
@PostMapping("/upload")
@ResponseBody
public Result uplaod(@RequestParam("file") MultipartFile file)throws Exception {
//用来检测程序运行时间
String fileName = IdWorker.get32UUID() +file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
try {
File file1 = new File(FILE_PATH+"\\"+fileName);
file1.createNewFile();
//获取输出流
OutputStream os=new FileOutputStream(file1.getPath());
//获取输入流 CommonsMultipartFile 中可以直接得到文件的流
InputStream is=file.getInputStream();
int temp;
//一个一个字节的读取并写入
while((temp=is.read())!=(-1))
{
os.write(temp);
}
os.flush();
os.close();
is.close();
InputStream inputStream = new FileInputStream(file1.getPath());
byte[] b = new byte[inputStream.available()];
inputStream.read(b);
} catch (FileNotFoundException e) {
e.printStackTrace();
return Result.error("上传文件失败");
}
return Result.success("/file/pic?pictureName="+fileName,"文件上传成功");
}
/**
* 获取本地图片
* @param pictureName //文件名
* @return
*/
@RequestMapping("/pic")
public void ShowImg(String pictureName, HttpServletRequest request, HttpServletResponse response) throws IOException {
//这里是存放图片的文件夹地址
@Controller
@RequestMapping("shoppingGat")
public class ShoppingGatController {
@Autowired
private ShoppingGatService shoppingGatService;
@Autowired
private ShopService shopService;
@Autowired
private CustomerAddressService customerAddressService;
@Autowired
private CustomerService customerService;
@Autowired
private RoyaltyService royaltyService;
/**
* 购物车界面
* @param model
* @return
* @throws Exception
*/
@RequestMapping("list.do")
public String list(Model model)throws Exception{
CustomerEntity userEntity = Contants.getCustomer();
EntityWrapper entityWrapper = new EntityWrapper();
entityWrapper.eq(ShoppingGatTable.CUSTOMER_ID,userEntity.getId());
List<ShoppingGatEntity> gats = shoppingGatService.selectList(entityWrapper);
if(gats!=null ){
for (ShoppingGatEntity gat : gats) {
ShopEntity shopEntity = shopService.selectById(gat.getShopId());
gat.setShopEntity(shopEntity);
}
}
model.addAttribute("gats",gats);
CustomerEntity customerEntity = customerService.selectById(userEntity.getId());
model.addAttribute("integral",customerEntity.getIntegral());
List<CustomerAddressEntity> customerAddressEntities = customerAddressService.selectList(entityWrapper);
model.addAttribute("customerAddressEntities",customerAddressEntities);
// // 指定文件上传到 COS 上的路径,即对象键。例如对象键为folder/picture.jpg,则表示将文件 picture.jpg 上传到 folder 路径下
// String key = KEY + fileName;
// PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, file1);
// PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);
// } catch (Exception e) {
// e.printStackTrace();
// return Result.error("上传文件失败");
// }
// return Result.success(BASEURL + fileName, "文件上传成功");
// }
public static final String FILE_PATH = System.getProperty("user.dir") + "\\src\\main\\resources\\static\\images\\";
static {
File file = new File(FILE_PATH);
file.mkdirs();
}
/**
* 文件上传返回code为200
* @param file
* @return
* @throws Exception
*/
@PostMapping("/upload")
@ResponseBody
public Result uplaod(@RequestParam("file") MultipartFile file)throws Exception {
//用来检测程序运行时间
String fileName = IdWorker.get32UUID() +file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
try {
File file1 = new File(FILE_PATH+"\\"+fileName);
file1.createNewFile();
//获取输出流
OutputStream os=new FileOutputStream(file1.getPath());
//获取输入流 CommonsMultipartFile 中可以直接得到文件的流
InputStream is=file.getInputStream();
int temp;
//一个一个字节的读取并写入
while((temp=is.read())!=(-1))
{
os.write(temp);
}
os.flush();
os.close();
is.close();
InputStream inputStream = new FileInputStream(file1.getPath());
byte[] b = new byte[inputStream.available()];
inputStream.read(b);
} catch (FileNotFoundException e) {
e.printStackTrace();
return Result.error("上传文件失败");
* @return
* @throws Exception
*/
@RequestMapping("delete.do")
@ResponseBody
public Result delete(String id)throws Exception{
CustomerEntity userEntity = Contants.getCustomer();
if(StringUtils.isEmpty(id)){
EntityWrapper entityWrapper = new EntityWrapper();
entityWrapper.eq(ShoppingGatTable.CUSTOMER_ID,userEntity.getId());
shoppingGatService.delete(entityWrapper);
}else{
shoppingGatService.deleteById(id);
}
return Result.success("成功");
}
/**
* 添加到购物车
* @param shopId
* @return
* @throws Exception
*/
@RequestMapping("add.do")
@ResponseBody
public Result add(String shopId,Integer num,String customerId)throws Exception{
CustomerEntity userEntity = Contants.getCustomer();
EntityWrapper entityWrapper = new EntityWrapper();
entityWrapper.eq(ShoppingGatTable.CUSTOMER_ID,userEntity.getId())
.eq(ShoppingGatTable.SHOP_ID,shopId);
ShoppingGatEntity gatEntity = shoppingGatService.selectOne(entityWrapper);
if(gatEntity!=null){
gatEntity.setNum(gatEntity.getNum()+num);
shoppingGatService.updateById(gatEntity);
}else{
gatEntity = new ShoppingGatEntity();
gatEntity.setId(IdWorker.get32UUID());
gatEntity.setNum(num);
gatEntity.setShopId(shopId);
gatEntity.setCustomerId(userEntity.getId());
gatEntity.setCid(customerId);
shoppingGatService.insert(gatEntity);
}
* 登陆
* @return
* @throws Exception
*/
@RequestMapping("regData.html")
@ResponseBody
public Result regData( CustomerEntity customerEntity, HttpServletResponse response)throws Exception{
customerEntity.setId(IdWorkerUtil.getId());
customerEntity.setHeader("/img/a5.jpg");
customerService.insert(customerEntity);
Cookie cookie = new Cookie("login_key_auth_customer",customerEntity.getId());
cookie.setPath("/");
cookie.setMaxAge(3600000);
response.addCookie(cookie);
return Result.success(customerEntity.getId(),"登陆成功");
}
}
/**
@Controller
@RequestMapping("mobileCustomer")
public class MobileCustomerController {
@Autowired
private CustomerService customerService;
/**
* 我的界面
* @param model
* @return
* @throws Exception
*/
@RequestMapping("jump.html")
public String my(Model model,String url)throws Exception{
model.addAttribute("url",url);
return "mobile/jump";
}
/**
* 我的Data
* @param model
* @return
* @throws Exception
*/
@RequestMapping("infoData.do")
@ResponseBody
public Result infoData(Model model)throws Exception{
CustomerEntity customerEntity = Contants.getCustomer();
return Result.success(customerEntity);
}
/**
/**
* 文章
*/
@Controller
@RequestMapping("article")
public class ArticleController {
@Autowired
private ArticleService articleService;
@Autowired
private CustomerService customerService;
@Autowired
private ChildTypeService childTypeService;
@Autowired
private ArticleShopService articleShopService;
@Autowired
private ShopService shopService;
/**
* 界面
* @return
* @throws Exception
*/
@GetMapping("list.htm")
public String list(Model model)throws Exception{
return "article/list";
}
CustomerEntity customerEntity = customerService.selectOne(entityWrapper);
if(customerEntity==null){
return Result.error("用户不存在");
}
if(!customerEntity.getPassword().equals(password)){
return Result.error("密码错误");
}
Cookie cookie = new Cookie("login_key_auth_customer",customerEntity.getId());
cookie.setPath("/");
cookie.setMaxAge(3600000);
response.addCookie(cookie);
return Result.success(customerEntity.getId(),"登陆成功");
}
/**
* 登陆界面
* @param model
* @return
* @throws Exception
*/
@RequestMapping("reg.html")
public String reg(Model model) throws Exception{
return "mobile/reg";
}
/**
* 登陆
* @return
* @throws Exception
*/
@RequestMapping("regData.html")
@ResponseBody
public Result regData( CustomerEntity customerEntity, HttpServletResponse response)throws Exception{
customerEntity.setId(IdWorkerUtil.getId());
customerEntity.setHeader("/img/a5.jpg");
customerService.insert(customerEntity);
Cookie cookie = new Cookie("login_key_auth_customer",customerEntity.getId());
cookie.setPath("/");
cookie.setMaxAge(3600000);
public class ImgControllerNoCos {
public static final String FILE_PATH = System.getProperty("user.dir") + "\\src\\main\\resources\\static\\images\\";
static {
File file = new File(FILE_PATH);
file.mkdirs();
}
/**
* 文件上传返回code为200
* @param file
* @return
* @throws Exception
*/
@PostMapping("/upload")
@ResponseBody
public Result uplaod(@RequestParam("file") MultipartFile file)throws Exception {
//用来检测程序运行时间
String fileName = IdWorker.get32UUID() +file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
try {
File file1 = new File(FILE_PATH+"\\"+fileName);
file1.createNewFile();
//获取输出流
OutputStream os=new FileOutputStream(file1.getPath());
//获取输入流 CommonsMultipartFile 中可以直接得到文件的流
InputStream is=file.getInputStream();
int temp;
//一个一个字节的读取并写入
while((temp=is.read())!=(-1))
{
os.write(temp);
}
os.flush();
os.close();
is.close();
InputStream inputStream = new FileInputStream(file1.getPath());
byte[] b = new byte[inputStream.available()];
inputStream.read(b);
} catch (FileNotFoundException e) {
e.printStackTrace();
return Result.error("上传文件失败");
}
orderShopEntity.setName(shopEntity.getName());
name = name.concat(shopEntity.getName() + "+");
orderShopEntity.setCover(shopEntity.getCover());
orderShopEntity.setShopId(shopEntity.getId());
orderShopEntity.setCustomerId(userEntity.getId());
orderShopService.insert(orderShopEntity);
shopEntity.setStock(shopEntity.getStock() - nums[i]);
shopService.updateById(shopEntity);
if (!StringUtils.isEmpty(shoppingGatEntity.getCid())) {
RoyaltyEntity royaltyEntity = new RoyaltyEntity();
royaltyEntity.setId(IdWorkerUtil.getId());
royaltyEntity.setCustomer(shoppingGatEntity.getCid());
royaltyEntity.setMark("订单下单抽取提成");
royaltyEntity.setTime(new Date());
royaltyEntity.setMoney(shopEntity.getRoyalty().multiply(new BigDecimal(shoppingGatEntity.getNum())));
royaltyService.insert(royaltyEntity);
}
}
jedis.set("WSY-SHOPID", name);
return Result.success("订单结算成功");
}
}
/**
* Created by Wsy
*/
@Controller
@RequestMapping("fileNoCos")
* @throws Exception
*/
@RequestMapping("jump.html")
public String my(Model model,String url)throws Exception{
model.addAttribute("url",url);
return "mobile/jump";
}
/**
* 我的Data
* @param model
* @return
* @throws Exception
*/
@RequestMapping("infoData.do")
@ResponseBody
public Result infoData(Model model)throws Exception{
CustomerEntity customerEntity = Contants.getCustomer();
return Result.success(customerEntity);
}
/**
* 我的界面
* @param model
* @return
* @throws Exception
*/
@RequestMapping("info.do")
public String info(Model model)throws Exception{
CustomerEntity customerEntity = Contants.getCustomer();
model.addAttribute("customer",customerEntity);
return "mobile/my";
}
/**
* 我的界面 -- 修改
* @param model
* @return
* @throws Exception
*/
@RequestMapping("myUpdate.do")
public String my_update(Model model)throws Exception{
CustomerEntity customerEntity = Contants.getCustomer();
model.addAttribute("entity",customerEntity);
@Controller
@RequestMapping("royalty")
public class RoyaltyController {
@Autowired
private RoyaltyService royaltyService;
@Autowired
private CustomerService customerService;
/**
* 列表界面
* @param model
* @return
* @throws Exception
*/
@RequestMapping("list.do")
public String list(Model model)throws Exception{
EntityWrapper entityWrapper = new EntityWrapper();
entityWrapper.eq("customer",Contants.getCustomer().getId());
entityWrapper.orderBy("time",false);
List<RoyaltyEntity> list = royaltyService.selectList(entityWrapper);
model.addAttribute("list",list);
BigDecimal all = new BigDecimal(0);
if(list!=null){
for (RoyaltyEntity royaltyEntity : list) {
all = all.add(royaltyEntity.getMoney());
}
}
model.addAttribute("all",all);
return "mobile/royalty";
}
/**
* 用户提取佣金
* @param money
* @return
* @throws Exception
*/
@RequestMapping("tiqu.do")
@ResponseBody
public Result tiqu(String money)throws Exception{
RoyaltyEntity royaltyEntity = new RoyaltyEntity();
String id = Contants.getCustomer().getId();
BigDecimal bigDecimal = new BigDecimal(money);