java项目:基于springboot的商城系统(springBoot+mybatis+layui+jquery)1003

项目描述

爱购商城:分为前端和后端两部分,主要功能包括:用户管理,轮播图管理,商品分类管理,商品品牌管理,商品管理 等功能

运行环境

jdk8+mysql+IntelliJ IDEA+maven

项目技术

springBoot+mybatis+layui+jquery+jsp

项目截图

首页
java项目:基于springboot的商城系统(springBoot+mybatis+layui+jquery)1003_第1张图片
收货地址
java项目:基于springboot的商城系统(springBoot+mybatis+layui+jquery)1003_第2张图片
购物车
java项目:基于springboot的商城系统(springBoot+mybatis+layui+jquery)1003_第3张图片
订单页
java项目:基于springboot的商城系统(springBoot+mybatis+layui+jquery)1003_第4张图片

商品管理
java项目:基于springboot的商城系统(springBoot+mybatis+layui+jquery)1003_第5张图片
修改商品
java项目:基于springboot的商城系统(springBoot+mybatis+layui+jquery)1003_第6张图片

用户管理
java项目:基于springboot的商城系统(springBoot+mybatis+layui+jquery)1003_第7张图片

部分代码

用户Controller代码

@Controller
@RequestMapping("/admin")
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/user/list")
    public String list(@RequestParam(defaultValue = "1")Integer pageNo,
                       @RequestParam(defaultValue = "10") Integer pageSize, Model model){
        PageModel<User> userPages = userService.queryUserList(pageNo, pageSize);
        model.addAttribute("userPages",userPages);
        return "admin/user/list";
    }
    @RequestMapping("/user/addPage")
    public String addPage(){
        return "admin/user/add";
    }
    @RequestMapping("/user/add")
    public String addUser(User user,Model model){
        try {
            user.setType(0);
            int i = userService.addUser(user);
            if (i==0){
                model.addAttribute("errMessage","服务器繁忙添加失败");
                return "500";
            }
        }catch (Exception e){
            model.addAttribute("errMessage",e.getMessage());
            return "500";
        }
        model.addAttribute("url", "admin/user/list");
        return "success";

    }
    @RequestMapping("user/updatePage")
    public String updatePage(String id,Model model){
        User user = userService.queryUserById(id);
        model.addAttribute("user",user);
        return "admin/user/update";
    }
    @RequestMapping("/user/update")
    public String updateUser(User user,Model model){
        try {
            int i = userService.updateUser(user);
            if (i==0){
                model.addAttribute("errMessage","服务器繁忙修改失败");
                return "500";
            }
        }catch (Exception e){
            model.addAttribute("errMessage",e.getMessage());
            return "500";
        }
        model.addAttribute("url", "admin/user/list");
        return "success";

    }
    @RequestMapping("user/deletePage")
    public String deletePage(String id,Model model){
        model.addAttribute("id",id);
        return "admin/user/delete";
    }
    @RequestMapping("user/delete")
    public String deleteUser(String id,Model model){
        try {
            int i = userService.deleteUser(id);
            if (i==0){
                model.addAttribute("errMessage","服务器繁忙修改失败");
                return "500";
            }
        }catch (Exception e){
            model.addAttribute("errMessage",e.getMessage());
            return "500";
        }
        model.addAttribute("url", "admin/user/list");
        return "success";
    }
}

商品Controller控制层


@Controller
@RequestMapping("admin/product")
public class ProductController {
    @Autowired
    private ProductService productService;
    @Autowired
    private ProductTypeService productTypeService;
    @Autowired
    private BrandService brandService;
    @RequestMapping("/list")
    public String list( @RequestParam(defaultValue = "1") Integer pageNo,
                        @RequestParam(defaultValue = "5")Integer pageSize,
                        String productName,
                        String productTypeID,
                        Model model){
        try {
            List<ProductType> productTypes = productTypeService.queryProductTypeAll();
            model.addAttribute("productTypes", productTypes);
            model.addAttribute("productName",productName);
            model.addAttribute("type",productTypeID);
            PageModel<Product> productPages= productService.queryProductPage(pageNo,pageSize,productName,productTypeID);
            model.addAttribute("productPages",productPages);
        } catch (Exception e) {
            e.printStackTrace();
            model.addAttribute("errMessage", "查询失败:"+e.getMessage());
            return  "500";
        }
        return "admin/product/list";
    }
    @RequestMapping("addPage")
    public String addPage(Model model){
        List<ProductType> productTypes= productTypeService.queryProductTypeAll();
        List<Brand> brands=  brandService.queryBrandAll();
        model.addAttribute("productTypes",productTypes);
        model.addAttribute("brands",brands);
        return "admin/product/add";
    }
    @RequestMapping("add")
    private String addProduct(Product product,Model model){
        try {
            int i = productService.addProduct(product);
            if (i==0){
                model.addAttribute("errMessage","服务器繁忙操作失败");
                return "500";
            }
        }catch (Exception e){
            model.addAttribute("errMessage",e.getMessage());
            return "500";
        }
        model.addAttribute("url", "admin/product/list");
        return "success";


    }
    @RequestMapping("updatePage")
    public String update(String id,Model model){
        Product product= productService.queryProductById(id);
        List<ProductType> productTypes= productTypeService.queryProductTypeAll();
        List<Brand> brands=  brandService.queryBrandAll();
        model.addAttribute("productTypes",productTypes);
        model.addAttribute("brands",brands);
        model.addAttribute("product",product);
        return "admin/product/update";
    }
    @RequestMapping("update")
    private String update(Product product,Model model){
        try {
            int i = productService.updateProduct(product);
            if (i==0){
                model.addAttribute("errMessage","服务器繁忙操作失败");
                return "500";
            }
        }catch (Exception e){
            model.addAttribute("errMessage",e.getMessage());
            return "500";
        }
        model.addAttribute("url", "admin/product/list");
        return "success";


    }
    @RequestMapping("deletePage")
    public String deletePage(String id,Model model){
        model.addAttribute("id",id);
        return "admin/product/delete";
    }
    @RequestMapping("/delete")
    public String delete(String id, Model model){
        try {
            int i = productService.delete(id);
            if (i==0){
                model.addAttribute("errMessage","服务器繁忙操作失败");
                return "500";
            }
        }catch (Exception e){
            model.addAttribute("errMessage",e.getMessage());
            return "500";
        }
        model.addAttribute("url", "admin/product/list");
        return "success";

    }
    @RequestMapping("batchDel")
    @ResponseBody
    public String batchDel(String[] ids) {
        System.out.println("进来了");
        productService.batchProductTypeDel(ids);
        return "/admin/product/list";

    }

}


登录Controller 代码


@Controller
@RequestMapping("/admin")
public class LoginController {
    @Autowired
    private UserService userService;

    @RequestMapping("/index")
    public String index(){
        return "admin/index/index";
    }
    @RequestMapping("/loginPage")
    public String loginPage(){
        return "admin/login/login";
    }
    @RequestMapping("/login")
    public String login(String username, String password, Model model, HttpSession session){
        try {
            User user= userService.queryUserByName(username,0);
            if (user==null){
                model.addAttribute("errMsg","用户名不存在");
                return "admin/login/login";
            }else {
                String password1 = user.getPassword();
                if (!EncryptionUtils.encryptMD5(password).equals(password1)){
                    model.addAttribute("errMsg","密码错误");
                    return "admin/login/login";
                }else {
                    session.setAttribute("_admin",username);
                    return "redirect: index";
                }
            }
        }catch (Exception e){
            model.addAttribute("errMsg","服务器繁忙登录失败!");
            return "admin/login/login";
        }

    }
    @RequestMapping("/logout")
    public String logout(HttpSession session){
        session.removeAttribute("_admin");
        return "admin/login/login";
    }
   @RequestMapping("/user/changePasswordPage")
   public String changePasswordPage(){
       return "admin/login/changePassword";
   }
   @RequestMapping("/user/changePassword")
   public String changePassword(String oldPassword,String newPassword,HttpSession session,Model model){
       String username = (String) session.getAttribute("_admin");
       User user= userService.queryUserByName(username,0);
       if (!EncryptionUtils.encryptMD5(oldPassword).equals(user.getPassword())){
            model.addAttribute("errMessage","密码错误修改失败");
            return "500";
       }else {
           user.setPassword(newPassword);
           try {
               int i = userService.updateUser(user);
               if (i==0){
                   model.addAttribute("errMessage","服务器繁忙修改失败");
                   return "500";
               }
           }catch (Exception e){
               model.addAttribute("errMessage",e.getMessage());
               return "500";
           }
           model.addAttribute("url", "admin/index");
           return "success";
       }
   }
}

注意事项

图片数据请修改路径

源码地址

你可能感兴趣的:(java毕业设计实战,java,eclipse,tomcat)