【问题标题】:@requestparam in spring is not working春季的@requestparam 不起作用
【发布时间】:2016-08-14 19:55:12
【问题描述】:

我已经为此苦苦挣扎了几个星期,我有下一个方法:

@RequestMapping( method = RequestMethod.GET )
    public ModelAndView update(
            HttpServletRequest request, 
            HttpServletResponse response,
    @RequestParam( value = "id", required = true ) String id ) throws Exception 
    {
        model = new ModelAndView( "/jspadmin/game/update" );

        getLog().error( "::: valor del string: " + request.getParameter( "id" ) );
        getLog().error( "::: valor del string: de ruta" + id );
     }

此代码在 multiactioncontroller 中,但我无法从 @RequestParam 注释中获取 id 值

我在 aplicationContext.xml

中有注释驱动

我根本不使用注释,只是在那个方法中,我不知道控制器是否需要强制使用 @Controller 注释来使方法中的注释起作用,我不知道我缺少什么,在此先感谢各位。

【问题讨论】:

  • 您是否在控制器级别设置了@RequestMappingvalue 属性?是的,@Controller 是控制器类所必需的。
  • 我在 xml 中创建控制器,如果我将 @controller 放在类中是否重要?因为我得到下一个错误:

标签: spring controller


【解决方案1】:

试试@Controller注解:

@Controller
@RequestMapping("/rootUrl")
public class MyController...

和行动:

@RequestMapping(value="/url", method = RequestMethod.GET )
public String update(@RequestParam...

【讨论】:

    【解决方案2】:

    请使用下面的代码,只需在请求映射中为某些模式添加价值

    @RequestMapping(value = "/save", method = RequestMethod.GET)
    public ModelAndView update(HttpServletRequest request, HttpServletResponse response,
            @RequestParam(value = "id", required = true) String id) throws Exception {
        System.out.println("Inside Save id is " + id);
        return new ModelAndView("index");
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-05-28
      • 1970-01-01
      • 1970-01-01
      • 2021-02-21
      • 2015-01-22
      • 2015-02-27
      • 2016-08-20
      相关资源
      最近更新 更多