Web开发(提前)

使用SpringBoot:

  1.创建SpringBoot应用,选中我们需要的模块

  2.SpringBoot已经默认将这些场景配置好了。只需要在配置文件中指定少量配置就可运行起来。

  3.自己编写业务代码。

    | 主要要明白其自动配置原理:

      》这个场景SpringBoot帮我们配置了什么?能不能修改?以及修改哪些配置,和能否扩展之类。

      

XXXXXAutoConfiguration:帮我们给容器中自动配置组件。

XXXXXProperties:配置类来封装配置文件的内容。

 

  

SpringBoot对静态资源的映射规则

                   

 

 

 

 

  1.所有/webjars/**,都去里面找资源。

 

 

          

 

 

 

 

      | webjars:以jar包的方式引入静态资源。参考:https://www.webjars.org/。以maven依赖的方式加入。例:

 

 

                          

 

 

 

  2."/**"访问当前项目的任何资源。(静态资源的文件夹)

            这张图中是存放静态资源的路径,没有就创建这个名字的文件夹:

 

 

    localhost:8080/abc === 去静态资源文件夹(就是存放静态资源的那些文件夹)里面找abc          

 

 

 

 

 

 

 

      3.欢迎页面,静态资源文件夹下的所有index.html页面,被"/**"映射

      即,就算只输入localhost:8080,他就会去找index.html。

    

     4.放图标:这个玩意儿

 

 

      所有的**/favicon.ico,都是在静态资源文件夹下面找(将图标改名成favicon.ico放入静态资源文件夹下即可

             另外,在web项目中,如果自定义了Web相关组件或拦截器也有可能导致无法显示,可对其进行有针对性的排查。

 

          改变静态资源路径:

      

 

 

 

模板引擎

  | jsp,velocity,Freemarker,Thymeleaf

   

 

 

   

  | SpringBoot推荐的Thymeleaf。

    》语法更简单,功能更强大。

  

  1.引入Thymeleaf

<!--在pom.xml中-->
<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
<!--在pom.xml中修改
thymeleaf
版本-->
<properties>
        <java.version>1.8</java.version>
        <thymeleaf.version>3.0.10.RELEASE</thymeleaf.version>
<!--布局功能的支持程序,thymeleaf3主程序,layout2以上版本-->
        <thymeleaf-layout-dialect.version>2.4.0</thymeleaf-layout-dialect.version>

    </properties>

 

thymeleaf的使用和语法
  | 默认规则:  
public static final String DEFAULT_PREFIX = "classpath:/templates/";//路径
    public static final String DEFAULT_SUFFIX = ".html";
    private boolean checkTemplate = true;
    private boolean checkTemplateLocation = true;
    private String prefix = "classpath:/templates/"; //前缀
    private String suffix = ".html";          //后缀
    private String mode = "HTML";

       只要我们把HTML页面放在类路径下的classpath:/templates/,然后thymeleaf就能自动渲染了

     使用:

      1.导入thymeleaf的名称空间(语法提示)        

<html lang="en" xmlns:th="http://www.thymeleaf.org">

 

        2.使用thymeleaf的语法        

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>成功!!!</h1>
<!--th:text="${H}"将div里面的文本设置为传过来的数据-->
    <div th:text="${H}">


    </div>

</body>
</html>

        

        3.语法规则

            

 

 

 

 

            》th:text    :改变当前元素里面的文本内容

              th:可以使用任意html属性,会替换原生属性的值。

       | 一些表达式

         

后面的内容都去java里面的SpringBoot里面的web笔记找

 

 

 

 

posted @ 2020-07-31 11:06  初雨了然  阅读(5)  评论(0)    收藏  举报