In this lesson, we talk about the use of controller:
Next, you'll demonstrate the use of templates:
Change the @restcontroller into a controller.
Then start the project and find the error.
In console:
Configure in Pom.xml:
Then add a directory to the resources named templates and create a new index.html in the templates:
The changes in Hellocontroller.java are as follows:
To access the browser:
This is actually equivalent to a JSP, except that the template engine uses Thymeleaf.
This approach is not recommended and will result in a lot of performance loss.
Use @controller and @responsebody instead of @restcontroller
To access the browser:
See here understand that actually @restcontroller this annotation is used to return the JSON data, without adding the words is to return the page.
New requirements Come: if we want to access through Hello also want to access through Hi, how to deal with it?
Change to:
We can also add @requestmapping to the entire class:
To access the browser:
If we want to change the method to post, this time directly through the browser is not directly accessible, you can use the Postman tool:
Then if the method is not written, both methods can be accessed, but not recommended, because the respective application scenarios, specific can see my next article.
Next, look at the @pathvariable:
will be as follows:
Change to:
To access the browser:
You can also write this:
To access the browser:
There is another way:
To access the browser:
There are several properties in the @RequestParam to understand:
To access the browser:
@RequestMapping can be simplified:
can also be used @postmapping () depending on the situation
Spring Boot Learning (lesson three)