首页>代码>基于SSM框架简单的商城购物车项目实例>/超市项目/shopcart/src/cn/sjzedu/controller/DiscountController.java
package cn.sjzedu.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import cn.sjzedu.pack.CashContext;
import cn.sjzedu.service.DiscountService;

@Controller
@RequestMapping("/Discount")
public class DiscountController {
	@Autowired
	private DiscountService discountService;
	//在后台活动设置界面增加满减活动跳转的controller
	@RequestMapping("/fullreduction")
	public ModelAndView cash(HttpServletRequest req,HttpServletResponse rsp) throws Exception{
		ModelAndView modelAndView = new ModelAndView();
		String man = req.getParameter("man");
		String jian  = req.getParameter("jian");
		if(man!=null&&jian!=null&&man.length()>0&&jian.length()>0){
			double man1 = Double.parseDouble(man);
			double jian1 = Double.parseDouble(jian);
			if(man1>jian1){
				discountService.deleteAll();
				int i = discountService.insertCashReturn(man1, jian1);
				if(i>0){
					modelAndView.addObject("alert", "添加成功");
					modelAndView.setViewName("rebate");
					String zhekou = "满" + man1 + "减" + jian1;
					req.getSession().setAttribute("zhekou",zhekou);
				}else{
					modelAndView.addObject("alert", "添加失败");
					modelAndView.setViewName("rebate");
				}
			}else{
				modelAndView.addObject("alert", "您输入的格式不正确");
				modelAndView.setViewName("rebate");
			}
			}
					
		return modelAndView;
	
	}
	//在后台活动设置界面增加打折活动跳转到controller
	@RequestMapping("/rebate")
	public ModelAndView rebate(HttpServletRequest req,HttpServletResponse rsp) throws Exception{
		ModelAndView modelAndView = new ModelAndView();
		String rebate = req.getParameter("rebate");
		if(rebate!=null&&rebate.length()>0){
			double rate = Double.parseDouble(rebate);			
				discountService.deleteAll();
				int i = discountService.insertCashRebate(rate);
				if(i>0){
					modelAndView.addObject("alert", "添加成功!");
					modelAndView.setViewName("rebate");
					String zhekou = rate + "折";
					req.getSession().setAttribute("zhekou",zhekou);
				}else{
					modelAndView.addObject("alert", "添加失败!");
					modelAndView.setViewName("rebate");
				}
			}else{
				modelAndView.addObject("alert", "请输入折扣!");
				modelAndView.setViewName("rebate");
			}
			
					
		return modelAndView;
	
	}
	
	//在后台取消活动后跳转的controller
		@RequestMapping("/cancle")
		public ModelAndView cancle(HttpServletRequest request){
			ModelAndView modelAndView = new ModelAndView();

			int result = discountService.deleteAll();
			if(result > 0){
				//取消成功
				request.getSession().removeAttribute("zhekou");
				modelAndView.addObject("cancle", "取消活动成功");
				modelAndView.setViewName("cancle");
			}else{
				//取消失败
				modelAndView.addObject("cancle", "取消活动失败");
				modelAndView.setViewName("cancle");
			}
			return modelAndView;
		}
}
最近下载更多
15342201772  LV9 2024年11月12日
Xppasdf  LV3 2024年10月29日
taoshen95  LV16 2024年3月22日
gecongkai  LV8 2023年6月22日
yzshabzbbdvw  LV4 2023年4月15日
malike  LV3 2022年12月14日
lsglsg9  LV23 2022年11月26日
微信网友_6200823191523328  LV3 2022年11月11日
admin0108  LV9 2022年10月12日
1020132795  LV5 2022年9月25日
最近浏览更多
xiaoaitx  LV8 1月1日
hcghhh 2024年12月28日
暂无贡献等级
微信网友_7310057461567488 2024年12月24日
暂无贡献等级
三秋桂子  LV1 2024年12月22日
Ella0902 2024年12月18日
暂无贡献等级
n1234560090 2024年12月11日
暂无贡献等级
sjwc88  LV3 2024年12月4日
Xppasdf  LV3 2024年10月29日
zouzou123  LV3 2024年10月18日
lyh1989  LV34 2024年7月21日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友