基于javaweb+mysql的springboot优咪商城系统(java+springboot+html+bootstrap+layui+maven+mysql)

基于javaweb+mysql的springboot优咪商城系统(java+springboot+html+bootstrap+layui+maven+mysql)

私信源码获取及调试交流

运行环境

Java≥8、MySQL≥5.7

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

基于javaweb的SpringBoot优咪商城系统(java+springboot+html+bootstrap+layui+maven+mysql)


管理员(user表):

admin   123456

普通用户(customer表):

13511111111	123456

13522222222	123456

前台用户:浏览商品、购物、收货评价等

后台管理员:管理商品、类型、订单等

环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。

2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;

3.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;

4.数据库:MySql 5.7版本;

技术栈

  1. 后端:Springboot

  2. 前端:html+bootstrap+jQuery+layui+ueditor

使用说明

运行项目 前台地址:http://localhost:8080/

后台浏览地址:http://localhost:8080/login.html


/**
 */
@Controller
@RequestMapping("file")
public class ImgController {
    public static final String FILE_PATH = System.getProperty("user.dir") + "\\src\\main\\resources\\static\\image_upload\\";

    /**
     * 文件上传返回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);

/**
 * 商品管理
 */
@Controller
@RequestMapping("customer")
public class CustomerController {

    @Autowired
    private CustomerService service;

    /**
     * 界面
     * @param model
     * @return
     */
    @RequestMapping("list.htm")
    public String list(Model model){
        List<CustomerEntity> list = service.selectList(new EntityWrapper<>());
        model.addAttribute("list",list);
        return "customer/list";
    }

    /**
     * 保存界面
     * @param model
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping("save.htm")
    public String save(Model model,String id)throws Exception{
        CustomerEntity entity = new CustomerEntity();
        if(!StringUtils.isEmpty(id)){
            entity = service.selectById(id);
        }
        model.addAttribute("entity",entity);
        return "customer/save";
    }

    /**
     * 保存
     * @param model
        }
    }
}

/**
 * 商品管理
 */
@Controller
@RequestMapping("shop")
public class ShopController {

    @Autowired
    private ShopService service;

    @Autowired
    private ShopTypeService shopTypeService;

    /**
     * 界面
     * @param model
     * @return
     */
    @RequestMapping("list.htm")
    public String list(Model model){
        if(articleEntities!=null && !articleEntities.isEmpty()){
            for (ArticleEntity articleEntity : articleEntities) {
                articleEntity.setCustomerName("系统发布");
                CustomerEntity userEntity = customerService.selectById(articleEntity.getCustomerId());
                articleEntity.setCustomerEntity(userEntity);
                ChildTypeEntity childTypeEntity = childTypeService.selectById(articleEntity.getChildType());
                if(childTypeEntity!=null){
                    articleEntity.setChildName(childTypeEntity.getName());
                }
            }
        }
        model.addAttribute("articleEntities",articleEntities);

        return "mobile/articleHome";
    }

}


    /**
     * 界面
     * @param model
     * @return
     */
    @RequestMapping("list.htm")
    public String list(Model model){
        List<CustomerEntity> list = service.selectList(new EntityWrapper<>());
        model.addAttribute("list",list);
        return "customer/list";
    }

    /**
     * 保存界面
     * @param model
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping("save.htm")
    public String save(Model model,String id)throws Exception{
        CustomerEntity entity = new CustomerEntity();
        if(!StringUtils.isEmpty(id)){
            entity = service.selectById(id);
        }
        model.addAttribute("entity",entity);
        return "customer/save";
    }

    /**
     * 保存
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("saveData.htm")
    @ResponseBody
    public Result save(Model model, CustomerEntity entity)throws Exception{
        if(StringUtils.isEmpty(entity.getId())){
            entity.setId(IdWorkerUtil.getId());
            service.insert(entity);
        }else{
            if(entity.getAuthStatus()==2){
                entity.setType(2);
            }
            service.updateById(entity);
        articleEntity.setTop(false);
        articleService.insert(articleEntity);
        return Result.success("保存成功");
    }

    /**
     * 界面
     * @return
     * @throws Exception
     */
    @GetMapping("edit.do")
    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 "mobile/article/edit";
    }

    /**
     * 保存数据
     * @return
     * @throws Exception
     */
    @RequestMapping("editData.do")
    @ResponseBody
    public Result editData(ArticleEntity articleEntity)throws Exception{
        articleService.updateById(articleEntity);
        return Result.success("保存成功");
    }

}

     * @throws Exception
     */
    @GetMapping("list.do")
    public String list(Model model)throws Exception{
        return "mobile/article/list";
    }

    /**
     * 分页
     * @return
     * @throws Exception
     */
    @GetMapping("page.do")
    @ResponseBody
    public PageVo page(String title, String  summary,int page , int limit)throws Exception{
        EntityWrapper entityWrapper = new EntityWrapper();
        if(!StringUtils.isEmpty(title)){
            entityWrapper.like(ArticleTable.TITLE,title);
        }
        if(!StringUtils.isEmpty(summary)){
            entityWrapper.like(ArticleTable.SUMMARY,summary);
        }
        entityWrapper.eq(ArticleTable.CUSTOMER_ID, Contants.getCustomer().getId());
        entityWrapper.orderBy("time",false);
        Page<ArticleEntity> paged = new Page();
        paged.setSize(limit);
        paged.setCurrent(page);
        Page<ArticleEntity> userTablePage = articleService.selectPage(paged, entityWrapper);

        List<ArticleEntity> list = userTablePage.getRecords();
        if(list!=null && !list.isEmpty()){
            for (ArticleEntity articleEntity : list) {
                ChildTypeEntity childTypeEntity = childTypeService.selectById(articleEntity.getChildType());
                if(childTypeEntity!=null){
                    articleEntity.setChildName(childTypeEntity.getName());
                }
            }
        }
        PageVo<ArticleEntity> pageVo = new PageVo<>();
        pageVo.setCode(0);
        pageVo.setCount(paged.getTotal());
        pageVo.setData(list);

/**
 * 活动
 */
@Controller
@RequestMapping("activity")
public class ActivityController {

    @Autowired
    private ActivityService service;

    /**
     * 界面
     * @param model
     * @return
     */
    @RequestMapping("list.htm")
    public String list(Model model){
        List<ActivityEntity> list = service.selectList(new EntityWrapper<>());
        model.addAttribute("list",list);
        return "activity/list";
    }

    /**
     * 保存界面
     * @param model
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping("save.htm")
    public String save(Model model,String id)throws Exception{
        ActivityEntity entity = new ActivityEntity();
        if(!StringUtils.isEmpty(id)){
            entity = service.selectById(id);
        }
        model.addAttribute("entity",entity);
        return "activity/save";
    }

    /**
     * 保存
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("saveData.htm")
    @ResponseBody

@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{
        CustomerEntity customerEntity = Contants.getCustomer();
        EntityWrapper wrapper = new EntityWrapper();
        wrapper.eq(CustomerAddressTable.CUSTOMER_ID,customerEntity.getId());
        List<CustomerAddressEntity> list = service.selectList(wrapper);
        model.addAttribute("list",list);
        return "mobile/address_list";
    }

    /**
     * 保存界面
     * @param model
     * @param id
    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {

        String uid = "";
        Cookie[] cookies =  httpServletRequest.getCookies();
        if(cookies==null || cookies.length==0){
        }else{
            for (Cookie cookie : cookies) {
                if(cookie.getName().equals("login_key_auth_customer")){
                    uid = cookie.getValue();
                }
            }
        }
        CustomerEntity userEntity = customerService.selectById(uid);
        if(userEntity==null){
            httpServletRequest.setAttribute("loginFlag",false);
        }else{
            httpServletRequest.setAttribute("loginFlag",true);
            httpServletRequest.setAttribute("loginCustomer",userEntity);
            Cookie cookie = new Cookie("login_key_auth_customer",userEntity.getId());
            cookie.setPath("/");
            cookie.setMaxAge(3600000);
            httpServletResponse.addCookie(cookie);
        }
        Contants.CUSTOMER_ENTITY_THREAD_LOCAL.set(userEntity);
        if(!httpServletRequest.getRequestURI().endsWith("do")){
            return true;
        }else{
            if(userEntity==null){
                throw new NeedLoginException("需要登录");
            }
        }
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {

    }
}

        userEntity.setSex(true);
        userEntity.setStatus(true);
        if(!StringUtils.isEmpty(id)){
            userEntity = userService.selectById(id);
        }
        model.addAttribute("userEntity",userEntity);
        return "user/save";
    }

    /**
     * 保存
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("saveData.htm")
    @ResponseBody
    @ImLog(type = "用户",mark = "保存用户 {name}")
    public Result save(Model model, UserEntity userEntity)throws Exception{
        if(StringUtils.isEmpty(userEntity.getId())){
            userEntity.setId(IdWorker.get32UUID());
            userEntity.setTime(new Date());
            userService.insert(userEntity);
        }else{
            userService.updateById(userEntity);
        }
        return Result.success("保存成功");
    }

    /**
     * 保存
     * @param model
     * @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
public class LoginController {

    @Autowired
    private UserService userService;

    @Autowired
    private RoleService roleService;

    /**
     * 登录
     * @return
     */
    @GetMapping("login.html")
    public String login(){
        return "login";
    }

    /**
     * 登录
     * @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")
        cookie.setPath("/");
        cookie.setMaxAge(0);
        response.addCookie(cookie);
        return Result.success("退出成功");
    }

    /**
     * 登陆
     * @return
     * @throws Exception
     */
    @RequestMapping("loginData.html")
    @ResponseBody
    public Result loginData(String phone,String password, HttpServletResponse response)throws Exception{
        EntityWrapper entityWrapper = new EntityWrapper();
        entityWrapper.eq("phone",phone);
        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
     */
    @Autowired
    private ShoppingGatService shoppingGatService;

    @Autowired
    private ShopService shopService;

    @Autowired
    private CustomerAddressService customerAddressService;

    @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);
       List<CustomerAddressEntity> customerAddressEntities =   customerAddressService.selectList(entityWrapper);
        model.addAttribute("customerAddressEntities",customerAddressEntities);
        return "mobile/gat";
    }

    /**
     * 删除
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping("delete.do")
    @ResponseBody
    public Result delete(String id)throws Exception{
        CustomerEntity userEntity = Contants.getCustomer();
@Controller
@RequestMapping("activity")
public class ActivityController {

    @Autowired
    private ActivityService service;

    /**
     * 界面
     * @param model
     * @return
     */
    @RequestMapping("list.htm")
    public String list(Model model){
        List<ActivityEntity> list = service.selectList(new EntityWrapper<>());
        model.addAttribute("list",list);
        return "activity/list";
    }

    /**
     * 保存界面
     * @param model
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping("save.htm")
    public String save(Model model,String id)throws Exception{
        ActivityEntity entity = new ActivityEntity();
        if(!StringUtils.isEmpty(id)){
            entity = service.selectById(id);
        }
        model.addAttribute("entity",entity);
        return "activity/save";
    }

    /**
     * 保存
     * @param model
     * @return
            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();
                //关闭输入流
                fileIs.close();
            }
        }
    }
}

            orderShopEntity.setId(IdWorkerUtil.getId());
            orderShopEntity.setPrice(new BigDecimal(prices[i]));
            orderShopEntity.setNum(nums[i]);
            orderShopEntity.setOrderId(orderEntity.getId());
            orderShopEntity.setName(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);
            shoppingGatService.deleteById(ids[i]);
            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);
            }
        }
        return Result.success("订单结算成功");
    }

}

@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);
    }

    /**
     * 我的界面
     * @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

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

  • 10
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值