[英]@RequestParam annotation
我的问题似乎很好奇,因为我是Java的新手。
我已经阅读了有关Java
注释的oracle 课程 。 但是我还不了解他们如何实践。 考虑以下spring framework 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堆栈( @EnabledWebMvc
或<mvc:annotation-driven />
)使用HandlerMethodArgumentResolver
实现来解析调用处理程序方法时使用的参数(以@RequestMapping
注释的方法)。
对于@RequestParam
,该实现为RequestParamMethodArgumentResolver
。
所有的参数都被收集,然后Spring使用反射来调用您的处理程序方法。 它在调用期间传递收集的参数。
您使用的Spring版本中的默认@EnabledWebMvc或<mvc:annotation-driven /> MVC堆栈使用HandlerMethodArgumentResolver
实现来解析调用处理程序方法时要使用的参数(用@RequestMapping
注释的方法)。
对于@RequestParam
,该实现为RequestParamMethodArgumentResolver
。
所有的参数都被收集,然后Spring使用反射来调用您的处理程序方法。 它在调用期间传递收集的参数。
在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.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.