81,122
社区成员




@Controller
@RequestMapping("/items")
public class ItemsController {
@Autowired
private ItemsService itemsService;
// 商品查询
@RequestMapping("/queryItems")
public ModelAndView queryItems(HttpServletRequest request) throws Exception {
// 测试forward后request是否可以共享
System.out.println("forward之后可以共享 id:"+request.getParameter("id"));
List<ItemsCustom> itemsList = itemsService.findItemsList(null);
// 返回ModelAndView
ModelAndView modelAndView = new ModelAndView();
// 相当于request的setAttribute,在jsp页面中可以通过itemsList取数据
modelAndView.addObject("itemsList", itemsList);
// 指定视图
// 下边的路径,如果在我们的视图解析器中配置了jsp路径的前缀和jsp路径的后缀,修改为
modelAndView.setViewName("items/itemsList");
return modelAndView;
}
@RequestMapping(value = "/editItems", method = { RequestMethod.POST,RequestMethod.GET })
public String editItems(Model model,@RequestParam(value = "id", required = true)Integer items_id)
throws Exception {
ItemsCustom itemsCustom = itemsService.findItemsById(items_id);
model.addAttribute("itemsCustom", itemsCustom);
return "items/editItems";
}
// 商品信息修改提交
@RequestMapping("/editItemsSubmit")
public String editItemsSubmit(HttpServletRequest request,Integer id,ItemsCustom itemsCustom) throws Exception {
// 调用service更新商品信息,页面需要将商品信息传到方法
itemsService.updateItems(id, itemsCustom);
return "forward:queryItems.action";
}
}
@RequestMapping(value = "/editItems", method = { RequestMethod.POST,RequestMethod.GET })
public String editItems(Model model,@RequestParam(value = "id", required = true)Integer items_id)
throws Exception {
ItemsCustom itemsCustom = itemsService.findItemsById(items_id);
model.addAttribute("itemsCustom", itemsCustom);
return "items/editItems";
}
你这个是什么情况?递归调用吗?没看到你的哪个方法转发到editItemsSubmit这个方法啊?