商品修改界面涉及到的JSP界面:
item_edit.jsp 界面, item_list.jsp 界面
商品修改界面涉及到的请求路径:
涉及请求 | 请求路径 | 请求方式 | 返回结果 |
商品初始化界面请求路径 | /rest/page/item-edit | get | 视图 |
商品描述信息请求路径 | /rest/item/query/item/desc/'+data.id | get | 数据 |
商品规格信息请求路径 | /rest/item/param/item/query/'+data.id | get | 数据 |
商品删除信息请求路径 | /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();
}
}