springmvc中同一个controller中的方法转发到另外一个方法,request域并没有共享,是怎么回事?
@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方法时却为空是什么鬼?有没有大佬教教我啊?
...全文
相关推荐
如何在springMVC的controller中获取request
很多时候,我们需要在 Controller 中获取 Request 对象以便实现某些功能,例如身份验证、Cookie 操作等。那么,在 SpringMVC 中如何获取 Request 对象呢?
简单谈谈SpringMVC转发和重定向的区别
本文将详细讲解 SpringMVC 中的转发和重定向的区别,并给出实践示例。一、转发(Forward)在 SpringMVC 中,转发是通过 `RequestDispatcher` 对象实现的。
SpringMVC中controller接收json数据的方法
- `@RequestBody`注解:用于注入HTTP请求体中的内容到方法参数中。在这个例子中,它将接收到的JSON数据转换为User对象。
详解springmvc 中controller与jsp传值
使用`Map<String, Object> model`参数:在Controller方法中,我们可以创建一个`Map`对象,并将其作为参数传递。然后在方法内部将数据放入Map,最后返回视图名称。
Springmvc中的转发重定向和拦截器的示例
拦截器是 Springmvc 中的一个组件,是运行在 DispatcherServlet 之后,运行在 Controller 之前的。


Web 开发
