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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

(十)Spring 与 MVC 框架整合

發布時間:2023/12/3 javascript 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 (十)Spring 与 MVC 框架整合 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Spring 整合 MVC

目錄

  • MVC 框架整合思想
  • 為什么要整合 MVC 框架
  • 搭建 Web 運行環境
  • Spring 整合 MVC 框架的核心思路
  • 1. 準備工廠
  • 2. 代碼整合
  • Spring 整合 Struts2

?

MVC 框架整合思想

為什么要整合 MVC 框架

  • MVC 框架提供了控制器(Controller)調用 Servlet
    DAO —> Service
  • 請求響應的處理
  • 接收請求參數?request.getParameter("")
  • 控制程序的運行流程
  • 視圖解析(JSP、JSON、Freemarker、Thymeleaf)
  • Spring 可以整合哪些 MVC 框架?

  • struts1
  • webwork
  • jsf
  • struts2
  • springMVC
  • 搭建 Web 運行環境

    <dependencies><dependency><groupId>org.springframework</groupId><artifactId>spring-web</artifactId><version>5.1.14.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId><version>5.1.14.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-beans</artifactId><version>5.1.14.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>5.2.6.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.1.4.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-aop</artifactId><version>5.1.14.RELEASE</version></dependency><dependency><groupId>org.aspectj</groupId><artifactId>aspectjrt</artifactId><version>1.8.8</version></dependency><dependency><groupId>org.aspectj</groupId><artifactId>aspectjweaver</artifactId><version>1.8.3</version></dependency><dependency><groupId>org.mybatis</groupId><artifactId>mybatis-spring</artifactId><version>2.0.4</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.1.12</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.43</version></dependency><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.5.4</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.11</version><scope>test</scope></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId><version>1.7.25</version></dependency><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.17</version></dependency><dependency><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><version>3.1.0</version><scope>provided</scope></dependency><dependency><groupId>javax.servlet</groupId><artifactId>jstl</artifactId><version>1.2</version></dependency><dependency><groupId>javax.servlet.jsp</groupId><artifactId>javax.servlet.jsp-api</artifactId><version>2.3.1</version><scope>provided</scope></dependency></dependencies>

    Spring 整合 MVC 框架的核心思路

    1. 準備工廠

    Web 開發過程中如何創建工廠?

    ApplicationContext ctx = new WebXmlApplicationContext("/applicationContext.xml");

    如何保證工廠唯一,同時被共用?

    • 共用:工廠存儲在?ServletContext?這個作用域中,ServletContext.setAttribute("xxx", ctx);
    • 唯一:在?ServletContext?對象創建的同時創建工廠。
      ServletContextListener?在?ServletContext?對象創建的同時,被調用(只會被調用一次),
      把創建工廠的代碼寫在?ServletContextListener?中,也會保證只調用一次,保證了工廠的唯一性。

    Spring 封裝了一個?ContextLoaderListener,主要做了兩件事:

  • 創建工廠
  • 把工廠存在?ServletContext?中
  • ContextLoaderListener?使用方式:web.xml 中

    <listener><listener-class> org.springframework.web.context.ContextLoaderListener </listen-class> </listener><context-param><param-name> contextConfigLocation </param-name><param-value> classpath:applicationContext.xml </param-value> </context-param>

    2. 代碼整合

    Spring 整合 Struts2

    這個選學。。。因為現在 Struts2 用的不多了。。暫時不學了

    總結

    以上是生活随笔為你收集整理的(十)Spring 与 MVC 框架整合的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。