Java @RequestParam注释

Java @RequestParam注释,java,spring,annotations,Java,Spring,Annotations,我的问题似乎很奇怪,因为我是Java的新手 我读过oracle关于Java注释的文章。但我还不明白它们是如何在实践中发挥作用的。考虑下面的Spring框架4.0.1定义的注释: @Target(value = {ElementType.PARAMETER}) @Retention(value = RetentionPolicy.RUNTIME) @Documented public @interface RequestParam { public String value() defa

我的问题似乎很奇怪,因为我是Java的新手

我读过oracle关于Java注释的文章。但我还不明白它们是如何在实践中发挥作用的。考虑下面的Spring框架4.0.1定义的注释:

@Target(value = {ElementType.PARAMETER})
@Retention(value = RetentionPolicy.RUNTIME)
@Documented
public @interface RequestParam {

    public String value() default "";

    public boolean required() default true;

    public String defaultValue() default "\n\t\t\n\t\t\n\ue000\ue001\ue002\n\t\t\t\t\n";
}
注释可以应用于函数参数,如下所示

 public void change(@RequestParam("id") String id, @RequestParam("cost") String cost, @RequestParam("name") String name, Model model) throws SQLException, UnsupportedEncodingException {
         //id will have the value of param id, passing inside request
         //but ***I have no explicitly assignation*** requested parameter 
         //to the function parameter
    }

谁将请求的参数值准确地分配给相应的函数参数?

在Spring MVC中,您必须应用

1- index.jsp in WEB-INF
2- property names for index.jsp in view.xml
3- Controller for property names
4- mapping for controller in servlet.xml
如果您想在需要的项目中使用@RequestParam

-Form action in jsp
-Class for variables
-Controller for form variables.
您正在使用的Spring版本中的默认@EnabledWebMvc或MVC堆栈使用的实现来解析调用带有@RequestMapping注释的处理程序方法时要使用的参数

对于@RequestParam,该实现是

参数都被收集,然后Spring使用反射来调用处理程序方法。它在调用过程中传递收集的参数。

您正在使用的Spring版本中的默认@EnabledWebMvc或mvc堆栈使用HandlerMethodArgumentResolver的实现来解析调用@RequestMapping注释的处理程序方法时要使用的参数

对于@RequestParam,该实现是RequestParamMethodArgumentResolver


参数都被收集,然后Spring使用反射来调用处理程序方法。它在调用过程中传递收集的参数。

不清楚。我想,没有必要在jsp中采取坚定的行动。控制器的动作可能仅用于业务逻辑。是。这只是一个例子。您可以设置类变量,我认为您可以使用@requestParam