簡體   English   中英

@RequestParam批注

[英]@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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM