springmvc中同一个controller中的方法转发到另外一个方法,request域并没有共享,是怎么回事?

飘雪朝晨 飘雪朝晨 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

@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";
}

}

我在上面editItemsSubmit方法中转发到queryItems.action没问题,但是我调试的时候断点打在第42行,40行中的形参itemsCustom,id和42行中的itemsCustom,id的值都为空这是怎么回事啊?
editItems方法执行完后,itemsCustom和id的值都是有的,但是执行到editItemsSubmit方法时却为空是什么鬼?有没有大佬教教我啊?
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
飘雪朝晨
Web 开发 81,108 成员 341,721 内容