【问题标题】:Parameter's modification in controller does not affect jsp rendering控制器中参数的修改不影响jsp渲染
【发布时间】:2016-05-20 02:10:04
【问题描述】:

我有一个这样的控制器:

@RequestMapping (value = "/page/{action}", method = RequestMethod.GET)
    public String page(@PathVariable String action, @RequestParam Map<String, Object> param, PageInfo pageInfo, Model model) throws Exception {
    param.put("xxx", "123");
    return "/path/to/jsp";
}

param 中“xxx”的原始值为“aaa”。 param.put("xxx", "123");之后,param中“xxx”的值为“123”,但渲染后页面显示的值为“aaa”。

修改对jsp渲染没有影响吗?

【问题讨论】:

标签: java spring jsp


【解决方案1】:

请尝试使用@ModelAttribute

@RequestMapping (value = "/page/{action}", method = RequestMethod.GET)
    public String page(@PathVariable String action, @ModelAttribute Map<String, Object> param, PageInfo pageInfo, Model model) throws Exception {
    param.put("xxx", "123");
    return "/path/to/jsp";
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-24
    相关资源
    最近更新 更多