在商品列表中点击需要修改的商品,跳转到商品修改页面,在该页面做商品的修改。
由于逆向工程已经生成了实现这一功能我们需要的方法,这里直接在service接口中新增方法:
@Override public ItemsCustom findItemsById(int id) throws Exception { Items items = itemsMapper.selectByPrimaryKey(id); ItemsCustom itemsCustom = new ItemsCustom(); BeanUtils.copyProperties(items,itemsCustom); return itemsCustom; } @Override public void updateItems(Integer id, ItemsCustom itemsCustom) throws Exception { /* 对于关键业务的处理 以及对ID为空的校验 空指针异常一定要杜绝! */ itemsMapper.updateByPrimaryKeyWithBLOBs(itemsCustom); }作用:
窄化URL请求限制HTTP请求方法: 如@RequestMapping(value="/editItems",method={RequestMethod.POST, RequestMethod.GET})直接返回一个视图,需要添加Object与ViewName
返回视图名称,可以在方法参数中定义model(相当于定义了Request)
返回真正视图名称 重定向 浏览器中URL地址会发生改变,Request中携带的数据将不能带过去。 //重定向到商品查询列表 //return "redirect:queryItems.action"; 转发//页面转发 return "forward:queryItems.action";在方法上需要定义形参Request与Response
转发:
request.getRequestDispatcher("页面路径").forward(request, response);重定向
response.sendRedirect("url")通过response指定响应结果,例如响应json数据如下:
response.setCharacterEncoding("utf-8"); response.setContentType("application/json;charset=utf-8"); response.getWriter().write("json串");