es una anotación de estereotipo. Agrega anotaciones @Controller y @ResponseBody a la clase. Necesitamos importar el paquete org.springframework.web.bind.annotation en nuestro archivo, para implementarlo.
paquete com.javatpoint;
import org.springframework.web.bind.annotation.RestController;
@RestController // usando @RestController anotación
publicclass HomeController {
// cuerpo del controlador
}
informa al resorte para devolver el resultado a la persona que llama.
se usa para proporcionar información de enrutamiento.
Le dice a Spring que cualquier solicitud HTTP debe asignarse al método correspondiente.
Necesitamos importar el paquete org.springframework.web.annotation en nuestro archivo
paquete com.javatpoint;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
publicclass HomeController {
@RequestMapping ( "/ hello" )
public String hello () {
regresar "¡Hola!" ;
}
}
como lo hemos hecho en el siguiente ejemplo.
paquete com.javatpoint;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
publicclass HomeController {
@RequestMapping (value = "/ hello" , method = "GET" )
public String hello () {
regresar "¡Hola!" ;
}
}
Una solicitud GET por localhost: 8080 / hello url se correlacionará con el método hello ().