import com.bean.Goods;
import com.github.pagehelper.PageInfo;
import com.service.GoodsService;
import com.util.PageUtil;
import com.util.SendMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
@Controller
public class GoodsController {
//@Autowired是做bean的注入时使用
@Autowired
private GoodsService goodsser;
@Qualifier("goodsservice")//Qualifier的意思是合格者,通过这个标示,表明了哪个实现类才是我们所需要的,添加@Qualifier注解,需要注意的是@Qualifier的参数名称为我们之前定义@Service注解的名称之一。
/**
*商品列表查询
*/
@RequestMapping("/findallgoods.do")
public String findallgoods(ModelMap map, HttpServletRequest request, String goodsname) {
PageUtil.setSize(5);
new PageUtil().setStartPage(request);
List<Goods> goodslist = goodsser.findallgoods(goodsname);
PageInfo<Goods> pagehelper = new PageInfo<Goods>(goodslist);
map.put("pagehelper", pagehelper);
map.put("pageHref", "findallgoods.do");
map.put("goodslist", goodslist);
map.put("goodsname", goodsname);
return "goods";
}
/**
* 新增商品
*/
@RequestMapping("/addgoods.do")
public void addOneGoods(ModelMap map, HttpServletResponse response, Goods goods, String t_motto){
int gid=goodsser.addGoods(goods);
if(gid>0){
SendMsg.sendMsg(response, "<script>window.parent.myconfirm('新增成功!',function(){});location.href='findallgoods.do';window.parent.mhidemodify();</script>");
}else{
SendMsg.sendMsg(response, "<script>window.parent.myconfirm('新增失败!',function(){});location.href='addGoods.jsp';window.parent.mhidemodify();</script>");
}
}
/**
* 删除商品
*/
@RequestMapping("/delgoods.do")
public void delOneGoods(ModelMap map,HttpServletResponse response,Integer goodsid){
int gid=goodsser.delGoods(goodsid);
if(gid>0){
SendMsg.sendMsg(response, "<script>window.parent.myconfirm('删除成功!',function(){});location.href='findallgoods.do';window.parent.mhidemodify();</script>");
}else{
SendMsg.sendMsg(response, "<script>window.parent.myconfirm('删除失败!',function(){});location.href='findallgoods.do';window.parent.mhidemodify();</script>");
}
}
}
【汇智学堂】-SpringMVC+Mybatis+Spring框架使用入门(垃圾分类商品管理查询功能Cotoller层)
猜你喜欢
转载自blog.csdn.net/weixin_39593940/article/details/91125454
今日推荐
周排行