基于javaweb+mysql的springboot在线蛋糕销售商城(java+springboot+maven+mysql+thymeleaf+html+redis)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的SpringBoot在线蛋糕销售商城(java+springboot+maven+mysql+thymeleaf+html+redis)
一、项目简述
功能: 主页显示商品; 所有蛋糕商品展示,可进行商品搜索; 点击商品进入商品详情页,具有立即购买功能,可增减购买商品数量亦可手动输入,热销商品展示。 立即购买进入确认订单页面,可选择已经添加的地址,亦可新增地址。 可选择购买哪些商品,可删除不需要的商品。 点击结算进入确认订单页面,确认后提交订单。后台管理:(修改密码等),商品管理(商品批量添加、上下架等),订单管理。
二、项目运行
环境配置:
Jdk1.8 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
项目技术:
JSP +Springboot+ SpringMVC + MyBatis + ThymeLeaf + FTP+ JavaScript + JQuery + Ajax + maven等等
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("article")
return "role/auth";
}
/**
* 权限分配
* @param ids
* @param model
* @return
* @throws Exception
*/
@RequestMapping("authData.htm")
@ResponseBody
@ImLog(type = "角色",mark = "角色分配权限 {id} {ids}")
public Result data(String[] ids,String roleId,Model model)throws Exception{
List<String> list = new ArrayList<>();
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("权限保存成功");
}
}
public class MobileShopController {
@Autowired
private ShopService shopService;
@Autowired
private OrderShopDao orderShopDao;
@Autowired
private ArticleService articleService;
@RequestMapping("info.html")
public String info(String id,String customerId, Model model)throws Exception{
ShopEntity shopEntity = shopService.selectById(id);
model.addAttribute("shop",shopEntity);
model.addAttribute("id",id);
List<OrderShopEntity> list = orderShopDao.list(id);
model.addAttribute("list",list);
model.addAttribute("customerId",customerId);
return "mobile/shop_info";
}
/**
* @param id
* @return
* @throws Exception
*/
@RequestMapping("aList.html")
@ResponseBody
public Result shopList(String id)throws Exception{
ShopEntity shopEntity = shopService.selectById(id);
if(StringUtils.isEmpty(shopEntity.getLabel())){
return Result.success("无");
}
String[] lebel = shopEntity.getLabel().split(",");
//查询
List<String> ids = new ArrayList<>();
for (String s : lebel) {
EntityWrapper wrapper = new EntityWrapper();
/**
* @param id
* @return
* @throws Exception
*/
@RequestMapping("aList.html")
@ResponseBody
public Result shopList(String id)throws Exception{
ShopEntity shopEntity = shopService.selectById(id);
if(StringUtils.isEmpty(shopEntity.getLabel())){
return Result.success("无");
}
String[] lebel = shopEntity.getLabel().split(",");
//查询
List<String> ids = new ArrayList<>();
for (String s : lebel) {
EntityWrapper wrapper = new EntityWrapper();
wrapper.like("label",s);
List<ArticleEntity> shops = articleService.selectList(wrapper);
if(shops!=null){
for (ArticleEntity shop : shops) {
ids.add(shop.getId());
}
}
}
EntityWrapper wrapper = new EntityWrapper();
wrapper.in("id",ids).orderBy("rand()");
List<ArticleEntity> shops = articleService.selectList(wrapper);
if(shops!=null){
if(shops.size()>3){
shops = shops.subList(0,3);
}
}
return Result.success(shops);
}
}
public String list(Model model) throws Exception {
CustomerEntity userEntity = Contants.getCustomer();
EntityWrapper wrapper = new EntityWrapper();
wrapper.eq(OrderTable.CUSTOMER_ID, userEntity.getId()).orderBy("time", false);
List<OrderEntity> orders = orderService.selectList(wrapper);
if (orders != null) {
for (OrderEntity order : orders) {
wrapper = new EntityWrapper();
wrapper.eq("order_id", order.getId());
List<OrderShopEntity> orderShops = orderShopService.selectList(wrapper);
order.setOrderShops(orderShops);
}
}
model.addAttribute("orders", orders);
return "mobile/orderList";
}
/**
* 订单结算
*
* @param ids 购物车ids
* @param nums 数量
* @return
* @throws Exception
*/
@RequestMapping("jiesuan.do")
@ResponseBody
public Result jiesuan(String ids[], Integer nums[], String prices[], OrderEntity orderEntity, String addressId) throws Exception {
CustomerEntity userEntity = Contants.getCustomer();
String orderId = IdWorkerUtil.getId();
jedis.set("WSY-ORDERID", orderId);
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]);
model.addAttribute("lebels",lebel);
CustomerEntity customerEntity = customerService.selectById(articleEntity.getCustomerId());
model.addAttribute("customerEntity",customerEntity);
if(!StringUtils.isEmpty(articleEntity.getShopIds())){
String articles[] = articleEntity.getShopIds().split(",");
List<String> str = new ArrayList<>();
for (String article : articles) {
str.add(article);
}
List<ShopEntity> shopEntities = shopService.selectBatchIds(str);
model.addAttribute("shopEntities",shopEntities);
}
return "article/info";
}
/**
* 界面
* @return
* @throws Exception
*/
@GetMapping("edit.htm")
public String edit(String id, Model model )throws Exception{
ArticleEntity articleEntity = articleService.selectById(id);
model.addAttribute("articleEntity",articleEntity);
List<ShopEntity> shopEntities = shopService.selectList(new EntityWrapper<>());
model.addAttribute("shopEntities",shopEntities);
return "article/edit";
}
/**
* 保存数据
* @return
* @throws Exception
*/
@RequestMapping("editData.htm")
@ResponseBody
public Result editData(ArticleEntity articleEntity)throws Exception{
articleService.updateById(articleEntity);
return Result.success("保存成功");
}
}
/**
* 用户提取佣金
* @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);
royaltyEntity.setId(IdWorkerUtil.getId());
royaltyEntity.setCustomer(id);
royaltyEntity.setMark("用户提取佣金");
royaltyEntity.setTime(new Date());
royaltyEntity.setMoney(bigDecimal);
royaltyService.insert(royaltyEntity);
CustomerEntity customerEntity = customerService.selectById(id);
money = money.replace("-","");
Integer integer = Integer.valueOf(money);
customerEntity.setIntegral(customerEntity.getIntegral()+integer/10);
customerService.updateById(customerEntity);
return Result.success("提取成功");
}
}
@Controller
@RequestMapping("mobileShop")
public class MobileShopController {
@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);
royaltyEntity.setId(IdWorkerUtil.getId());
royaltyEntity.setCustomer(id);
royaltyEntity.setMark("用户提取佣金");
royaltyEntity.setTime(new Date());
service.updateById(entity);
}
return Result.success("保存成功");
}
/**
* 删除
* @param id
* @return
* @throws Exception
*/
@PostMapping("del.do")
@ResponseBody
public Result del(String id)throws Exception{
service.deleteById(id);
return Result.success("保存成功");
}
}
@Controller
@RequestMapping("royalty")
public class RoyaltyController {
@Autowired
private RoyaltyService royaltyService;
@Autowired
private CustomerService customerService;
/**
* 列表界面
* @param model
* @return
* @throws Exception
*/
@RequestMapping("list.do")
}
/**
* 登录
* @return
*/
@GetMapping("logout.htm")
public String logout(HttpServletResponse response){
Cookie cookie = new Cookie("login_key_auth","");
cookie.setPath("/");
cookie.setMaxAge(0);
response.addCookie(cookie);
return "redirect:/login.html";
}
/**
* 登录
* @param loginName
* @param password
* @return
* @throws Exception
*/
@PostMapping("loginData.html")
@ResponseBody
@ImLog(type = "登录",mark = "用户 {loginName} 登录")
public Result loginData(String loginName, String password, HttpServletResponse response)throws Exception{
EntityWrapper entityWrapper = new EntityWrapper();
entityWrapper.eq(UserTable.LOGIN_NAME,loginName);
UserEntity userEntity = userService.selectOne(entityWrapper);
if(userEntity==null){
return Result.error("用户名或密码错误");
}
if(!password.equals(userEntity.getPassword())){
return Result.error("用户名或密码错误");
}
RoleEntity roleEntity = roleService.selectById(userEntity.getRoleId());
if(roleEntity==null || roleEntity.getStatus()==false ){
return Result.error("用户无角色可用");
}
Cookie cookie = new Cookie("login_key_auth",userEntity.getId());
cookie.setPath("/");
cookie.setMaxAge(3600000);
response.addCookie(cookie);
return Result.success("登录成功");
}
}
* @return
* @throws Exception
*/
@RequestMapping("del.htm")
@ResponseBody
@ImLog(type = "用户",mark = "删除用户 {id}")
public Result del(Model model, String id )throws Exception{
userService.deleteById(id);
return Result.success("保存成功");
}
}
@Controller
@RequestMapping("customerAddress")
public class CustomerAddressController {
@Autowired
private CustomerAddressService service;
/**
* 列表界面
* @param model
* @return
* @throws Exception
*/
@RequestMapping("list.do")
public String list(Model model)throws Exception{
这里建议设置使用 https 协议
// clientConfig.setHttpProtocol(HttpProtocol.https);
// // 3 生成 cos 客户端。
// COSClient cosClient = new COSClient(cred, clientConfig);
// // 指定要上传的文件
// // 指定文件将要存放的存储桶
// String bucketName = BUCKETNAME;
// // 指定文件上传到 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))
*/
@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
outStream.write(data);
outStream.flush();
} catch (Exception e) {
return;
}finally {
if(outStream!=null){
//关闭输出流
outStream.close();
//关闭输入流
fileIs.close();
}
}
}
}
/**
* 商品管理
*/
@Controller
@RequestMapping("shop")
public class ShopController {
@Autowired
private ShopService service;
@Autowired
private ShopTypeService shopTypeService;
/**
* 界面
}
/**
* 界面
* @return
* @throws Exception
*/
@GetMapping("add.htm")
public String add(Model model)throws Exception{
List<ShopEntity> shopEntities = shopService.selectList(new EntityWrapper<>());
model.addAttribute("shopEntities",shopEntities);
return "article/add";
}
/**
* 保存数据
* @return
* @throws Exception
*/
@RequestMapping("addData.htm")
@ResponseBody
public Result addDatax(ArticleEntity articleEntity, HttpSession session)throws Exception{
articleEntity.setId(IdWorkerUtil.getId());
articleEntity.setTime(new Date());
articleEntity.setStatus(1);
articleEntity.setCustomerId("-1");
articleService.insert(articleEntity);
return Result.success("保存成功");
}
/**
* 根据文章ID推荐商品
* @param id
* @return
* @throws Exception
*/
@RequestMapping("shopList.html")
@ResponseBody
public Result shopList(String id)throws Exception{
ArticleEntity articleEntity = articleService.selectById(id);
if(StringUtils.isEmpty(articleEntity.getLabel())){
/**
* 保存界面
* @param model
* @param id
* @return
* @throws Exception
*/
@RequestMapping("save.do")
public String save(Model model,String id)throws Exception{
CustomerAddressEntity entity = new CustomerAddressEntity();
if(!StringUtils.isEmpty(id)){
entity = service.selectById(id);
}
model.addAttribute("entity",entity);
return "mobile/address_save";
}
/**
* 保存
* @param model
* @return
* @throws Exception
*/
@RequestMapping("saveData.do")
@ResponseBody
public Result save(Model model, CustomerAddressEntity entity)throws Exception{
CustomerEntity customerEntity = Contants.getCustomer();
entity.setCustomerId(customerEntity.getId());
if(StringUtils.isEmpty(entity.getId())){
entity.setId(IdWorkerUtil.getId());
service.insert(entity);
}else{
service.updateById(entity);
}
return Result.success("保存成功");
}
/**
* 删除
* @param id
* @return
* @throws Exception
*/
@PostMapping("del.do")
@ResponseBody
public Result del(String id)throws Exception{
service.deleteById(id);
return Result.success("保存成功");
}
}
* @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 {
//这里是存放图片的文件夹地址
FileInputStream fileIs=null;
OutputStream outStream = null;
try {
fileIs = new FileInputStream(FILE_PATH+"/"+pictureName);
//得到文件大小
int i=fileIs.available();
//准备一个字节数组存放二进制图片
byte data[]=new byte[i];