# 参数传递

Spring MVC 允许以多种方式将客户端中的数据传送到控制器的处理器方法中，包括：

## 查询参数（Query Parameter）

```java
@GetMapping("query")
public String queryParam(
    @RequestParam int page,
    @RequestParam int count) {
    return page + " : " + count;
}
```

```java
@Test
public void queryParam() throws Exception {
      mockMvc.perform(
          MockMvcRequestBuilders.get("/query?page=1&count=5")
      ).andExpect(MockMvcResultMatchers.content().string("1 : 5"));
}
```

## 表单参数（Form Parameter）

```java
@Data
public class PageBounds {
    private int page;
    private int count;
}

@GetMapping("form")
public String form(PageBounds pageBounds) {
  return pageBounds.getPage() + " : " + pageBounds.getCount();
}
```

```java
@Test
public void form() throws Exception {
      mockMvc.perform(
          MockMvcRequestBuilders.get("/form")
          .queryParam("page", "1")
          .queryParam("count", "5")
      ).andExpect(MockMvcResultMatchers.content().string("1 : 5"));
}
```

## 路径变量（Path Variable）

```java
@GetMapping("path/{page}/{count}")
public String pathVariable(
    @PathVariable int page,
    @PathVariable int count) {
    return page + " : " + count;
}
```

```java
@Test
public void pathVariable() throws Exception {
    mockMvc.perform(
        MockMvcRequestBuilders.get("/path/1/5")
    ).andExpect(MockMvcResultMatchers.content().string("1 : 5"));
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bohans.gitbook.io/ji-chu/spring/basic/spring-mvc/kong-zhi-qi-bian-xie-ji-qiao/can-shu-chuan-di.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
