SpringBoot-Web开发-静态资源导入、首页定制、Thymeleaf、Thymeleaf基础语法以及使用

本文介绍了SpringBoot中如何导入和处理静态资源,包括webjars和不同目录下的静态资源优先级。接着讲解了如何定制首页,并探讨了Thymeleaf模板引擎的安装、配置以及基础语法,如变量表达式、选择表达式、国际化内容获取和URL定义等。最后,通过创建Controller和HTML页面展示了Thymeleaf的实际应用。
摘要由CSDN通过智能技术生成

jar:webapp
自动装配
springboot:配置、能不能修改、哪些可以修改、能否扩展
xxxAutoConfiguration向容器中自动配置组件
XXXProperties:自动装配类,装配配置文件中的自定义的一些内容

web开发需求:
1.导入静态资源
2.首页
3.jsp,模板引擎Thymeleaf
4.装配扩展SpringMVC
5.增删改查
6.拦截器
7.国际化

静态资源导入

双击shift搜索WebMvcAutoConfiguration,在ctrl+f找到addResourceHandlers,分析WebMvcAutoConfiguration下的addResourceHandlers 关于静态资源导入解决方法

public void addResourceHandlers(ResourceHandlerRegistry registry) {
//如果自定义资源已经被导入
        if (!this.resourceProperties.isAddMappings()) {
            logger.debug("Default resource handling disabled");
        } else {
            Duration cachePeriod = this.resourceProperties.getCache().getPeriod();
            CacheControl cacheControl = this.resourceProperties.getCache().getCachecontrol().toHttpCacheControl();
            if (!registry.hasMappingForPattern("/webjars/**")) {
                this.customizeResourceHandlerRegistration(registry.addResourceHandler(new String[]{"/webjars/**"}).addResourceLocations(new String[]{"classpath:/META-INF/resources/webjars/"}).setCachePeriod(this.getSeconds(cachePeriod)).setCacheControl(cacheControl));
            }

            String staticPathPattern = this.mvcProperties.getStaticPathPattern();
            if (!registry.hasMappingForPattern(staticPathPattern)) {
                this.customizeResourceHandlerRegistration(registry.addResourceHandler(new String[]{staticPathPattern}).addResourceLocations(WebMvcAutoConfiguration.getResourceLocations(this.resourceProperties.getStaticLocations())).setCachePeriod(this.getSeconds(cachePeriod)).setCacheControl(cacheControl));
            }

        }
    }

第一种导入方式:去wenjars上找
if (!registry.hasMappingForPattern("/webjars/")) {
this.customizeResourceHandlerRegistration(registry.addResourceHandler(new String[]{"/webjars/
"}).addResourceLocations(new

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值