Spring Boot: Controllers
The component where you map routes to the model and view
In Spring, a controller class starts with the annotation @Controller
right before the start of the class, like this:
@Controller
public class UserInterfaceApplication {
The import that defines @Controller
is:
import org.springframework.stereotype.Controller;
Inside, you’ll see methods such as this one for using Mustache templates:
@RequestMapping("/index.html")
public String index(final Map<String, Object> map) throws HttpAction {
map.put("fname", "Phill");
map.put("lname", "Conrad");
return "index";
}
Or this one for using Freemarker templates:
…
More on Spring Boot: Controllers
- Spring Boot: Ajax—Communicating between front-end JavaScript and backend Java using XMLHTTP requests
- Spring Boot: Annotations—The various things starting with @ that are particular to Spring and Spring Boot
- Spring Boot: Command Line—A Command Line program within the Spring Boot framework
- Spring Boot: Configuration—The src/resources/application.yml file, and how to fix 'Could not resolve placeholder ${salt}' type errors
- Spring Boot: Controllers—The component where you map routes to the model and view
- Spring Boot: Example Projects—Links to various Spring Boot Projects of interest
- Spring Boot: Heroku—Running Spring Boot Applications On Heroku
- Spring Boot: HTTPS—Enabling HTTPS
- Spring Boot: Logging—How to handle logging in Spring Boot
- Spring Boot: main—What the main program looks like in a Spring Boot Application
- Spring Boot: OAuth—Social login with Spring Boot
- Spring Boot: Starter Parent—What does the `parent` section in the pom.xml do?