First, the Knowledge point
@Controller |
Processing HTTP requests (deprecated) |
@RestController |
Spring4 after the new annotation, the original return JSON requires @responsebody mates @controller |
@RequestMapping |
Configuring URL Mappings |
Second, the specific use of the explanation
[Email protected] (understand, now the development is basically a front-end separation, no longer use the template, the rest of the way to return JSON data is mainstream)
Needs to be used with the template
1) Open Pom.xml
Add one of the official spring templates Thymeleaf
<dependency> <groupId>org.springframework.boot</groupId> <artifactId> Spring-boot-starter-thymeleaf</artifactid> </dependency>
2) under Resources, create a new folder templates, and then create a new html,index.html in it
< H1 >Hello Spring boot! </ H1 >
3) Controller will change @restcontroller to @controller
Package Com.dechy.girl.girl;import Org.springframework.beans.factory.annotation.autowired;import Org.springframework.beans.factory.annotation.value;import Org.springframework.stereotype.controller;import Org.springframework.web.bind.annotation.requestmapping;import Org.springframework.web.bind.annotation.requestmethod;import Org.springframework.web.bind.annotation.RestController, @Controllerpublic class Hellocontroller { @Autowired private girlproperties girlproperties; @RequestMapping (value = "/hello", method = requestmethod.get) public String say () { return ' index '; }}
4) After launch, access to the content of index.html
Use of the Spring boot controller