concept controller class in category spring

appears as: controller class, The controller class
Spring Security in Action

This is an excerpt from Manning's book Spring Security in Action.

Let’s also create a simple endpoint to test the security configuration. I added a controller class, as presented in the next code snippet.

In listing 10.1, you find the definition of the controller class with the two endpoints we use for a test.

We’ll define a controller class having an action for the main page and a REST endpoint. Because the class is a normal Spring MVC @Controller class, for the REST endpoint, we also have to add the @ResponseBody annotation explicitly. Listing 10.20 presents the definition of the controller.

Listing 10.20 The definition of the controller class
@Controller
public class MainController {
 
  private Logger logger =    #A
          Logger.getLogger(MainController.class.getName());
 
  @GetMapping("/")    #B
  public String main() {
    return "main.html";
  }
 
  @PostMapping("/test")
  @ResponseBody
  public String test() {    #C
    logger.info("Test method called");
    return "HELLO";
  }
}