卜若的代码笔记系列-Web系列-SpringBoot-第二十八章:springboot的动态网页

1.有时候我们会有一些特别的需求比如我们希望在请求服务器某个页面时,服务器能够根据特殊情况发送一些其他信息,这就叫动态网页。

1.1 Springboot的动态网页支持

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

 引入这个包,之后的相关操作你们可以去搜索一下百度,因为我这边还配置了static的路径,所以我的配置不一定适合你。

1.2 返回动态页面

通常情况下,我们会喜欢使用jsp,尤其是在SpringMVC框架下面,但是更多的情况,我们其实喜欢使用html,而对于h5来讲也提供了相关的支持。

从后台返回前台一个动态页面几个非常重要的点

1.2.1 @Controller的批注

请注意,你需要使用@Controller而不是@RestController批注

1.2.2 返回的页面保存在

你可以自定义这个文件夹,如果没有的话。

1.2.3 一个例子


@Controller
public class TestDynamicPage {


    @GetMapping("/testgetpage")
    public String getTestPage(Model model){

        System.out.println("123");
        model.addAttribute("h1","你爸爸");
        return "testPage.html";
    }
}

1.3 在前端如何接受这个数据?

h5提供了相关支持

扫描二维码关注公众号,回复: 10752992 查看本文章
发布了225 篇原创文章 · 获赞 11 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_37080133/article/details/105413332