package com.tongkai.controller;
import java.lang.ProcessBuilder.Redirect;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tongkai.pojo.Goods;
import com.tongkai.pojo.TCart;
import com.tongkai.service.GoodsService;
@Controller
@RequestMapping("goods")
public class GoodsController {
@Autowired
private GoodsService goodsService;
@RequestMapping("add")
public String add(Goods goods){
int insert = goodsService.insert(goods);
return "redirect:/goods/show";
}
@RequestMapping("show")
public String show(Goods goods,HttpSession session,String pageNo, String pageSize){
int num = 1;
int size = 3;
if(pageNo != null && !"".equals(pageNo)) {
num = Integer.parseInt(pageNo);
}
if (pageSize != null && !"".equals(pageSize)) {
size = Integer.parseInt(pageSize);
}
PageHelper.startPage(num,size);
List<Goods> gList = goodsService.gList(goods);
PageInfo<Goods> pageInfo = new PageInfo<Goods>(gList);
session.setAttribute("pageHelper", pageInfo);
return "show";
}
@RequestMapping("delete")
public String delete(int gid){
int deleteById = goodsService.deleteById(gid);
System.out.println(deleteById);
return "redirect:/goods/show";
}
}