package com.none.controller;
import java.io.IOException;
import java.util.List;
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.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.none.model.Vip;
import com.none.service.VipService;
@Controller
@RequestMapping("vip")
public class VipController {
@Autowired
VipService service;
/*获取一个vip(验证登录)*/
@RequestMapping("selectByCode.action")
@ResponseBody
public Vip selectById(String username)
{
System.out.println(username);
Vip vip = service.getByCode(username);
System.out.println(vip);
return vip;
}
/*注销用户*/
@RequestMapping("logout.action")
@ResponseBody
public void logout(HttpServletRequest request,HttpServletResponse response)
{
System.out.println("用户注销");
request.getSession().removeAttribute("vip");
System.out.println(request.getSession().getAttribute("vip"));
try {
response.sendRedirect(request.getContextPath() + "/page/index.jsp");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/*用户登录*/
@RequestMapping("login.action")
public void login(String username,HttpServletRequest request,HttpServletResponse response)
{
System.out.println(service.getByCode(username));
request.getSession().setAttribute("vip", service.getByCode(username));
try {
response.sendRedirect(request.getContextPath() + "/page/index.jsp");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/*新增一个vip(钱在前台设置好)*/
@RequestMapping("addVip.action")
public void add(Vip vip,HttpServletRequest request,HttpServletResponse response)
{
/*当前会员一律八折,卡号由后台生成*/
vip.setCode(service.getCode());
vip.setDiscount(0.8);
vip.setDueTime("9999-12-31");
service.addVip(vip);
ModelAndView mav = new ModelAndView("/page/showRegister");
request.getSession().setAttribute("vipRegister",vip);
try {
response.sendRedirect(request.getContextPath() + "/page/showRegister.jsp");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/*获得vip总数*/
@RequestMapping("getNumber.action")
@ResponseBody
public int getNumber() {
System.out.println("获得vip总数控制层");
System.out.println(service.getNumber());
return service.getNumber();
}
/*获取所有vip*/
public List<Vip> getAll(){
return service.getAll();
}
/*获取部分vip(翻页)*/
@RequestMapping("getAllLimit.action")
@ResponseBody
public List<Vip> getAllLimit(int begin,int num){
System.out.println("获得vip分页控制层");
return service.getAllLimit(begin,num);
}
/*更新vip信息*/
@RequestMapping("updateVip.action")
public void update(HttpServletRequest request,HttpServletResponse response,Vip vip)
{
Vip v = (Vip) request.getSession().getAttribute("vip");
v.setMoney(vip.getMoney() + v.getMoney());
v.setBirthday(vip.getBirthday());
v.setName(vip.getName());
v.setPassword(vip.getPassword());
v.setPhone(vip.getPhone());
service.updateVip(v);
try {
response.sendRedirect(request.getContextPath() + "/page/index.jsp");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/*vip充值(本身就是更新vip)*/
@RequestMapping("charge")
public ModelAndView charge(Vip vip)
{
return null;
}
/*删除一个vip*/
@RequestMapping("delete")
public ModelAndView delete(int id)
{
return null;
}
}
评论0