7.Springboot之web开发

                          自用

要解决的问题:

1.导入静态资源(html之类的(webapp))

2.首页

3.没有写Jsp的地方-------->所以要学模板引擎Thymeleaf

4.装配扩展springmvc

5.增删改查

6.拦截器

7.国际化(中英文切换)

 

1.静态资源

 

 页面放下面这几个包里,localhost:8080都能直接访问到/**是当前目录下

 

Publicresources是我们自己建的

 

2.首页如何定制

我习惯在public这个包里建

名字叫index.html

 

 这样就能直接在8080访问了

 

 

模板引擎   Thymeleaf

现在我们演示一下springboot里面怎么跳转页面

templates目录里面的页面只能通过@controller@RequestMapper(/pig)进行页面跳转进行访问且需要模板引擎的支持

 

下次创建项目的时候记得把这个给勾选上Thymeleaf

 

 

 

引入thymeleaf依赖

<!--引入thymeleaf依赖-->

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-thymeleaf</artifactId>

        </dependency>

 

因为要跳转嘛,跳转到别的页面的东西要在controller层里面写

 

 

 这里我们可以看到,所跳转的页面为test.html

 

 为什么要写在templates下面呢,因为是模板引擎(开个玩笑)  看theymeleaf的源码:  so~

 

 

 模板引擎还有获取值的功能

现在我们试着用模板引擎去获取值

 

  test.html

 

Thymeleaf语法:

 

转译和不转义

 

 

 

 

 效果:

遍历:

 

 

 

 

 把东西遍历出来

 

 

posted @ 2020-02-27 17:47  涂妖教  阅读(170)  评论(0)    收藏  举报