<address id="ttjl9"></address>

      <noframes id="ttjl9"><address id="ttjl9"><nobr id="ttjl9"></nobr></address>
      <form id="ttjl9"></form>
        <em id="ttjl9"><span id="ttjl9"></span></em>
        <address id="ttjl9"></address>

          <noframes id="ttjl9"><form id="ttjl9"></form>

          首頁

          JS學習筆記

          前端達人

          JS學習筆記

          js和java的異同點

          變量聲明

          函數聲明

          js中的變量提升和函數提升

          為什么有變量提升

          總結

          js和java的異同點

          首先,js的語法和kottlin的語法有些相似。比如var,方法聲明用



            function 方法名稱 (參數名稱...){

            //方法內部邏輯

            }



          還有變量類型聲明 :



          數據類型 : 變量名=值



          區別:一:js的數據類型和java類似。只不過js中的數據類型number將java中的int,double,float整合了。

          二:js中可以不用聲明變量類型。變量不聲明數據類型的話,那么他的類型取決于當前的值是什么數據類型。舉例:



          var num=0;

          num-"lyyyyyyyyyyyyyy";

          num=[];

          num={};



          三:js中的類型判斷:



          判斷基本類型,返回一個字符串

          1

          console.log(typeof '');//string

          console.log(typeof []);//object

          console.log(typeof {});//object

          console.log(typeof 1);//number

          console.log(typeof null);//object

          console.log(typeof undefined);//undefined

          console.log(typeof true);//boolean

          console.log(typeof function(){});//function

          console.log(typeof /\d/);//object





          檢查某個對象屬于哪個構造函數,返回true/false

          1

          function A(){};

          function B(){};

          let a = new A();

          console.log(a instanceof A);

          console.log(a instanceof B);

          console.log([] instanceof Array);//true

          console.log({} instanceof Object);//true

          console.log(/\d/ instanceof RegExp);//true

          console.log(function(){} instanceof Object);//true

          console.log(function(){} instanceof Function);//true





          變量聲明

          js的變量聲明其實大體上可以分為三種:var聲明、let與const聲明和函數聲明。



          函數聲明

          doSomething();

           

          function doSomething() {

              console.log('doSomething');

          }

          var foodoSomething= 2;



          你覺得上面會輸出什么?TypeError嗎?其實輸出的結果是foo。這就引出了我們的問題了,當函數聲明與其他聲明一起出現的時候,是以誰為準呢?答案就是,函數聲明高于一切,畢竟函數是js的第一公民。



          那么,下面的例子呢?



          doSomething();

           

          function doSomething() {

              console.log('1');

          }

           

          function doSomething() {

              console.log('2');

          }



          當出現多個函數聲明,那怎么辦呢?以上代碼輸出結果為2。

          因為有多個函數聲明的時候,是由最后面的函數聲明來替代前面的。



          domeSomething();

           

          var domeSomething= function() {

              console.log('domeSomething');

          }



          var domeSomething = function() {}這種格式我們叫做函數表達式。



          它其實也是分為兩部分,一部分是var foo,而一部分是foo = function() {},參照例2,我們可以知道,這道題的結果應該是報了TypeError(因為foo聲明但未賦值,因此foo是undefined)。



          js中的變量提升和函數提升

          在js中對變量進行操作后打印值經常會出現undefined的現象。其實原因是因為js中有一個叫做變量提升的功能。舉例:

          1

          var data="lyyyyy";

          getData();

          function getData(){

          //第一次打印

          console.log("data值為: ", data);

          var data="yyyyyyy";

          //第二次打印

          console.log("data值為: ", data);

          }



          打印的值第一個為undefined,而第二個打印的值為yyyyy.



          原因:

          在執行getData()方法的時候會在函數內部首先將變量的聲明提升到第一步。

          然后再聲明函數內部的函數(如果函數內部有函數的話)。

          之后才會按照方法內部的邏輯先后順序執行代碼。前兩步只是聲明?。?!

          看到這里應該就已經知道為什么會有上面那樣的結果了。



          實際的方法內部代碼執行順序應該是這樣的:



          function getData(){

          //一。聲明變量

          var data;

          //二。聲明函數(如果函數內部有函數的話)



          //三。按照代碼的順序執行

          console.log("data值為: ", data);

          data="yyyyyyy";

          //第二次打印

          console.log("data值為: ", data);

          }



          看到拆分后的代碼執行順序對結果也就不迷茫了。



          為什么有變量提升

          那么為什么會出現變量提升這個現象呢?



          其實js和其他語言一樣,都要經歷編譯和執行階段。而js在編譯階段的時候,會搜集所有的變量聲明并且提前聲明變量,而其他的語句都不會改變他們的順序,因此,在編譯階段的時候,第一步就已經執行了,而第二步則是在執行階段執行到該語句的時候才執行。



          總結

          1.js會將變量的聲明提升到js頂部執行,因此對于這種語句:var a = 2;其實上js會將其分為var a;和a = 2;兩部分,并且將var a這一步提升到頂部執行。



          2.變量提升的本質其實是由于js引擎在編譯的時候,就將所有的變量聲明了,因此在執行的時候,所有的變量都已經完成聲明。

          3.當有多個同名變量聲明的時候,函數聲明會覆蓋其他的聲明。如果有多個函數聲明,則是由最后的一個函數聲明覆蓋之前所有的聲明。


          ————————————————
          版權聲明:本文為CSDN博主的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。


          藍藍設計www.syprn.cn )是一家專注而深入的界面設計公司,為期望卓越的國內外企業提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網站建設 、平面設計服


          postMessage跨域、跨iframe窗口消息傳遞

          前端達人

          文章目錄

          1. 作用
          2. 語法
          3. 使用
          4. 兼容性
          5. 應用場景

            說起postMessage 可能平時大家也不遇到,但是如果遇到問題了,又想不起它,這里記錄下防止后面忘記它。




          6. 作用

            window.postMessage()方法可以安全地實現Window對象之間的跨域通信。例如,在一個頁面和它生成的彈出窗口之間,或者是頁面和嵌入其中的iframe之間。



            通常情況下,受瀏覽器“同源策略”的限制跨域問題一直是個問題,window.postMessage()提供了一個受控的機制來安全地規避這個限制(如果使用得當的話)。


          7. 語法

            一般來說,一個窗口可以獲得對另一個窗口的引用(例如,通過targetWindow=window.opener),然后使用targetWindow.postMessage()在其上派發MessageEvent。接收窗口隨后可根據需要自行處理此事件,傳遞給window.postMessage()的參數通過事件對象暴露給接收窗口。



            基本語法:



            targetWindow.postMessage(message, targetOrigin, [transfer]);

            1

            targetWindow

            targetWindow就是接收消息的窗口的引用。 獲得該引用的方法包括:



            Window.open

            Window.opener

            HTMLIFrameElement.contentWindow

            Window.parent

            Window.frames +索引值

            message

            要發送到目標窗口的消息。 數據使用結構化克隆算法進行序列化。 這意味著我們可以將各種各樣的數據對象安全地傳遞到目標窗口,而無需自己對其進行序列化。



            targetOrigin

            定目標窗口的來源,必須與消息發送目標相一致,可以是字符串或URI。 表示任何目標窗口都可接收,為安全起見,請一定要明確提定接收方的URI。如果為"*"則都可以接收。



            transfer

            可選屬性。是一串和message同時傳遞的Transferable對象,這些對象的所有權將被轉移給消息的接收方,而發送一方將不再保有所有權。


          8. 使用

            postMessage程序



            var receiver = document.getElementById('receiver').contentWindow;

            var btn = document.getElementById('send');

            btn.addEventListener('click', function (e) {

                e.preventDefault();

                var val = document.getElementById('text').value;

                receiver.postMessage("Hello "+val+"!", "http://www.xxx.com");

            }); 



            接收端



            window.addEventListener("message", receiveMessage, false);

            function receiveMessage(event){

              if (event.origin !== "http://www.xxx.com")

                return;

            }



            event對象有三個屬性,分別是origin,data和source。event.data表示接收到的消息;event.origin表示postMessage的發送來源,包括協議,域名和端口;event.source表示發送消息的窗口對象的引用; 我們可以用這個引用來建立兩個不同來源的窗口之間的雙向通信。


          9. 兼容性



            總體兼容性還是很好的!




          10. 應用場景

            跨域通信(包括GET請求和POST請求)

            WebWorker

            vue項目中使用到了iframe并且需要傳遞參數



            ————————————————

            版權聲明:本文為CSDN博主「zy1281539626」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。

            原文鏈接:https://blog.csdn.net/zy1281539626/article/details/114934551


            藍藍設計www.syprn.cn )是一家專注而深入的界面設計公司,為期望卓越的國內外企業提供卓越的UI界面設計BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網站建設 、平面設計服


          SpringBoot與Web開發

          前端達人

          SpringBoot與Web開發(超詳細)

          一、簡介

          二、SpringBoot對靜態資源的映射規則

          1、所有 /webjars/ ,都去 classpath:/META-INF/resources/webjars/ 找資源

          2、"/
          " 訪問當前項目的任何資源,都去靜態資源的文件夾找映射

          3、歡迎頁: 靜態資源文件夾下的所有index.html頁面,被"/"映射

          三、模板引擎

          1、引入Thymeleaf

          2、Thymeleaf的使用

          1、導入thymeleaf的名稱空間

          2、使用thymeleaf語法

          3、Thymeleaf的語法規則

          四、SpringMVC自動配置

          1、Spring MVC auto-configuration

          2、擴展SpringMVC

          原理

          3、全面接管SpringMVC

          原理

          五、如何修改SpringBoot的默認配置

          一、簡介

          使用SpringBoot的步驟:



          1、創建SpringBoot應用,選中我們需要的模塊。

          2、SpringBoot已經默認將這些場景配置好了,只需要在配置文件中指定少量配置就可以運行起來。

          3、自己編寫業務代碼。



          自動配置原理:



          xxxxAutoConfiguration:幫我們給容器中自動配置組件

          xxxxProperties:配置類來封裝配置文件的內容

          1

          2

          二、SpringBoot對靜態資源的映射規則

          @ConfigurationProperties(prefix = "spring.resources", ignoreUnknownFields = false)

          public class ResourceProperties implements ResourceLoaderAware {

            //可以設置和靜態資源有關的參數,緩存時間等

          1

          2

          3

          WebMvcAuotConfiguration:

          @Override

          public void addResourceHandlers(ResourceHandlerRegistry registry) {

          if (!this.resourceProperties.isAddMappings()) {

          logger.debug("Default resource handling disabled");

          return;

          }

          Integer cachePeriod = this.resourceProperties.getCachePeriod();

          if (!registry.hasMappingForPattern("/webjars/
          ")) {

          customizeResourceHandlerRegistration(

          registry.addResourceHandler("/webjars/**")

          .addResourceLocations(

          "classpath:/META-INF/resources/webjars/")

          .setCachePeriod(cachePeriod));

          }

          String staticPathPattern = this.mvcProperties.getStaticPathPattern();

                    //靜態資源文件夾映射

          if (!registry.hasMappingForPattern(staticPathPattern)) {

          customizeResourceHandlerRegistration(

          registry.addResourceHandler(staticPathPattern)

          .addResourceLocations(

          this.resourceProperties.getStaticLocations())

          .setCachePeriod(cachePeriod));

          }

          }



                 //配置歡迎頁映射

          @Bean

          public WelcomePageHandlerMapping welcomePageHandlerMapping(

          ResourceProperties resourceProperties) {

          return new WelcomePageHandlerMapping(resourceProperties.getWelcomePage(),

          this.mvcProperties.getStaticPathPattern());

          }



                //配置喜歡的圖標

          @Configuration

          @ConditionalOnProperty(value = "spring.mvc.favicon.enabled", matchIfMissing = true)

          public static class FaviconConfiguration {



          private final ResourceProperties resourceProperties;



          public FaviconConfiguration(ResourceProperties resourceProperties) {

          this.resourceProperties = resourceProperties;

          }



          @Bean

          public SimpleUrlHandlerMapping faviconHandlerMapping() {

          SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();

          mapping.setOrder(Ordered.HIGHEST_PRECEDENCE + 1);

                        //所有  /favicon.ico 

          mapping.setUrlMap(Collections.singletonMap("
          /favicon.ico",

          faviconRequestHandler()));

          return mapping;

          }



          @Bean

          public ResourceHttpRequestHandler faviconRequestHandler() {

          ResourceHttpRequestHandler requestHandler = new ResourceHttpRequestHandler();

          requestHandler

          .setLocations(this.resourceProperties.getFaviconLocations());

          return requestHandler;

          }



          }





          1、所有 /webjars/ ,都去 classpath:/META-INF/resources/webjars/ 找資源

          webjars:以jar包的方式引入靜態資源。WebJars



          訪問localhost:8080/webjars/jquery/3.3.1/jquery.js的結果:





          2、"/
          " 訪問當前項目的任何資源,都去靜態資源的文件夾找映射

          "classpath:/META-INF/resources/", 

          "classpath:/resources/",

          "classpath:/static/", 

          "classpath:/public/" 

          "/":當前項目的根路徑



          例子:訪問localhost:8080/abc 就是去靜態資源文件夾里面找abc



          例如我們訪問js文件夾下的Chart.min.js:



          訪問結果:





          3、歡迎頁: 靜態資源文件夾下的所有index.html頁面,被"/"映射

          編寫index.html文件。



          訪問結果:





          三、模板引擎

          常見的模板引擎:JSP、Velocity、Freemarker、Thymeleaf(springboot推薦,語法更簡單,功能更強大)





          1、引入Thymeleaf

          Thymeleaf官網



          在pom.xml中添加以下依賴:



           <dependency>

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

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

           </dependency>



          2、Thymeleaf的使用

          @ConfigurationProperties(prefix = "spring.thymeleaf")

          public class ThymeleafProperties {



          private static final Charset DEFAULT_ENCODING = Charset.forName("UTF-8");



          private static final MimeType DEFAULT_CONTENT_TYPE = MimeType.valueOf("text/html");



          public static final String DEFAULT_PREFIX = "classpath:/templates/";



          public static final String DEFAULT_SUFFIX = ".html";



          1

          只要我們把HTML頁面放在classpath:/templates/,thymeleaf就能自動渲染。



          success.html:



          HelloController:



          package com.keafmd.springboot.controller;



          import org.springframework.stereotype.Controller;

          import org.springframework.web.bind.annotation.RequestMapping;

          import org.springframework.web.bind.annotation.ResponseBody;



          /


            Keafmd

           


            @ClassName: HelloController

           
          @Description:

            @author: 牛哄哄的柯南

           
          @date: 2021-03-04 19:54

           */



          @Controller

          public class HelloController {



              @ResponseBody

              @RequestMapping("/hello")

              public String hello(){

                  return "Hello World";

              }



              @RequestMapping("/success")

              public String success() {

                  return "success";

              }

          }



          訪問success的結果:





          1、導入thymeleaf的名稱空間

          <html lang="en" xmlns:th=";

          1

          2、使用thymeleaf語法

          HelloController:



          package com.keafmd.springboot.controller;



          import org.springframework.stereotype.Controller;

          import org.springframework.web.bind.annotation.RequestMapping;

          import org.springframework.web.bind.annotation.ResponseBody;



          import java.util.Map;



          /*

           
          Keafmd

           

           
          @ClassName: HelloController

            @Description:

           
          @author: 牛哄哄的柯南

            @date: 2021-03-04 19:54

           
          /



          @Controller

          public class HelloController {



              @ResponseBody

              @RequestMapping("/hello")

              public String hello(){

                  return "Hello World";

              }



              /*

               
          查出一些數據在頁面顯示

                @param map

               
          @return

               */

              @RequestMapping("/success")

              public String success(Map<String,Object> map) {

                  map.put("hello","你好");

                  return "success";

              }

          }



          success.html:



          <!DOCTYPE html>

          <html lang="en" xmlns:th="
          ;

          <head>

              <meta charset="UTF-8">

              <title>Title</title>

          </head>

          <body>

              <h1>成功</h1>

              <!--th:text 將div里面的文本內容設置為-->

              <div th:text="${hello}"></div>

          </body>

          </html>



          運行結果:





          3、Thymeleaf的語法規則

          1、th:任意html屬性,來替換原生屬性的值



          th:text — 改變當前元素里面的文本內容

          更多參考下圖:



          2、表達式



          Simple expressions:(表達式語法)

              Variable Expressions: ${...}:獲取變量值;OGNL;

              1)、獲取對象的屬性、調用方法

              2)、使用內置的基本對象:

              #ctx : the context object.

              #vars: the context variables.

                          #locale : the context locale.

                          #request : (only in Web Contexts) the HttpServletRequest object.

                          #response : (only in Web Contexts) the HttpServletResponse object.

                          #session : (only in Web Contexts) the HttpSession object.

                          #servletContext : (only in Web Contexts) the ServletContext object.

                          

                          ${session.foo}

                      3)、內置的一些工具對象:

          execInfo : information about the template being processed.

          messages : methods for obtaining externalized messages inside variables expressions, in the same way as they would be obtained using #{…} syntax.

          uris : methods for escaping parts of URLs/URIs

          conversions : methods for executing the configured conversion service (if any).

          dates : methods for java.util.Date objects: formatting, component extraction, etc.

          calendars : analogous to #dates , but for java.util.Calendar objects.

          numbers : methods for formatting numeric objects.

          strings : methods for String objects: contains, startsWith, prepending/appending, etc.

          objects : methods for objects in general.

          bools : methods for boolean evaluation.

          arrays : methods for arrays.

          lists : methods for lists.

          sets : methods for sets.

          maps : methods for maps.

          aggregates : methods for creating aggregates on arrays or collections.

          ids : methods for dealing with id attributes that might be repeated (for example, as a result of an iteration).



              Selection Variable Expressions: {...}:選擇表達式:和${}在功能上是一樣;

              補充:配合 th:object="${session.user}:

             <div th:object="${session.user}">

              <p>Name: <span th:text="
          {firstName}">Sebastian</span>.</p>

              <p>Surname: <span th:text="{lastName}">Pepper</span>.</p>

              <p>Nationality: <span th:text="
          {nationality}">Saturn</span>.</p>

              </div>

              

              Message Expressions: #{...}:獲取國際化內容

              Link URL Expressions: @{...}:定義URL;

              @{/order/process(execId=${execId},execType='FAST')}

              Fragment Expressions: ~{...}:片段引用表達式

              <div th:insert="~{commons :: main}">...</div>

             

          Literals(字面量)

                Text literals: 'one text' , 'Another one!' ,…

                Number literals: 0 , 34 , 3.0 , 12.3 ,…

                Boolean literals: true , false

                Null literal: null

                Literal 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 , or

              Boolean 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: _ 



          注意:內容過多,詳細內容參考官方文檔。



          示例:↓



          HelloController:



          package com.keafmd.springboot.controller;



          import org.springframework.stereotype.Controller;

          import org.springframework.web.bind.annotation.RequestMapping;

          import org.springframework.web.bind.annotation.ResponseBody;



          import java.util.Arrays;

          import java.util.Map;



          /*

           
          Keafmd

           

           
          @ClassName: HelloController

            @Description:

           
          @author: 牛哄哄的柯南

            @date: 2021-03-04 19:54

           
          /



          @Controller

          public class HelloController {



              @ResponseBody

              @RequestMapping("/hello")

              public String hello(){

                  return "Hello World";

              }



              /*

               
          查出一些數據在頁面顯示

                @param map

               
          @return

               */

              @RequestMapping("/success")

              public String success(Map<String,Object> map) {

                  map.put("hello","你好");

                  map.put("hello1","<h1>你好</h1>");

                  map.put("users", Arrays.asList("柯南","小蘭","基德"));

                  return "success";

              }

          }



          success.html:



          <!DOCTYPE html>

          <html lang="en" xmlns:th="
          ;

          <head>

              <meta charset="UTF-8">

              <title>Title</title>

          </head>

          <body>

              <h1>成功</h1>

              <!--th:text 將div里面的文本內容設置為-->

              <div id="div01" class="myDiv" th:id="${hello}" th:class="${hello}" th:text="${hello}">這里的內容被覆蓋</div>



              <hr/>

              <div th:text="${hello1}"></div>

              <div th:utext="${hello1}"></div>

              <hr/>

              <!--th:each 每次遍歷都會生成當前這個標簽-->

              <h4 th:text="${user}" th:each="user:${users}"></h4>

              <hr/>

              <h4>

                  <span th:each="user:${users}"> [[${user}]] </span>

              </h4>

          </body>

          </html>



          效果:







          四、SpringMVC自動配置

          1、Spring MVC auto-configuration

          參考官方文檔:點這里



          Spring Boot 自動配置好了SpringMVC



          以下是SpringBoot對SpringMVC的默認配置:(WebMvcAutoConfiguration)



          Inclusion of ContentNegotiatingViewResolver and BeanNameViewResolver beans.



          自動配置了ViewResolver(視圖解析器:根據方法的返回值得到視圖對象(View),視圖對象決定如何渲染(轉發?重定向?))

          ContentNegotiatingViewResolver:組合所有的視圖解析器的。

          如何定制:我們可以自己給容器中添加一個視圖解析器;自動的將其組合進來。

          Support for serving static resources, including support for WebJars (see below).靜態資源文件夾路徑,webjars



          Static index.html support. 靜態首頁訪問



          Custom Favicon support (see below). favicon.ico



          自動注冊了 of Converter, GenericConverter, Formatter beans.



          Converter:轉換器; public String hello(User user):類型轉換使用Converter

          Formatter :格式化器; 2017.12.17===Date

          @Bean

          @ConditionalOnProperty(prefix = "spring.mvc", name = "date-format")//在文件中配置日期格式化的規則

          public Formatter<Date> dateFormatter() {

              return new DateFormatter(this.mvcProperties.getDateFormat());//日期格式化組件

          }

          1

          2

          3

          4

          5

          自己添加的格式化器轉換器,我們只需要放在容器中即可



          Support for HttpMessageConverters (see below).



          HttpMessageConverter:SpringMVC用來轉換Http請求和響應的;User—Json



          HttpMessageConverters 是從容器中確定;獲取所有的HttpMessageConverter



          自己給容器中添加HttpMessageConverter,只需要將自己的組件注冊容器中(@Bean,@Component)



          Automatic registration of MessageCodesResolver (see below):定義錯誤代碼生成規則



          Automatic use of a ConfigurableWebBindingInitializer bean (see below).



          我們可以配置一個ConfigurableWebBindingInitializer來替換默認的(添加到容器)



          初始化WebDataBinder

          請求數據=====JavaBean

          1

          2

          org.springframework.boot.autoconfigure.web:web的所有自動場景



          If you want to keep Spring Boot MVC features, and you just want to add additional MVC configuration (interceptors, formatters, view controllers etc.) you can add your own @Configuration class of type WebMvcConfigurerAdapter, but without @EnableWebMvc. If you wish to provide custom instances of RequestMappingHandlerMapping, RequestMappingHandlerAdapter or ExceptionHandlerExceptionResolver you can declare a WebMvcRegistrationsAdapter instance providing such components.



          如果你想保持Spring Boot MVC 功能,你只是想添加額外的(MVC配置)(
          https://docs.spring.io/spring/docs/4.3.14.RELEASE/spring-framework-reference/htmlsingle MVC)(攔截器,格式器,視圖控制器等)您可以添加自己的@ configuration類WebMvcConfigurerAdapter類型,但沒有@EnableWebMvc。如果你想提供RequestMappingHandlerMapping, RequestMappingHandlerAdapter或ExceptionHandlerExceptionResolver的自定義實例,你可以聲明一個WebMvcRegistrationsAdapter實例來提供這樣的組件。



          If you want to take complete control of Spring MVC, you can add your own @Configuration annotated with @EnableWebMvc.



          如果你想完全控制Spring MVC,你可以添加你自己的@Configuration注解@EnableWebMvc。



          2、擴展SpringMVC

          實現如下功能:



          <mvc:view-controller path="/hello" view-name="success"></mvc:view-controller>



          <mvc:interceptors>

              <mvc:interceptor>

                  <mvc:mapping path="/hello"/>

                  <bean></bean>

              </mvc:interceptor>

          </mvc:interceptors>



          做法:編寫一個配置類(@Configuration),是WebMvcConfigurerAdapter類型;不能標注@EnableWebMvc



          特點:既保留了所有的自動配置,也能用我們擴展的配置。



          在config包下創建個MyMvcConfig。



          代碼實現:



          package com.keafmd.springboot.config;



          import org.springframework.context.annotation.Configuration;

          import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;

          import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;





          /*

           
          Keafmd

           

           
          @ClassName: MyMvcConfig

            @Description:

           
          @author: 牛哄哄的柯南

            @date: 2021-03-17 20:26

           
          /

          @Configuration

          public class MyMvcConfig implements WebMvcConfigurer {

              @Override

              public void addViewControllers(ViewControllerRegistry registry) {

                  //瀏覽器發送 /keafmd 請求 來到success頁面

                  registry.addViewController("/keafmd").setViewName("success");

              }

          }



          原理

          1、WebMvcAutoConfiguration是SpringMVC的自動配置類。

          2、在做其他自動配置時會導入,@Import(EnableWebMvcConfiguration.class)。



             @Configuration

          public static class EnableWebMvcConfiguration extends DelegatingWebMvcConfiguration {

               private final WebMvcConfigurerComposite configurers = new WebMvcConfigurerComposite();



               //從容器中獲取所有的WebMvcConfigurer

               @Autowired(required = false)

               public void setConfigurers(List<WebMvcConfigurer> configurers) {

                   if (!CollectionUtils.isEmpty(configurers)) {

                       this.configurers.addWebMvcConfigurers(configurers);

                      //一個參考實現;將所有的WebMvcConfigurer相關配置都來一起調用;  

                      @Override

                      // public void addViewControllers(ViewControllerRegistry registry) {

                       //    for (WebMvcConfigurer delegate : this.delegates) {

                        //       delegate.addViewControllers(registry);

                        //   }

                       }

                   }

          }



          3、容器中所有的WebMvcConfigurer都會一起起作用。

          4、我們的配置類也會被調用。



          效果:SpringMVC的自動配置和我們的擴展配置都會起作用。



          3、全面接管SpringMVC

          SpringBoot對SpringMVC的自動配置不需要了,所有都是我們自己配置,所有的SpringMVC的自動配置都失效了。



          做法:我們需要在配置類中添加@EnableWebMvc即可。



          @EnableWebMvc

          @Configuration

          public class MyMvcConfig implements WebMvcConfigurer {

              @Override

              public void addViewControllers(ViewControllerRegistry registry) {

                  //瀏覽器發送 /keafmd 請求 來到success頁面

                  registry.addViewController("/keafmd").setViewName("success");

              }

          }





          全面接管后,靜態資源失效。

          不推薦這樣全面接管。





          原理

          加了@EnableWebMvc自動配置就失效了。



          1、@EnableWebMvc的核心:



          @Import({DelegatingWebMvcConfiguration.class})

          public @interface EnableWebMvc {



          2、DelegatingWebMvcConfiguration



          @Configuration(

              proxyBeanMethods = false

          )

          public class DelegatingWebMvcConfiguration extends WebMvcConfigurationSupport {



          3、WebMvcAutoConfiguration



          @Configuration(

              proxyBeanMethods = false

          )

          @ConditionalOnWebApplication(

              type = Type.SERVLET

          )

          @ConditionalOnClass({Servlet.class, DispatcherServlet.class, WebMvcConfigurer.class})

          //容器中沒有這個組件的時候,這個自動配置類才生效

          @ConditionalOnMissingBean({WebMvcConfigurationSupport.class})

          @AutoConfigureOrder(-2147483638)

          @AutoConfigureAfter({DispatcherServletAutoConfiguration.class, TaskExecutionAutoConfiguration.class, ValidationAutoConfiguration.class})

          public class WebMvcAutoConfiguration {



          4、@EnableWebMvc將WebMvcConfigurationSupport組件導入進來,自動配置類失效了。



          5、導入的WebMvcConfigurationSupport只是SpringMVC最基本的功能。



          五、如何修改SpringBoot的默認配置

          1、SpringBoot在自動配置很多組件的時候,先看容器中有沒有用戶自己配置的(@Bean、@Component)如果有就用用戶配置的,如果沒有,才自動配置;如果有些組件可以有多個(ViewResolver)將用戶配置的和自己默認的組合起來。

          2、在SpringBoot中會有非常多的xxxConfigurer幫助我們進行擴展配置。

          3、在SpringBoot中會有很多的xxxCustomizer幫助我們進行定制配置。



          以上就是SpringBoot與Web開發(超詳細)篇一的全部內容。

          ————————————————

          版權聲明:本文為CSDN博主「牛哄哄的柯南」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。

          原文鏈接:https://blog.csdn.net/weixin_43883917/article/details/114375472


          藍藍設計www.syprn.cn )是一家專注而深入的界面設計公司,為期望卓越的國內外企業提供卓越的UI界面設計BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網站建設 、平面設計服


          凈水機設備界面設計--賞析

          前端達人

          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏


          轉自:站酷

          作者:許小瓶


          藍藍設計www.syprn.cn )是一家專注而深入的界面設計公司,為期望卓越的國內外企業提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網站建設 、平面設計服

          2021UI作品集--設計資源賞析

          前端達人


          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏






          轉自:站酷

          作者:小張翼德Z


          藍藍設計www.syprn.cn )是一家專注而深入的界面設計公司,為期望卓越的國內外企業提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網站建設 、平面設計服



          騰訊Lemon Cleaner改版 設計賞析

          前端達人

          騰訊Lemon Cleaner改版,設計資源賞析

          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏


          轉自:站酷

          作者:小佛v5


          藍藍設計www.syprn.cn )是一家專注而深入的界面設計公司,為期望卓越的國內外企業提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網站建設 、平面設計服

          公司業務全景可視化展示賞析

          前端達人

          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏
          收藏


          轉自:站酷

          作者:Eric孫


          藍藍設計www.syprn.cn )是一家專注而深入的界面設計公司,為期望卓越的國內外企業提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網站建設 、平面設計服

          云店通SaaS系統(B端)

          前端達人

          這個項目在2019年立項,在2020年完成,項目進行中又幾番變動,萬幸最終還是完成了!
          非常感謝團隊中的小伙伴給予的幫助,能夠與你們一起共事非常幸運!

          ------------------------------------------------------------------
          *本次輸出非100%與最終上線稿件相同,有部分設計因開發成本與項目預算原因未能實現!
          *部分商品圖片來源于網絡,僅作為展示與交流使用!
          ------------------------------------------------------------------

          收藏
          收藏
          收藏
          收藏
          收藏
          收藏


          轉自:站酷

          作者:火龍果_pitaya


          藍藍設計www.syprn.cn )是一家專注而深入的界面設計公司,為期望卓越的國內外企業提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網站建設 、平面設計服

          手機appUI界面設計賞析

          前端達人

          移動互聯網的迅速崛起,讓移動網頁,移動客戶端越來越重要,客戶端的頁面設計也是一門很大的學問??萍佳杆侔l展的今手機屏幕的尺寸越來越放大化,但卻始終 很有限,因此,在APP的界面設計中,精簡是一貫的準則。這里所說的精簡并不是內容上盡可能的少量,而是要注重重點的表達。在視覺上也要遵循用戶的視覺邏 輯,用戶看著順眼了,才會真正的喜歡。

          接下來為大家分享精美的app UI設計案例:

          藍藍設計(北京蘭亭妙微科技有限公司)是一家專注而深入的UI設計公司,公司對UI設計的追求一向很高,致力于為卓越的國內外企業提供卓越的手機 ui設計、軟件界面設計、網站設計,用戶研究、交互設計等服務。

          jhk-1615795023016.pngjhk-1615795030849.pngjhk-1615795030849.pngjhk-1615795058578.pngjhk-1615795128660.jpgjhk-1615795162438.png

          --手機appUI設計--

          藍藍設計www.syprn.cn )是一家專注而深入的界面設計公司,為期望卓越的國內外企業提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網站建設 、平面設計服

          網站界面賞析,簡潔,清新--藍藍設計

          前端達人


          網頁中超過95%以上的信息都是通過文字的形式呈現。 然而,頁面文字并非毫無章法的隨意呈現。事實上,更具可讀性、視覺效果以及獨特排版和布局的網頁文本設計,更能吸引用戶,提升用戶愉悅度。這也是為什么越來越多的設計師日益重視網頁排版設計的重要原因。






          網站界面是基于瀏覽器的界面,隨著人們對于用戶體驗要求的不斷提高,BS界面的設計要求也越來越高,




          接下來為大家分享一下我收集到的案例:

          jhk-1612914009798.pngjhk-1615445795533.jpgjhk-1615445805715.jpgjhk-1615445810968.jpgjhk-1615445871742.pngjhk-1615445943142.pngjhk-1615445959669.png


          --網站界面UI設計--

          藍藍設計www.syprn.cn )是一家專注而深入的界面設計公司,為期望卓越的國內外企業提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網站建設 、平面設計服



          日歷

          鏈接

          個人資料

          藍藍設計的小編 http://www.syprn.cn

          存檔

          亚洲va欧美va天堂v国产综合