SpringBoot—页面返回

Controller返回ftl、html页面

 1、引入freemarker依赖,用于ftl页面返回;pom引入thymeleaf依赖,用于HTML页面返回

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

2、controller层代码段

@Controller
@RequestMapping("/test")
public class TestController {
	
	@RequestMapping("/ftl") //返回ftl页面
	public ModelAndView test() {
		return new ModelAndView("ftl/hello");
	}
	
	@RequestMapping("/html") //返回HTML页面
	public String html() {
		
		return "html/hello";
	}
	
	@RequestMapping("/string") //返回字符串
	@ResponseBody
	public String rest() {
		return "string";
	}
	
	@RequestMapping("/jsp")
	public String jsp() {
		
		return "hello";
	}
}

3、所返回页面文件路径

ftl文件路径:/src/main/resources/templates/ftl/hello.ftl

html文件路径:/src/main/resources/templates/html/hello.html

猜你喜欢

转载自blog.csdn.net/weixin_38772170/article/details/82499353