基于javaweb+mysql的springboot+mybatis在线购物商城shop系统(仅前台购物)(java+springboot+ssm+mysql+thymeleaf+html)

这是一个适用于课程设计的JavaWeb项目,采用SpringBoot、MyBatis框架,结合MySQL数据库,实现了用户登录、注册、商品查询与下单、购物车管理等功能。前端使用HTML、CSS、JavaScript、jQuery、LayUI和Thymeleaf技术。
摘要由CSDN通过智能技术生成

基于javaweb+mysql的springboot+mybatis在线购物商城shop系统(仅前台购物)(java+springboot+ssm+mysql+thymeleaf+html)

运行环境

Java≥8、MySQL≥5.7

开发工具

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

适用

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

功能说明

用户:登录、注册、商品查询与下单、购物车管理

技术框架

HTML CSS JavaScript jQuery LayUI thymeleaf SpringBoot SpringMVC MyBatis

基于javaweb+mysql的SpringBoot+MyBatis在线购物商城shop系统(仅前台购物)(java+springboot+ssm+mysql+thymeleaf+html)


@Controller
@RequestMapping("/cart")
public class CartController {
   

    @Autowired
    private CartService cartService;
    @Autowired
    private UserAddressService userAddressService;

    @GetMapping("/add/{productId}/{price}/{quantity}")
    public String add(
            @PathVariable("productId") Integer productId,
            @PathVariable("price") Float price,
            @PathVariable("quantity") Integer quantity,
            HttpSession session
    ){
   
        Cart cart = new Cart();
        cart.setProductId(productId);
        cart.setQuantity(quantity);
        cart.setCost(price*quantity);
        User user = (User) session.getAttribute("user");
        cart.setUserId(user.getId());
        try {
   
            if(cartService.save(cart)){
   
                return "redirect:/cart/findAllCart";
            }
        } catch (Exception e) {
   
            return "redirect:/productCategory/list";
        }
        return null;
    }

    @GetMapping("/findAllCart")
    public ModelAndView findAllCart(HttpSession session){
   
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("settlement1");
        User user = (User)session.getAttribute("user");
        modelAndView.addObject("cartList",cartService.findAllCartVOByUserId(user.getId()));
        return modelAndView;
    }

    @GetMapping("/deleteById/{id}")
    public String deleteById(@PathVariable("id") Integer id){
   
        cartService.removeById(id);
        return "redirect:/cart/findAllCart";
    @PostMapping("/findByKey")
    public ModelAndView findByKey(String keyWord, HttpSession session) {
   
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("productList");
        //根据关键字查询
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.like("name", keyWord);
        modelAndView.addObject("productList", productService.list(wrapper));
        modelAndView.addObject("list", productCategoryService.getAllProductCategoryVO());
        User user = (User) session.getAttribute("user");
        if (user == null) {
   
            modelAndView.addObject("cartList", new ArrayList<>());
        } else {
   
            modelAndView.addObject("cartList", cartService.findAllCartVOByUserId(user.getId()));
        }
        return modelAndView;
    }

    @GetMapping("/findById/{id}")
    public ModelAndView findById(@PathVariable("id") Integer id, HttpSession session) {
   
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("productDetail");
        modelAndView.addObject("product", productService.getById(id));
        modelAndView.addObject("list", productCategoryService.getAllProductCategoryVO());
        User user = (User) session.getAttribute("user");
        if (user == null) {
   
            modelAndView.addObject("cartList", new ArrayList<>());
        } else {
   
            modelAndView.addObject("cartList", cartService.findAllCartVOByUserId(user.getId()));
        }
        return modelAndView;
    }

    @RequestMapping("/findAllTableProduct")
    @ResponseBody
    public TableDataVO<TableProductVO> findAllTableProduct(Integer page, Integer limit) {
   
        return productService.findAllTableData(page, limit);
    }
}

    @ResponseBody
    public String updateCart(
            @PathVariable("id") Integer id,
            @PathVariable("quantity") Integer quantity,
            @PathVariable("cost") Float cost
    ){
   
        Cart cart = cartService.getById(id);
        cart.setQuantity(quantity);
        cart.setCost(cost);
        if(cartService.updateById(cart)){
   
            return "success";
        }else{
   
            return "fail";
        }
    }
}

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

    @Autowired
    private UserService userService;
    @Autowired
    private CartService cartService;

    @PostMapping("/register")
    public String register(User user, Model model) {
   
        boolean result = false;
        try {
   

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

    @Autowired
    private UserService userService;
    @Autowired
    private CartService cartService;

    @PostMapping("/register")
    public String register(User user, Model model) {
   
        boolean result = false;
        try {
   
            if 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值