Day07:环境配置

1、thymeleaf模板引擎

  • 命名空间:<html xmlns:th="http://www.thymeleaf.org">
  • 迭代:

<ul class="list-group"> <li class="list-group-item" th:each="person:${people}"> <span th:text="${person.name}"></span> <span th:text="${person.age}"></span> </li> </ul>

  • 判断对象是否为空:${not #lists.isEmpty(people)}
  • script中访问model的值:
    <script th:inline="javascript"> var single = [[${singlePerson}]]; console.log(single.name + "/" + single.age); </script>
  • html总访问model
    ${entity.properties} th:onclick='"getName(\" + ${person.name} + '\');'"

2、集成Spring MVC

  • 参数中传入Model,给Model添加attribute,即可返回对象及值

3、Web相关配置

  • Spring Boot自动配置:
    ViewResolver
    ContentNegotiatingViewResolber:代理给不同的ViewResolver来处理不同的View; BeanNameViewResolver:controller返回视图名,根据该resolver查找bean的名称为返回字符串的view来渲染视图

4、静态首页,index可以自动映射的路径

classpath:/META-INF/resources/index.html classpath:/resources/index.html classpath:/static/index.html classpath:/public/index.html

5、接管springboot的web配置

  • 完全控制:在@Configuration注解的配置类上,加上@EnableWebMvc注解实现
  • 增加配置:定义配置类并继承WebMvcConfigurerAdapter,不用注解,然后重写方法:

@Override public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController("/xx").setViewName("/xx"); }

6、Servlet容器配置

server.port= server.session-timeout= #用户会话session过期时间,以秒为单位 server.context-path= #配置访问路径,默认为/ server.tomcat.url-encoding= server.tomcat.compression= #tomcat是否开启压缩,默认关闭

7、SSL(secure sockets layer,网络套接层)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容