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

飘雪朝晨 2017-11-01 02:46:53

@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方法时却为空是什么鬼?有没有大佬教教我啊?
...全文
1352 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
飘雪朝晨 2017-11-01
  • 打赏
  • 举报
回复
引用 3 楼 qq_39912309 的回复:
@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这个方法啊?
找到问题所在了,因为form标签中enctype属性值的问题,改为application/x-www-form-urlencoded或者不写这个属性就能传过来值了。
飘雪朝晨 2017-11-01
  • 打赏
  • 举报
回复
引用 3 楼 qq_39912309 的回复:
@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这个方法啊?
回复你了。。
飘雪朝晨 2017-11-01
  • 打赏
  • 举报
回复
不是啊,这个是查询出来的数据列表后面有个修改按钮,调用的就是这个方法,然后传id参数过来,根据id查询数据库记录,将记录放到model中,返回给editItems.jsp页面上显示啊,这个页面是一条记录的修改页面。,然后这个是个表单,提交按钮就是调用了editItemsSubmit这个方法。
qq_39912309 2017-11-01
  • 打赏
  • 举报
回复
@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这个方法啊?
飘雪朝晨 2017-11-01
  • 打赏
  • 举报
回复
飘雪朝晨 2017-11-01
  • 打赏
  • 举报
回复
内容概要:本文围绕“新型电力系统下多分布式电源接入配电网承载力评估方法”的研究,系统性地介绍了基于Matlab的仿真建模与代码实现方案,旨在评估高比例分布式电源(如光伏、风电等)接入背景下配电网的接纳能力。研究融合了智能优化算法(如蜣螂优化、灰狼优化、遗传算法)、多目标优化、鲁棒优化及双层优化模型,结合潮流计算、稳定性分析与故障仿真,构建了完整的承载力评估体系。文档不仅提供核心算法实现,还拓展至微电网调度、储能配置、电氢耦合系统、电动汽车协同等前沿方向,强调“复现+创新”相结合的科研路径,助力研究者快速掌握高水平论文复现技巧并激发原创思路。; 适合人群:具备电力系统、自动化或相关专业背景,熟悉Matlab/Simulink仿真环境,正在从事科研或工程应用的研究生及初级科研人员(工作1-3年);; 使用场景及目标:①复现高水平期刊关于配电网承载力的优化模型;②开展高比例可再生能源接入下的配电网规划与运行研究;③学习并应用智能优化算法解决复杂电力系统问题;④获取完整科研资源包以加速课题进展与论文撰写; 阅读建议:建议读者关注公众号“荔枝科研社”获取网盘资源,下载全套代码与模型文件,按照文档结构循序渐进学习,重点理解算法设计逻辑与仿真建模细节,结合所提供的复现案例深化对优化模型与工程应用场景的理解,提升科研效率与创新能力。

81,111

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧