作者:LC--Vincent | 来源:互联网 | 2023-09-24 16:34
importorg.springframework.stereotype.Controller;importorg.springframework.ui.ModelMap;i
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.shopping.Convert.Converter;
import com.shopping.domain.Goods;
import com.shopping.service.GoodsService;
import com.shopping.viewmodel.VMGoods;
/**
* @ClassName: GoodsController
* @Description:TODO(这里用一句话描述这个类的作用)
* @author: zhangzhifei
* @date: 2015年8月20日 下午12:01:11
*/
@Controller
@RequestMapping("/goods")
public class GoodsController {
/**
* @Fields goodsService : TODO(用一句话描述这个变量表示什么)
*/
@Resource(name="goodsService")
public GoodsService goodsService;
@RequestMapping("/AddGoods")
public String AddGoods(ModelMap modelMap) {
modelMap.addAttribute("goods", new VMGoods());
return "AddGoods";
/**
* @Title: SearchGoods
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param goodsname
* @param goodsType
* @return
* @author: zhangzhifei
* @date: 2015年8月20日 下午5:00:35
*/
@RequestMapping("/search")
public String SearchGoods(@RequestParam(value="goodsname")String goodsname,
@RequestParam(value="goodsType")String goodsType,
ModelMap modelMap){
List Goods goodslist = goodsService.Query(new Goods());
modelMap.addAttribute("goodslist",goodslist);
return "SearchResult";
/**
* @Title: Add
* @Description: 处理添加货物请求
* @param goods
* @param bindingResult
* @return
* @author: zhangzhifei
* @date: 2015年8月20日 下午5:00:26
*/
@RequestMapping("/add")
public String Add(@Valid @ModelAttribute("goods")VMGoods vmgoods ,
BindingResult error, ModelMap model){
if(error.hasErrors()){
return "AddGoods";
}
else{
Goods goods = Converter.VMGoodsToGoods(vmgoods);
if(goodsService.Add(goods) == true){
model.addAttribute("result", 1);
}
else{
model.addAttribute("result", 0);
}
return "AddGoods";
}
/**
* @Title: Delete
* @Description: 删除商品
* @param id
* @param modelMap
* @return
* @author: zhangzhifei
* @date: 2015年8月23日 下午4:09:24
*/
@RequestMapping("/delete")
public String Delete(@RequestParam(value="id")int id,ModelMap modelMap){
if(goodsService.DeleteById(id) == true){
modelMap.addAttribute("result", 1);
}
else{
modelMap.addAttribute("result", 0);
List Goods goodslist = goodsService.Query(new Goods());
modelMap.addAttribute("goodslist",goodslist);
return "SearchResult";
/**
* @Title: Update
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param id
* @param modelMap
* @return
* @author: zhangzhifei
* @date: 2015年8月23日 下午4:22:49
*/
@RequestMapping("/update")
public String Update(int id, ModelMap modelMap){
Goods goods = new Goods();
goods = goodsService.QueryById(id);
modelMap.addAttribute("goods",goods);
return "UpdateGoods";
/**
* @Title: UpdateGoods
* @Description: TODO(这里用一句话描述这个方法的作用)
* @param goods
* @param modelMap
* @return
* @author: zhangzhifei
* @date: 2015年8月23日 下午4:22:58
*/
@RequestMapping("/UpdateGoods")
public String UpdateGoods(Goods goods1, ModelMap modelMap){
goodsService.Update(goods1);
List Goods goodslist = goodsService.Query(new Goods());
modelMap.addAttribute("goodslist",goodslist);
return "SearchResult";
}
}