I am using spring boot to try and build my own mini website.
I have a controller
package hello;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
@RestController
public class HelloController {
@RequestMapping("/greeting")
public String index() {
return "index";
}
}
and a html file resources/templates/index which I am trying to render but I just get the text "index" rendered. How can I return the html file instead of the text?
You have specified @RestController
which says the result should be put into the @ResponseBody
. You would want to use @Controller
instead and then make sure you have a template framework (Thymeleaf, etc) in the classpath. Normally with most template frameworks you have to include the .html
on the file that is within the templates
folder.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.