日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 前端技术 > javascript >内容正文

javascript

SpringBoot笔记整理(三)

發(fā)布時(shí)間:2024/7/19 javascript 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SpringBoot笔记整理(三) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

SpringBoot筆記整理(一)
SpringBoot筆記整理(二)
SpringBoot筆記整理(三)
SpringBoot筆記整理(四)

Web開(kāi)發(fā)

1、使用SpringBoot:

1)創(chuàng)建SpringBoot應(yīng)用,選中需要的模塊
2)SpringBoot已經(jīng)默認(rèn)將這些場(chǎng)景配置好了,只需要在配置文件中指定少量配置就可以運(yùn)行起來(lái)
3)自己編寫(xiě)業(yè)務(wù)代碼

自動(dòng)配置原理

xxxAutoConfiguration:幫我們給容器中自動(dòng)配置組件 xxxProperties:配置類(lèi)來(lái)封裝配置文件的內(nèi)容

2、SpringBoot對(duì)靜態(tài)資源的映射規(guī)則

@ConfigurationProperties(prefix = "spring.resources",ignoreUnknownFields = false ) public class ResourceProperties {//可以設(shè)置和靜態(tài)資源有關(guān)的參數(shù),緩存時(shí)間等 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));}} }//配置歡迎頁(yè)映射 @Bean public WelcomePageHandlerMapping welcomePageHandlerMapping(ApplicationContext applicationContext, FormattingConversionService mvcConversionService, ResourceUrlProvider mvcResourceUrlProvider) {WelcomePageHandlerMapping welcomePageHandlerMapping = new WelcomePageHandlerMapping(new TemplateAvailabilityProviders(applicationContext), applicationContext, this.getWelcomePage(), this.mvcProperties.getStaticPathPattern());welcomePageHandlerMapping.setInterceptors(this.getInterceptors(mvcConversionService, mvcResourceUrlProvider));return welcomePageHandlerMapping; }

1)所有/webjars/**,都去classpath:/META-INF/resources//webjars/找資源
webjars:以jar包的方式引入靜態(tài)資源;
https://www.webjars.org/

<dependency><groupId>org.webjars</groupId><artifactId>jquery</artifactId><version>3.4.1</version> </dependency>

2)“/**”訪問(wèn)當(dāng)前項(xiàng)目的任何資源(靜態(tài)資源的文件夾)

"classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/" "/":當(dāng)前項(xiàng)目的根路徑

3)歡迎頁(yè):靜態(tài)資源文件夾下的所有index.html頁(yè)面,被"/"映射
4)所有的
/favicon.ico 都是在靜態(tài)資源文件下找

3、模板引擎

SpringBoot推薦的Thymeleaf:語(yǔ)法更簡(jiǎn)單,功能更強(qiáng)大
3.1 引入Thymeleaf

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

3.2 Thymeleaf使用&語(yǔ)法

@ConfigurationProperties(prefix = "spring.thymeleaf" ) public class ThymeleafProperties {private static final Charset DEFAULT_ENCODING;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頁(yè)面放在classpath:/templates/,thymeleaf就能自動(dòng)渲染

使用:
3.2.1 導(dǎo)入thymeleaf的名稱(chēng)空間

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

3.2.2 使用thymeleaf語(yǔ)法

<!DOCTYPE html> <html lang="en" xmlns:th="http://www/thymeleaf.org"> <head><meta charset="UTF-8"><title>Title</title> </head> <body><h1>success</h1><!--th:text 將div里面的文本內(nèi)容設(shè)置為--><div th:text="${hello}">這里顯示歡迎信息</div> </body> </html>

1)th:text:改變當(dāng)前元素里面的文本內(nèi)容
th:任意html屬性,來(lái)替換原生屬性的值

2)表達(dá)式語(yǔ)法

Simple expressions:Variable Expressions: ${...}Selection Variable Expressions: *{...}Message Expressions: #{...}Link URL Expressions: @{...}Fragment Expressions: ~{...} LiteralsText literals: 'one text', 'Another one!',...Number literals: 0, 34, 3.0, 12.3,...Boolean literals: true, falseNull literal: nullLiteral tokens: one, sometext, main,... Text operations:String concatenation: +Literal substitutions: |The name is ${name}| Arithmetic operations:Binary operators: +, -, *, /, %Minus sign (unary operator): - Boolean operations:Binary operators: and, orBoolean negation (unary operator): !, not Comparisons and equality:Comparators: >, <, >=, <= (gt, lt, ge, le)Equality operators: ==, != (eq, ne)Conditional operators:If-then: (if) ? (then)If-then-else: (if) ? (then) : (else)Default: (value) ?: (defaultvalue) Special tokens:No-Operation: _

總結(jié)

以上是生活随笔為你收集整理的SpringBoot笔记整理(三)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。