1. 程式人生 > >Spring MVC使用篇(四)—— 檢視解析器

Spring MVC使用篇(四)—— 檢視解析器

文章目錄

1、檢視解析器簡介

  在Spring MVC的流程中最終返回給使用者的檢視為具體的View物件,並且View物件中包含了model中的反饋資料。而檢視解析器ViewResolver的作用就是,把一個邏輯上的檢視名稱解析為一個真正的檢視,即將邏輯檢視的名稱解析為具體的View物件,讓View物件去處理檢視,並將帶有返回資料的檢視反饋給客戶端。

2、演示案例環境搭建

  本文仍以之前的水果商城顯示全部水果資訊為例,具體環境搭建分為以下幾步:

  • 第一步,在web.xml中配置前端控制器(DispatcherServlet),具體配置資訊如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0"> <servlet> <servlet-name>dispatcher</
servlet-name
>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/config/springmvc.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>*.action</url-pattern> </servlet-mapping> <!--post中文亂碼過濾器--> <filter> <filter-name>CharacterEncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> </filter> <!--該配置表示,名為CharacterEncodingFilter的過濾器對所有請求進行過濾,然後該過濾器會 以encoding指定的編碼格式對請求資料進行統一編碼--> <filter-mapping> <filter-name>CharacterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
  • 第二步,在核心配置檔案springmvc.xml中利用基於註解的方式,配置處理器對映器和介面卡,並配置自動掃描,具體配置資訊如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
		http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
		http://www.springframework.org/schema/mvc
		http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
		http://www.springframework.org/schema/context
		http://www.springframework.org/schema/context/spring-context-3.2.xsd
		http://www.springframework.org/schema/aop
		http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
		http://www.springframework.org/schema/tx
		http://www.springframework.org/schema/tx/spring-tx-3.2.xsd ">

    <!--基於註解的方式配置處理器對映器和介面卡方法一-->
    <!--配置基於註解的處理器介面卡與處理器對映器-->
    <mvc:annotation-driven/>

    <!--基於註解的方式配置處理器對映器和介面卡方法二-->
    <!--註解對映器-->
    <!--<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" />-->
    <!--註解介面卡-->
    <!--<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter" />-->

    <!--使用掃描配置,對某一個包下面的所有類進行掃描,
    找出所有使用@Controller註解的Handler控制器類-->
    <context:component-scan base-package="com.ccff.controller"/>

    <!--配置檢視解析器-->
    <!-- 新增接下來的各種檢視解析器配置 -->
</beans>
  • 第三步,基於註解的控制器Handler程式碼如下:
package com.ccff.controller;

import com.ccff.model.Fruits;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

//基於註解的Handler類
//使用@Controller來標識它是一個控制器
@Controller
@RequestMapping("/query")
public class FruitsController {

    private FruitsService fruitsService = new FruitsService();

    //@RequestMapping實現對方法和url進行對映,一個方法對應一個url
    //一般建議將url和方法寫成一樣的
    @RequestMapping("/queryAllFruits.action")
    public String queryAllFruits(Model model){
        //模擬service獲取水果商品列表
        List<Fruits> fruitsList = fruitsService.queryFruitsList();
        //將結果放到model中傳到顯示頁面中
        model.addAttribute("fruitsList",fruitsList);
        return "/fruits/fruitsList";
    }
}

class FruitsService{
    public List<Fruits> queryFruitsList(){
        List<Fruits> fruitsList = new ArrayList<Fruits>();

        Fruits apple = new Fruits();
        apple.setId(1);
        apple.setName("紅富士蘋果");
        apple.setPrice(2.3);
        apple.setProducing_area("山東");

        Fruits banana = new Fruits();
        banana.setId(2);
        banana.setName("香蕉");
        banana.setPrice(1.5);
        banana.setProducing_area("上海");

        fruitsList.add(apple);
        fruitsList.add(banana);
        return fruitsList;
    }
}
  • 第四步,jsp頁面的編寫,程式碼如下:
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>   
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
<html>  
<head>  
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
  <title>水果列表</title>  
</head>  
<body>
  <h3>水果列表</h3>
  <table width="300px;" border=1>  
    <tr>
      <td>編號</td>
      <td>名稱</td>  
      <td>價格</td>    
      <td>產地</td> 
   </tr>  
   <c:if test="${fruitsList==null}">
      <b>水果商品資訊為空!</b>
   </c:if>
   <c:forEach items="${fruitsList}" var="fruit">
     <tr>
       <td>${fruit.id }</td>
       <td>${fruit.name }</td>  
       <td>${fruit.price }</td>    
       <td>${fruit.producing_area }</td>  
     </tr>  
    </c:forEach>  
   </table>   
</body>
</html> 

3、AbstractCa chingViewResolver

  該類作為一個抽象類,實現了該抽象類的檢視解析器會將其曾經解析過的檢視進行快取,當再次解析檢視的時候,它會首先在快取中尋找該檢視,如果找到,就返回相應的檢視物件,如果沒有在快取中找到,就建立一個新的檢視物件,在返回的同時,將其放置到存放快取資料的map物件中。實現該抽象類的檢視解析器類,檢視解析的能力會大大提高。

4、UrlBasedViewResolver

  該類是對ViewResolver的一種簡單實現,它繼承了抽象類AbstractCachingViewResolver(也就是說它具有對已解析檢視進行快取的功能)。

   UrlBasedViewResolver是一種通過拼接資原始檔的URI路徑來展示檢視的一種解析器。

  • 它通過prefix屬性指定檢視資源所在路徑的字首資訊;
  • 通過suffix屬性指定檢視資源所在路徑的字尾資訊(一般是檢視檔案的格式);
  • 當ModelAndView物件返回具體的View名稱時,它會將字首prefix與字尾suffix與具體檢視名稱拼接,得到一個檢視資原始檔的具體載入路徑,從而載入真正的檢視檔案並反饋給使用者。

   例如字首屬性prefix配置的值為“、WEB-INF/jsp”,字尾屬性suffix配置的值為“.jsp”,ModelAndView中View檢視的名稱為“/user/login”,那麼UrlBasedViewResolver最終解析出來的檢視資原始檔的載入路徑就為“/WEB-INF/jsp/user/login/jsp”。需要注意的是,預設的prefix與suffix都為空值。

   UrlBasedViewResolver支援返回的檢視名稱中含有“redirect:”及“forward:”字首,即支援檢視的“重定向”和“內部跳轉”設定。例如,當檢視名稱為“redirect:login.action”時,UrlBasedViewResolver會把返回的檢視名稱字首“redirect:”去掉,取後面的login.action組成一個RedirectView,在RedirectView中把請求返回的model模型屬性組合成查詢引數的形式,組合到redirect的URL後面,然後呼叫HttpServletRequest物件的sendRedirect方法進行重定向。而如果名稱中包含“forward:”,檢視名稱會被封裝成一個InternalResourceView物件,然後在伺服器端利用RequestDispatcher的forward方式跳轉到指定地址。

  使用UrlBasedViewResolver除了要配置字首屬性prefix和字尾屬性suffix之外,還要配置一個“viewClass”,表示解析成哪種檢視。若展示JSP頁面,出於安全性考慮,jsp檔案通常放在WEB-INF目錄下(該目錄下內容是不能直接通過request請求的方式請求到的),而InternalResourceView在伺服器端以跳轉的方式可以很好的解決該問題。

注意:要使用jstl標籤展現資料,就要使用JstlView。

  在springmvc.xml中配置UrlBasedViewResolver檢視解析器顯示水果商城全部水果商品資訊,配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
		http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
		http://www.springframework.org/schema/mvc
		http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
		http://www.springframework.org/schema/context
		http://www.springframework.org/schema/context/spring-context-3.2.xsd
		http://www.springframework.org/schema/aop
		http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
		http://www.springframework.org/schema/tx
		http://www.springframework.org/schema/tx/spring-tx-3.2.xsd ">

    <!--基於註解的方式配置處理器對映器和介面卡方法一-->
    <!--配置基於註解的處理器介面卡與處理器對映器-->
    <mvc:annotation-driven/>

    <!--使用掃描配置,對某一個包下面的所有類進行掃描,
    找出所有使用@Controller註解的Handler控制器類-->
    <context:component-scan base-package="com.ccff.controller"/>

    <!--配置UrlBasedViewResolver檢視解析器-->
    <bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="prefix" value="/WEB-INF/jsp" />
        <property name="suffix" value=".jsp" />
        <property name="viewClass" value="org.springframework.web.servlet.view.InternalResourceView" />
    </bean>

</beans>

  將專案部署到Tomcat上,執行後結果如下,說明UrlBasedViewResolver檢視解析器配置正確,正常執行:
在這裡插入圖片描述

5、InternalResourceViewResolver

  InternalResourceViewResolver名為“內部資源檢視解析器”,是在日常開發中最常用的檢視解析器型別。它是UrlBasedViewResolver的子類,擁有UrlBasedViewResolver的一切特性。

  InternalResourceViewResolver自身的特點是:它會把返回的檢視名稱自動解析為InternalResourceView型別的物件,而InternalResourceView會把Controller處理器方法返回的模型屬性都存放到對應的request屬性中,然後通過RequestDispatcher在伺服器端把請求重定向到目標URL。也就是說,InternalResourceViewResolver檢視解析的時候,無須在單獨執行viewClass屬性了。

  在springmvc.xml中配置InternalResourceViewResolver檢視解析器顯示水果商城全部水果商品資訊,配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
		http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
		http://www.springframework.org/schema/mvc
		http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
		http://www.springframework.org/schema/context
		http://www.springframework.org/schema/context/spring-context-3.2.xsd
		http://www.springframework.org/schema/aop
		http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
		http://www.springframework.org/schema/tx
		http://www.springframework.org/schema/tx/spring-tx-3.2.xsd ">

    <!--基於註解的方式配置處理器對映器和介面卡方法一-->
    <!--配置基於註解的處理器介面卡與處理器對映器-->
    <mvc:annotation-driven/>

    <!--使用掃描配置,對某一個包下面的所有類進行掃描,
    找出所有使用@Controller註解的Handler控制器類-->
    <context:component-scan base-package="com.ccff.controller"/>

    <!--配置檢視解析器-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp"/>
        <property name="suffix" value=".jsp"/>
    </bean>  
</beans>

  上面配置實現了,當一個被請求的Controller處理器方法返回一個名為“/fruits/fruitsList”的檢視時,InternalResourceViewResolver會將“/fruits/fruitsList”解析成一個nternalResourceView的物件,然後將返回的model模型屬性資訊存放到對應的HttpServletRequest屬性中,最後利用RequestDispatcher在伺服器端把請求forward到“/WEB-INF/jsp/fruits/fruitsList.jsp”上。

  將專案部署到Tomcat上,執行後結果如下,說明InternalResourceViewResolver檢視解析器配置正確,正常執行:
在這裡插入圖片描述

6、XmlViewResolver

  該檢視解析器也繼承了AbstractCachingViewResolver抽象類(具有快取檢視頁面的能力)。

  使用XmlViewResolver需要新增一個xml配置檔案,用於定義檢視的bean物件。當獲得Controller方法返回的檢視名稱後,XmlViewResolver會到指定的配置檔案中尋找對應name名稱的檢視bean配置,解析並處理該檢視。

  如果不指定XmlViewResolver的配置檔案,那麼預設配置檔案為/WEB-INF/views.xml,如果不想使用預設值,可以在springmvc.xml的配置檔案中配置XmlViewResolver時,指定其location屬性,在value中指定配置檔案所在的位置。

  在springmvc.xml中配置XmlViewResolver檢視解析器顯示水果商城全部水果商品資訊,配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
		http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
		http://www.springframework.org/schema/mvc
		http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
		http://www.springframework.org/schema/context
		http://www.springframework.org/schema/context/spring-context-3.2.xsd
		http://www.springframework.org/schema/aop
		http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
		http://www.springframework.org/schema/tx
		http://www.springframework.org/schema/tx/spring-tx-3.2.xsd ">

    <!--基於註解的方式配置處理器對映器和介面卡方法一-->
    <!--配置基於註解的處理器介面卡與處理器對映器-->
    <mvc:annotation-driven/>

    <!--使用掃描配置,對某一個包下面的所有類進行掃描,
    找出所有使用@Controller註解的Handler控制器類-->
    <context:component-scan base-package="com.ccff.controller"/>

    <!--配置檢視解析器-->
    <bean class="org.springframework.web.servlet.view.XmlViewResolver">
        <property name="location" value="/WEB-INF/config/views.xml" />
        <property name="order" value="1" />
    </bean>
</beans>

  在上面的配置中,設定了一個屬性“order”,它的作用是,在配置有多重型別的檢視解析器的情況下(即使有ViewResolver鏈),order會指定該檢視解析器的處理檢視的優先順序,order的值越小優先順序越高。特別要說明的是,order屬性在 所有實現Ordered介面的檢視解析器中都適用。

  檢視XML配置檔案views.xml的配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

	<!-- Controller中方法的返回值返回該檢視的id -->
    <bean id="fruitsList" class="org.springframework.web.servlet.view.InternalResourceView">
        <property name="url" value="/WEB-INF/jsp/fruits/fruitsList.jsp" />
    </bean>

</beans>

  views.xml配置檔案遵循的DTD規則和Spring的bean工廠配置檔案相同,所以bean中的標籤規範與springmvc.xml中的bean相關的規範相同。在上面的配置中添加了一個id為“fruitsList”的InternalResourceView檢視型別的bean配置,其中配置了url的對映引數。當Controller返回一個名為“fruitsList”的檢視時,XmlViewResolver會在views.xml配置檔案中尋找相關的bean配置中包含的id的檢視配置,並遵循bean配置的View檢視型別進行檢視的解析,將最終的檢視頁面顯示給使用者。因此,對於之前的FruitsController中的queryAllFruits方法的返回值稍作修改,具體程式碼如下:

package com.ccff.controller;

import com.ccff.model.Fruits;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

//基於註解的Handler類
//使用@Controller來標識它是一個控制器
@Controller
@RequestMapping("/query")
public class FruitsController {

    private FruitsService fruitsService = new FruitsService();

    //@RequestMapping實現對方法和url進行對映,一個方法對應一個url
    //一般建議將url和方法寫成一樣的
    @RequestMapping("/queryAllFruits.action")
    public String queryAllFruits(Model model){
        //模擬service獲取水果商品列表
        List<Fruits> fruitsList = fruitsService.queryFruitsList();
        //將結果放到model中傳到顯示頁面中
        model.addAttribute("fruitsList",fruitsList);
        
        return "fruitsList";	/**這裡與之前的不同**/
    }   
}

class FruitsService{
    public List
            
           

相關推薦

Spring MVC使用—— 檢視解析

文章目錄 1、檢視解析器簡介 2、演示案例環境搭建 3、AbstractCa chingViewResolver 4、UrlBasedViewResolver 5、InternalResourceViewResolver 6、XmlVi

Spring Boot——Spring回顧——Spring MVC基礎高階配置

檔案上傳配置 上傳頁面 新增轉向到upload頁面的ViewController MultipartResolver配置 控制器 伺服器端推送技術 SSE 演示控制器 演示頁面 配置 Servlet 3.0+非同步方法處理

Spring MVC系列之session處理[email

介紹        在web開發中,session的重要性不言而喻,與cookie相比,session更加安全,處於伺服器端,開發者經常把一些重要的資訊放在session,方便在多次請求中方便的獲取資訊,Spring MVC 對session的支援也依舊很強大很靈活 Sp

Spring MVC學習 處理資料模型

Spring MVC提供了以下幾種方式輸出模型資料: 1.使用ModelAndView輸出模型資料,程式碼如下: <a href="TestRequestMapping/TestModelAndView">TestModelAndView<

Spring MVC 系列——Spring MVC 與Ajax互動及重定向操作

 一、Spring MVC 與Ajax互動 一般情況下,Controller中方法返回值型別有兩種 1、String 直接跳轉到某View介面 2、Void 不需要進行頁面跳轉,直接訪問下一個方法

Linux小白入門vim編輯

vim [需要編輯的文字所在路徑] vim有三種工作模式 ① 一般模式(命令模式) ② 編輯模式 ③ 底行模式(擴充套件命令列模式) 使用vim開啟一個文字時,預設處於一般模式。該模式不能對文字直接進行文字編輯,但是可以使用一些快捷鍵,對檔案進行快捷操作。 如果需

Spring MVC-控制器Controller-參數方法名稱解析Parameter Method Name Resolver 示例轉載實踐

title rop port img lsp java類 轉載 mvc export 以下內容翻譯自:https://www.tutorialspoint.com/springmvc/springmvc_parametermethodnameresolver.htm 說明

Spring MVC使用—— 處理器對映和介面卡

文章目錄 1、重溫請求流程 2、Spring MVC預設的註解配置 2.1 在Spring 3.1之前 2.2 在Spring 3.1之後 3、配置註解的處理器對映器和介面卡方式 3.1 第一種配置方式

spring面試題:面向切面程式設計AOP+MVC

Spring面向切面程式設計(AOP) 1.  解釋AOP 面向切面的程式設計,或AOP, 是一種程式設計技術,允許程式模組化橫向切割關注點,或橫切典型的責任劃分,如日誌和事務管理。   2. Aspect 切面 AOP

自定義控制元件三部曲檢視——RecyclerView系列之一簡單使用

絕望的時候不要那麼絕望,高興的時候不要那麼高興,是你慢慢會學會的。 ——董卿 轉了一年多,又回來繼續做Android。果然還是看到程式碼最讓我興奮……但有些事,沒經歷過,總歸還是遺憾的。在VIVO的遊戲中心,有一個特別炫酷的功能: 這個功能就是使

微服務架構實戰Spring boot2.0 + Mybatis +Druid監控資料庫訪問效能

簡介 該專案主要利用Spring boot2.0 + Mybatis +Druid 實現監控資料庫訪問效能。 Druid是一個非常優秀的資料庫連線池。在功能、效能、擴充套件性方面,都超過其他資料庫連線池,包括DBCP、C3P0、BoneCP、Proxool、JBoss DataSour

Spring+SpringMVC+MyBatis+easyUI整合基礎程式碼簡化

前言當然,也可以直接匯入原始碼, 點選這裡下載程式碼。由於剛開始寫部落格,所以很多細節都想不到,原始碼也放到GitHub上去了,自己動動手應該也就可以了,無非是自己多注意一點,細心一點,編碼啊,jar包啊,有時候或者一個分號,或者一個單引號雙引號,這些都可能導致出錯的,一定要多動手,自己多實踐。簡化目的又看了

Spring+SpringMVC+MyBatis+easyUI整合優化單元測試例項

日常囉嗦 前一篇文章《Spring+SpringMVC+MyBatis+easyUI整合優化篇(三)程式碼測試》講了不為和不能兩個狀態,針對不為,只能自己調整心態了,而對於不能,本文會結合一些例項進行講解,應該可以使得你掌握單元測試的方法。篇幅所限,所以先寫三

Spring Boot 學習之快取和 NoSQL

該系列並非完全原創,官方文件、作者一、前言當系統的訪問量增大時,相應的資料庫的效能就逐漸下降。但是,大多數請求都是在重複的獲取相同的資料,如果使用快取,將結果資料放入其中可以很大程度上減輕資料庫的負擔,提升系統的響應速度。本篇將介紹 Spring Boot 中快取和 NoSQ

Spring Boot系列Spring Boot原始碼解析

一、自動裝配原理   之前博文已經講過,@SpringBootApplication繼承了@EnableAutoConfiguration,該註解匯入了AutoConfigurationImport Selector,這個類主要是掃描spring-boot-autoconfigure下面的META-INF\

MVC框架驅動類 - 工廠模式

同時 exist class ... string obj 所有 獲取對象 ret 將框架中大部分要創建的對象,都經由驅動類創建,獲取,判斷。這樣做有如下好處: 1 統一管理所有創建的類,包括創建前處理與創建後處理 2 單一創建,防止多次創建類 實例: <?php

linux操作系統基礎

空閑 僵屍進程 標準 為什麽 嘗試 mount命令 性能分析 包含 put 系統監控 1. 系統監視和進程控制工具—top和free1) 掌握top命令的功能:top命令是Linux下常用的性能分析工具,能夠實時顯示系統中各個進程的資源占用狀況,類似於Windows的

Spring Boot 入門微服務之 Config Server 統一配置中心

bootstra pan pat 默認 star default client efault localhost 一、目錄結構 二、pom文件 <!-- 配置服務依賴 --> <dependency> &l

Spring MVC-控制器Controller-多動作控制器Multi Action Controller示例轉載實踐

cli move tps tree ssa targe ima and patch 以下內容翻譯自:https://www.tutorialspoint.com/springmvc/springmvc_multiactioncontroller.htm 說明:示例基於Sp

Spring Boot學習

自動配置 pat xml配置 XML 入口 spa ges auto classpath @SpringBootApplication 每一個Spring Boot項目都有一個名為*Application的入口類,入口類中有個main方法,在main方法中使用: Sprin