# Controllers

Controllers are easy to implement:

```java
@Controller
@RequestMapping("/")
public class HomeController
```

HTTP operations are mapped with specific annotations:

```java
@GetMapping(produces = MediaType.TEXT_HTML_VALUE)
public final String showWelcome()
```

All the HTTP verbs can be mapped. This can be chosen by usin the specific annotations or the generic one:

```java
@RequestMapping(method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
public final String showWelcome()
```

## REST Controller

There is a specific annotation for REST controllers:

```java
@RestController
@RequestMapping("/employees")
public class EmployeeController
```

This adds the @ResponseBody annotation, indicating that the values returned by annotated methods will be stored in the response body.

Otherwise operations make use of the same mappings:

```java
@GetMapping(produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public final Iterable<Employee> getEmployees(final Pageable page)
```


---

# 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://bernardo.gitbook.io/development-docs-java/spring-mvc/controllers.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.
