基于javaweb+mysql的springboot网上超市线上购物系统(java+springboot+maven+mysql+thymeleaf+html)

基于javaweb+mysql的springboot网上超市线上购物系统(java+springboot+maven+mysql+thymeleaf+html)

私信源码获取及调试交流

运行环境

Java≥8、MySQL≥5.7

开发工具

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

适用

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

功能说明

基于javaweb的SpringBoot网上超市线上购物系统(java+springboot+maven+mysql+thymeleaf+html)

管理员:

admin 123456

用户:

13511111111 123456

13511111112 123456

13511111113 123456

    @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
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserDao userDao;

    @Autowired
    private RoleService roleService;

    @Autowired
    private UserService userService;

    /**
    @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("shoppingGat")
public class ShoppingGatController {
        CustomerEntity customerEntity = Contants.getCustomer();
        model.addAttribute("entity",customerEntity);
        return "mobile/my_update";
    }

    /**
     * 我的界面 -- 修改
     * @return
     * @throws Exception
     */
    @RequestMapping("myUpdateData.do")
    @ResponseBody
    public Result myUpdateData( CustomerEntity customerEntity)throws Exception{
        customerEntity.setId(Contants.getCustomer().getId());
        customerService.updateById(customerEntity);
        return Result.success("成功");
    }

    /**
     * 登陆界面
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("login.html")
    public String login(Model model) throws Exception{
        return "mobile/login";
    }

    /**
     * 退出登陆
     * @return
     * @throws Exception
     */
    @RequestMapping("logOut.do")
    @ResponseBody
    public Result logOut( HttpServletResponse response)throws Exception{
        Cookie cookie = new Cookie("login_key_auth_customer","-1");
        cookie.setPath("/");
        cookie.setMaxAge(0);
        response.addCookie(cookie);
        return Result.success("退出成功");
    }

    /**
     * 登陆
     * @return
        orderShopService.updateById(orderShopEntity);
        orderShopEntity = orderShopService.selectById(orderShopEntity.getId());
        Double num = orderShopDao.num(orderShopEntity.getShopId());
        ShopEntity shopEntity = new ShopEntity();
        shopEntity.setId(orderShopEntity.getShopId());
        shopEntity.setScore(num);
        shopService.updateById(shopEntity);
        return Result.success(1);
    }

    /**
     * 收货
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping("shouhuo.do")
    @ResponseBody
    public Result shouhuo(String id)throws Exception{
        OrderEntity orderEntity = orderService.selectById(id);
        orderEntity.setStatus(3);
        orderService.updateById(orderEntity);
        return Result.success("欢迎下次光临");
    }

    /**
     *
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("list.do")
    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());
        model.addAttribute("menuEntities",menuEntities);
        model.addAttribute("roleId",id);
        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("权限保存成功");
    }

}

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

       
     
        PageVo<ArticleEntity> pageVo = new PageVo<>();
        pageVo.setCode(0);
        pageVo.setCount(paged.getTotal());
     
        pageVo.setPageNum(limit);
        pageVo.setPageSize(page);
        return pageVo;

    }

    /**
     * 界面
     * @return
     * @throws Exception

    /**
     * 保存数据
     * @return
     * @throws Exception
     */
    @RequestMapping("addData.do")
    @ResponseBody
    public Result addDatax(ArticleEntity articleEntity, HttpSession session)throws Exception{
        articleEntity.setId(IdWorkerUtil.getId());
        articleEntity.setTime(new Date());
        articleEntity.setStatus(0);
        articleEntity.setCustomerId(Contants.getCustomer().getId());
        articleEntity.setTop(false);
        return Result.success("保存成功");
    }

    /**
     * 界面
     * @return
     * @throws Exception
     */
    @GetMapping("edit.do")
    public String edit(String id, Model model )throws Exception{
        List<ShopEntity> shopEntities =  shopService.selectList(new EntityWrapper<>());
        model.addAttribute("shopEntities",shopEntities);
        return "mobile/article/edit";
    }

}

/**
    }

    @PostMapping("list.do")
    public Result list()throws Exception{
        //首先查询帮助信息
        EntityWrapper entityWrapper = new EntityWrapper();
        //消息列表
        entityWrapper
                .eq("user_id", Contants.getCustomer().getId())
                .orderBy("time",true);
        List<ChatRoomEntity> list = chatRoomService.selectList(entityWrapper);
        for (ChatRoomEntity chatRoomEntity : list) {
            chatRoomEntity.setBr(chatRoomEntity.getSendUser().equals(Contants.getCustomer().getId()));
        }
        return Result.success(list);
    }

    /**
     * 发送消息
     * @param chatRoomEntity
     * @return
     */
    @RequestMapping("addContent.do")
    public Result addContent(ChatRoomEntity chatRoomEntity){
        //首先查询帮助信息
        chatRoomEntity.setId(IdWorker.get32UUID());
        chatRoomEntity.setRead(false);
        chatRoomEntity.setSendUser(Contants.getCustomer().getId());
        chatRoomEntity.setUserId(Contants.getCustomer().getId());
        chatRoomEntity.setAssistUserId("-99");
        chatRoomEntity.setTime(new Date());
        chatRoomService.insert(chatRoomEntity);
        return Result.success("发送成功");
    }
}

    private CustomerService customerService;

    @Autowired
    private ChildTypeService childTypeService;

    @Autowired
    private ShopService shopService;

    /**
     * 界面
     * @return
     * @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);

       
     
        PageVo<ArticleEntity> pageVo = new PageVo<>();
        pageVo.setCode(0);
        pageVo.setCount(paged.getTotal());
     
        pageVo.setPageNum(limit);
        pageVo.setPageSize(page);
        return pageVo;

    }

        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
     */
    @RequestMapping("regData.html")
    @ResponseBody
    public Result regData( CustomerEntity customerEntity, HttpServletResponse response)throws Exception{
        customerEntity.setId(IdWorkerUtil.getId());
        customerEntity.setHeader("/img/a5.jpg");
        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("用户保存成功");
    }

}

        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
     * @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("用户保存成功");
    }

}

@Controller
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserDao userDao;

    @Autowired
    private RoleService roleService;

    @Autowired
    private UserService userService;

    /**
     * 用户界面
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("list.htm")
            return true;
        }
        Cookie[] cookies =  httpServletRequest.getCookies();
        if(cookies==null || cookies.length==0){
            throw new NeedLoginException("需要登录");
        }
        String uid = "";
        for (Cookie cookie : cookies) {
            if(cookie.getName().equals("login_key_auth")){
                uid = cookie.getValue();
            }
        }
        if(StringUtils.isEmpty(uid)){
            throw new NeedLoginException("需要登录");
        }
        UserEntity userEntity = userService.selectById(uid);
        if(userEntity==null || userEntity.getStatus()==false){
            throw new NeedLoginException("需要登录");
        }
        Contants.USER_ENTITY_THREAD_LOCAL.set(userEntity);
        Cookie cookie = new Cookie("login_key_auth",userEntity.getId());
        cookie.setPath("/");
        cookie.setMaxAge(3600000);
        httpServletResponse.addCookie(cookie);
        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 {

    }
}

        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}")
    public Result del(String id)throws Exception{
        roleService.deleteById(id);
        return Result.success("保存成功");
    }

    /**
     * 权限界面
     * @return
     * @throws Exception
     */
    @RequestMapping("auth.htm")
    public String auth(String id,Model model)throws Exception{
        EntityWrapper entityWrapper = new EntityWrapper();
        entityWrapper.eq(RoleMenuTable.ROLE_ID,id);
        List<RoleMenuEntity> entity = roleMenuService.selectList(entityWrapper);

        List<MenuEntity> menuEntities = menuService.selectList(null);
        if(entity!=null && !entity.isEmpty()){
            Set<String> menuids = new HashSet<>();
            for (RoleMenuEntity roleMenuEntity : entity) {
                menuids.add(roleMenuEntity.getMenuId());
            }
            for (MenuEntity menuEntity : menuEntities) {
                if(menuids.contains(menuEntity.getId())){
                    menuEntity.setAuth(true);

}

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

    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))
            {

/**
 * 普通用户管理
 */
@Controller
@RequestMapping("childType")
public class ChildTypeController {

    @Autowired
    private ChildTypeService childTypeService  ;

    /**
     * 根据1级分类查询2级分类
     * @param type
     * @return
     */
    @PostMapping("childList.htm")
    @ResponseBody
    public Result childList(Integer type){
        EntityWrapper entityWrapper = new EntityWrapper();
        List<ChildTypeEntity> list =  childTypeService.selectList(entityWrapper);
        return Result.success(list);
    }

    /**
     * 根据1级分类查询2级分类
     * @param type
     * @return
     */
    @PostMapping("childList.do")
    @ResponseBody
    public Result childListdo(Integer type){
        EntityWrapper entityWrapper = new EntityWrapper();
        List<ChildTypeEntity> list =  childTypeService.selectList(entityWrapper);
        return Result.success(list);
    }

    /**

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

  • 7
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
JavaWeb网上购物系统是一种基于Web的小型电子商务系统,它采用MVC模式和MySQL数据库完成网上购物系统的主要功能模块。该系统包括系统首页、注册与登录、商品详情、购物车信息、订单详情和注销等功能模块。用户可以在系统首页浏览商品信息,注册并登录后可以查看商品详情、将商品加入购物车、提交订单等操作。系统还包括验证码验证、数据库连接池等功能。通过这个系统,可以提高自己的编程水平,熟悉并掌握一个完整的JavaWeb开发流程,为今后的工作打下基础。 以下是该系统的部分代码示例: 1. index.jsp ```jsp <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>系统首页</title> </head> <body> <h1>欢迎来到网上购物系统!</h1> <a href="login.jsp">登录</a> <a href="register.jsp">注册</a> </body> </html> ``` 2. JdbcUtils.java ```java public class JdbcUtils { private static String url = "jdbc:mysql://localhost:3306/shopping?useSSL=false&serverTimezone=UTC"; private static String user = "root"; private static String password = "123456"; public static Connection getConnection() throws SQLException { return DriverManager.getConnection(url, user, password); } public static void release(Connection conn, Statement st, ResultSet rs) { if (rs != null) { try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } if (st != null) { try { st.close(); } catch (SQLException e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } } ``` 3. People.java ```java public class People { private String username; private String password; private String email; // 省略getter和setter方法 } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

java毕业

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值