淘淘商城_商品修改界面_出现/修改/提交(记录)

商品修改界面涉及到的JSP界面:

                      item_edit.jsp 界面, item_list.jsp 界面

商品修改界面涉及到的请求路径:

 
 涉及请求请求路径请求方式返回结果
商品初始化界面请求路径/rest/page/item-editget视图
商品描述信息请求路径/rest/item/query/item/desc/'+data.idget数据
商品规格信息请求路径/rest/item/param/item/query/'+data.idget数据
商品删除信息请求路径/rest/item/delete post数据
商品界面提交请求路径/rest/item/update post数据

商品修改界面详细处理请求路径代码:

Controller:

@Controller
@RequestMapping("/rest")
public class ItemRestController {

	@Autowired
	private ItemEditService itemEditService;
	
	@RequestMapping("/page/item-edit")
	public String ItemEdit() {
		// 编辑单个商品的信息界面
		return "item-edit";
	}
	
	@RequestMapping(value = "/item/update" , method=RequestMethod.POST)
	@ResponseBody
	public TaotaoResult ItemEdit(TbItem item , String desc) {
		// 编辑单个商品的信息界面
		TaotaoResult updateItem = null;
		try{
			updateItem = itemEditService.UpdateItem( item , desc );
			return updateItem;
		}catch(Exception e) {
			return null;
		}
	}
	
	@RequestMapping(value = "/item/query/item/desc/{id}")
	@ResponseBody
	public TaotaoResult ItemDesc(@PathVariable long id) {
		// 加载商品描述
		TaotaoResult itemDesc = itemEditService.ItemDesc( id );
		return itemDesc;
	}
	
	@RequestMapping(value = "/item/param/item/query/{id}")
	@ResponseBody
	public TaotaoResult ItemParamData(@PathVariable long id) {
		// 加载商品规格
		TaotaoResult itemParamData = itemEditService.ItemParamData(id);
		return itemParamData;
	}
	
	@RequestMapping(value = "/item/delete" , method = RequestMethod.POST)
	@ResponseBody
	public TaotaoResult deleteItem(@RequestParam String ids) {
		// 商品删除
		TaotaoResult deleteItem = itemEditService.deleteItem( ids );
		return deleteItem;
	}

	@RequestMapping(value = "/item/instock" , method = RequestMethod.POST)
	@ResponseBody
	public TaotaoResult instockItem(@RequestParam String ids) {
		// 商品下架
		TaotaoResult instockItem = itemEditService.instockItem( ids );
		return instockItem;
	}
	
	@RequestMapping(value = "/item/reshelf",method=RequestMethod.POST)
	@ResponseBody
	public TaotaoResult reshelfItem(@RequestParam String ids) {
		 // 商品上架
		 TaotaoResult reshelfItem = itemEditService.reshelfItem( ids );
		 return reshelfItem;
	}
}

Service:

public interface ItemEditService {
// 商品下架
public TaotaoResult instockItem(String ids);

// 商品上架
public TaotaoResult reshelfItem(String ids);

// 商品删除
public TaotaoResult deleteItem(String ids);

// 商品规格
public TaotaoResult ItemParamData(long id);

// 商品描述
public TaotaoResult ItemDesc(long id);

// 更新商品
public TaotaoResult UpdateItem(TbItem item, String desc);
}

Service Impl:

@Service
public class ItemEditServiceImpl implements ItemEditService{
 
	@Autowired
	private TbItemMapper itemMapper;

	@Autowired
	private TbItemDescMapper itemDescMapper;

	
	@Override
	public TaotaoResult instockItem(String ids) {
		// 找到对应的商品
		String[] buff = ids.split(",");
		for (String id : buff) {
			// 修改商品信息
			TbItem selectByPrimaryKey = itemMapper.selectByPrimaryKey(Long.parseLong(id));
			selectByPrimaryKey.setStatus( (byte) 2);
			// 更改商品信息
			itemMapper.updateByPrimaryKey(selectByPrimaryKey);
		}
		return TaotaoResult.ok();
	}

	@Override
	public TaotaoResult reshelfItem(String ids) {
		// 找到对应的商品
		String[] buff = ids.split(",");
		for (String id : buff) {
			// 修改商品信息
			TbItem selectByPrimaryKey = itemMapper.selectByPrimaryKey(Long.parseLong(id));
			selectByPrimaryKey.setStatus( (byte)1 );
			// 更改商品信息
			itemMapper.updateByPrimaryKey(selectByPrimaryKey);
		}
		return TaotaoResult.ok();
	}

	@Override
	public TaotaoResult deleteItem(String ids) {
		// 找到对应的商品
		String[] buff = ids.split(",");
		for (String id : buff) {
			// 删除商品信息
			TbItem selectByPrimaryKey = itemMapper.selectByPrimaryKey( Long.parseLong(id) );
			selectByPrimaryKey.setStatus( (byte)3 );
			itemMapper.updateByPrimaryKey( selectByPrimaryKey );
		}
		return TaotaoResult.ok();
	}

	// paramData 信息保存属性
	@Override
	public TaotaoResult ItemParamData(long id) {
		TbItem selectByPrimaryKey = itemMapper.selectByPrimaryKey(id);
		// 保存的信息返回结果
        Map<String, Long> result = new HashMap<String , Long>();
        // 信息封装
		if(selectByPrimaryKey != null) {
			result.put("paramData", selectByPrimaryKey.getPrice() );
		}else
			result.put("paramData", 0l );
		return TaotaoResult.ok(  result );
	}

	// itemDesc 信息保存属性
	@Override
	public TaotaoResult ItemDesc(long id) {
		TbItemDesc selectByPrimaryKey = itemDescMapper.selectByPrimaryKey(id);
		// 保存的信息返回结果
        Map<String, String> result = new HashMap<String , String>();
        // 信息封装
		if(selectByPrimaryKey != null) {
			result.put("itemDesc", selectByPrimaryKey.getItemDesc() );
		}else
			result.put("itemDesc", "暂无描述信息" );
		return TaotaoResult.ok(  result );
	}

	@Override
	public TaotaoResult UpdateItem(TbItem tbItem , String desc) {
		// 更新商品信息
		if(itemMapper.selectByPrimaryKey( tbItem.getId() ) == null) {
			 throw new IllegalAccessError("商品 不存在");
		}
		// 修改商品最新更新状态
		tbItem.setUpdated(new Date());
		TbItemExample tbItemExample = new TbItemExample();
		Criteria createCriteria = tbItemExample.createCriteria();
		createCriteria.andIdEqualTo( tbItem.getId() );
		// 插入数据库
		itemMapper.updateByExampleSelective( tbItem , tbItemExample );
        
		// 更新商品描述
		TaotaoResult result = insertTbItemDesc( tbItem.getId() , desc );
		if (result == null ||  result.getStatus() != 200) {
			throw new IllegalAccessError("商品 描述条件不正确");
		}
		// 返回结果
		return TaotaoResult.ok();
	}
	
	public TaotaoResult insertTbItemDesc(long itemDescId, String itemDesc) {
		// 查询是否存在
		TbItemDesc tbItemDesc = new TbItemDesc();
		if( itemDescMapper.selectByPrimaryKey( itemDescId ) == null) {
			// 添加信息
			tbItemDesc.setItemId(itemDescId);
			tbItemDesc.setItemDesc(itemDesc);
			tbItemDesc.setCreated(new Date());
			tbItemDesc.setUpdated(new Date());
			// 插入数据
			itemDescMapper.insert( tbItemDesc );
		}else {
			// 更新的数据
			tbItemDesc.setUpdated(new Date());
			tbItemDesc.setItemDesc( new String( itemDesc ) );
			// 更新的条件
			TbItemDescExample tbItemDescExample = new TbItemDescExample();
			com.taotao.pojo.TbItemDescExample.Criteria createCriteria = tbItemDescExample.createCriteria();
			createCriteria.andItemIdEqualTo( itemDescId );
			// 执行sql语句数据
			itemDescMapper.updateByExampleSelective( tbItemDesc , tbItemDescExample );
		}
		return TaotaoResult.ok();
	}
}

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值