Java项目:蔬菜网上商城+后台管理系统(java+SSM+mysql+maven+tomcat)

源码获取:博客首页 "资源" 里下载!

一、项目简述

功能: 功能:系统分管理员界面与用户界面 管理员:用户管理,商品类别管理,商品管理,订单管理,公 告管理留言里筲等 向户:房总主册功能,用户登录功能,商品浏览,商品留言评 论,商品购买,商品支付,订单查询等等

二、项目运行

环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)

项目技术: JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + Fileupload + maven等等。

购物车Controller:

/**
 * 购物车Controller
 *
 */
@Controller
@RequestMapping("/car")
public class CarController {
    @Autowired
    private CarService carService;
    @Autowired
    private ItemService itemService;

    /**
     * 加入购物车
     *
     * @param request
     * @param car
     * @return
     */
    @RequestMapping("/addcar")
    @ResponseBody
    public String addcar(HttpServletRequest request, Car car) {
        JSONObject json = new JSONObject();
        Object userId = request.getSession().getAttribute("userId");
        //如果未登录,返回0,提示先登录
        if (userId == null) {
            json.put(Consts.RES, 0);
            return json.toJSONString();
        }
        //保存到购物车
        Item item = itemService.getById(car.getItemId());
        car.setUserId(Integer.valueOf(userId.toString()));
        String price = item.getPrice();
        Double value = Double.valueOf(price);
        car.setPrice(value);
        // BigDecimal bigDecimal = new BigDecimal(value).setScale(2,BigDecimal.ROUND_UP);
        if (item.getZk() != null) {
            value = value * item.getZk() / 10;
            BigDecimal bigDecimal = new BigDecimal(value).setScale(2, RoundingMode.UP);
            car.setPrice(bigDecimal.doubleValue());
        }
        Integer num = car.getNum();
        Double t = value * num;
        BigDecimal bigDecimal = new BigDecimal(t).setScale(2, RoundingMode.UP);
        Double tDouble = bigDecimal.doubleValue();
        car.setTotal(tDouble + "");
        carService.insert(car);
        json.put(Consts.RES, 1);
        return json.toJSONString();
    }

    /**
     * 跳转到购物车页面
     * @param model
     * @param request
     * @return
     */
    @RequestMapping("/findBySql")
    public String findBySql(Model model, HttpServletRequest request) {
         Object userId = request.getSession().getAttribute("userId");
         if(userId==null){
             return "redirect:/login/uLogin";

         }
         Integer id = Integer.valueOf(userId.toString());
         String sql = "select * from car where user_id="+id+" order by id";
        List<Car> carList = carService.listBySqlReturnEntity(sql);
        model.addAttribute("list",carList);
        return "/car/carview";
    }

    /**
     * 删除购物车
     * @param id
     * @return
     */
    @RequestMapping("/delete")
    @ResponseBody
    public String delete(Integer id){
        carService.deleteById(id);
        return "success";
    }
}

登录相关的控制器:

/**
 * 登录相关的控制器
 */
@Controller
@RequestMapping("/login")
public class LoginController extends BaseController {

    @Autowired
    private ManageService manageService;
    @Autowired
    private ItemCategoryService itemCategoryService;
    @Autowired
    private ItemService itemService;
    @Autowired
    private UserService userService;
    /**
     * 管理员登录前
     * @return
     */
    @RequestMapping("login")
    public String login(){
        return "/login/mLogin";
    }

    /**
     * 登录验证
     * @return
     */
    @RequestMapping("toLogin")
    public String toLogin(Manage manage, HttpServletRequest request){
       Manage byEntity = manageService.getByEntity(manage);
       if(byEntity==null){
           return "redirect:/login/mtuichu";
       }
       request.getSession().setAttribute(Consts.MANAGE,byEntity);
       return "/login/mIndex";
    }

    /**
     * 管理员退出
     */
    @RequestMapping("mtuichu")
    public String mtuichu(HttpServletRequest request){
        request.getSession().setAttribute(Consts.MANAGE,null);
        return "/login/mLogin";
    }

    /**
     * 默认首页面
     * @param model
     * @param item
     * @param request
     * @return
     */
    @RequestMapping("uIndex")
    public String uIndex(Model model, Item item, HttpServletRequest request){
        //查询一级类目列表
        String sql1 = "select * from item_category where pid is null and isDelete=0 order by name ";
        List<ItemCategory> itemCategoryFatherList = itemCategoryService.listBySqlReturnEntity(sql1);
        List<CategoryDto> categoryDtoList = new ArrayList<>();
        for (ItemCategory itemCategory:itemCategoryFatherList){
            CategoryDto categoryDto = new CategoryDto();
            categoryDto.setFather(itemCategory);
            //查询一级目录对应的二级目录商品名
            String sql2 = "select * from item_Category where isDelete = 0 and pid = "+itemCategory.getId();
            List<ItemCategory> itemCategoryChildrenList = itemCategoryService.listBySqlReturnEntity(sql2);
            categoryDto.setChldren(itemCategoryChildrenList);
            categoryDtoList.add(categoryDto);
        }
        model.addAttribute("lbs",categoryDtoList);
        //查找折扣商品
        String sql3 = "select * from item where isDelete=0 and zk is not null order by zk desc limit 0,10";
        List<Item> itemListZK = itemService.listBySqlReturnEntity(sql3);
        model.addAttribute("zks",itemListZK);
        //查找热销商品
        String sql4 = "select * from item where isDelete=0 order by gmNum desc limit 0,10";
        List<Item> itemListGM = itemService.listBySqlReturnEntity(sql4);
        model.addAttribute("rxs",itemListGM);
        return "/login/uIndex";
    }

    /**
     * 跳转到注册页面
     * @return
     */
    @RequestMapping("/register")
    public String register(){
        return "/register/register";
    }

    @RequestMapping("/toRegister")
    public String toRegister(User user){
        if(user.getSex().equals("man")){
            user.setSex("男");
        }
        if(user.getSex().equals("woman")){
            user.setSex("女");
        }
        userService.insert(user);
        return "login/uIndex";
    }

    /**
     * 跳转到普通用户登录页面
     * @return
     */
    @RequestMapping("/uLogin")
    public String uLogin(){
        return "/login/uLogin";
    }

    /**
     * 验证普通用户登录
     * @param request
     * @param user
     * @return
     */
    @RequestMapping("/toULogin")
    public String toULogin(HttpServletRequest request,User user){
        User byEntity = userService.getByEntity(user);
        if (byEntity==null){
            //return "/register/register";
            return "redirect:/login/register.action";
        }else{
            request.getSession().setAttribute("userId",byEntity.getId());
            request.getSession().setAttribute("username",byEntity.getRealName());
            request.getSession().setAttribute(Consts.USER,byEntity);
            return "redirect:/login/uIndex.action";
        }
    }

    /**
     * 用户退出
     * @param request
     * @return
     */
    @RequestMapping("exit")
    public String exit(HttpServletRequest request){
        /*request.setAttribute("userId",null);*/
        request.getSession().setAttribute("userId",null);
        request.getSession().setAttribute("username",null);
        request.getSession().setAttribute(Consts.USER,null);
        return "redirect:/login/uIndex.action";
    }

    /**
     * 跳转到修改密码页面
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/updatePW")
    public String updatePW(HttpServletRequest request,Model model){
        Object userId = request.getSession().getAttribute("userId");

        if (userId==null){
            return "redirect:/login/toULogin.action";
        }
        User user = userService.load(Integer.valueOf(userId.toString()));
        model.addAttribute("obj",user);
        return "login/updatePW";
    }
    @RequestMapping("/exUpdate")
    @ResponseBody
    public String exUpdate(HttpServletRequest request,String passWord){
        Object userId = request.getSession().getAttribute("userId");
        JSONObject js = new JSONObject();
        if (userId==null){
            js.put(Consts.RES,0);
        }
        User user = userService.load(Integer.valueOf(userId.toString()));
        user.setPassWord(passWord);
        userService.updateById(user);
        js.put(Consts.RES,1);
        return js.toString();
    }
}

订单详情controller:

/**
 * 订单详情controller
 */
@Controller
@RequestMapping("/orderDetail")
public class OrderDetailController {
    @Autowired
    private OrderDetailService orderDetailService;

    /**
     * 获取订单详情列表
     * @param model
     * @param orderDetail
     * @return
     */
    @RequestMapping("/findbysql")
    public String OrderDetailList(Model model,OrderDetail orderDetail){
        String sql = "select * from order_detail where status = 0 and order_id = "+orderDetail.getOrderId();
        Pager<OrderDetail> pagers = orderDetailService.findBySqlRerturnEntity(sql);
        model.addAttribute("pagers",pagers);
        model.addAttribute("obj",orderDetail);
        return "/orderDetail/orderDetailList";
    }
}

源码获取:博客首页 "资源" 里下载!

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

qq1334611189

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

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

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

打赏作者

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

抵扣说明:

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

余额充值