沒有什麼比一個時代的沒落更令人傷感的了
整個社會和人都在追求創新、進步、成長,沒有人願意停步不前,一個個老事物慢慢從我們生活中消失掉真的令人那麼傷感麼。或者說被取代。我想有些是的,但有些東西其實並不是這樣。
遊天鳴和藍玉不正說明了兩種截然不同的人生麼。隨著社會的進步,那些消失的藝術或者說民間藝術可能現實中我們再也見不到了,這個社會永遠都是優勝劣汰,消失以為著不再需要,只不過這些老物件有更多的技藝和精神層面的東西罷了。
《百鳥朝鳳》這部電影我最近才在網路上看,看完後我久久不能動彈,它並沒有強烈的戲劇衝突,畫面也不夠細膩,人物刻畫並不突出,但它講明了嗩呐這個事兒,不腦殘,令人動容,這才是有思考的電影。 如果建立一個 Spring 項目
Spring MVC 架構在 Java 的 Web 項目中應該是無人不知的吧,你不會搭建一個 Spring 架構。作為身為一個剛剛學習Java的我都會,如果你不會的話,那可真令人憂傷。
1.在 MyEclipse 建立項目後,可以以選擇的方式去配置一個 Spring 項目,這裡不在討論。因為我只用 Eclipse。
2.手動搭建。就是動手。 建立一個 Java Web 項目
1.開啟 Eclipse ,在Project Explorer選項卡下面點擊右鍵,選擇Web - Dynamic Web Prodect(這一步應該都知道阿。。。)。
2.點擊Next。起一個你認為還不錯的項目名,注意:命名很重要,把每一次命名都當做給自己孩子起名字一樣莊嚴神聖。
3.沒有了,完成。
搞到 Spring 架構的 jar 包
無論你用坑蒙拐騙,還是死皮賴臉,只要你搞到 Spring 架構的 jar 包就行。我這裡給你個地址,你可以體面的去下載就行了。地址:http://projects.spring.io/spring-framework/
找到適合自己的版本,下載下來儲存到合適的位置就可以了,就這麼簡單。解壓後,應該是這樣的:
你看包的命名,你可能就大致明白了這個 jar 包是幹嘛的了,接下來就是引入你需要的了。
然後,你要你需要的 jar 包,複製到項目的/WebContent/WEB-INF/lib下,為什麼要這麼做,下面會說的。 匯入 jar 包
記得當年一個學 Java 的朋友抱怨說: Java 每天都在導包,不如 .Net 爽。我現在並不這麼認為。
在項目名上,點擊右鍵,Build Path - Configure Bulid Path... - Libraries - Add JARs...,在彈出的框裡邊找到項目的/WebContent/WEB-INF/lib,這樣就看到剛剛你複製過來的 jar 包了。
配置配置配置
搭建 Spring 架構最重要的步驟應該就是配置了。官網對架構的解釋說明如下:
Spring MVC 架構是圍繞一個 DispatcherServlet 來設計的,這個 Servlet 會把請求分發給各個處理器,並支援可配置的處理器映射、視圖渲染、本地化、時區與主題渲染等,甚至還能支援檔案上傳。處理器是你的應用中註解了 @Controller 和 @RequestMapping 的類和方法,Spring 為處理器方法提供了極其多樣靈活的配置。
所以,首先我們應該在/WebContent/WEB-INF/下建立web.xml檔案,接下來在這個檔案中配置 DispatcherServlet。
<servlet> <servlet-name>springMVC</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup></servlet><servlet-mapping> <servlet-name>springMVC</servlet-name> <url-pattern>/</url-pattern></servlet-mapping><context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value></context-param>
還可以配置字元編碼,預設啟動頁面什麼的,這裡不在配置,具體見樣本項目:https://github.com/mafly/SpringDemo/blob/master/WebContent/WEB-INF/web.xml,因為這裡是把 DispatcherServlet 命名為springMVC,並且讓它在 Web 項目一啟動就載入。接下來我們需要在/WebContent/WEB-INF/目錄下建立一個springMVC-servlet.xml的Spring設定檔。Spring官方文檔上推薦的預設的檔案名稱是[servlet-name]-servlet.xml檔案,這裡 servlet-name 叫 springMVC ,因此,我建立了一個springMVC-servlet.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:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xmlns:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd"><!-- 使用預設的註解映射 --><mvc:annotation-driven /><mvc:resources location="/" mapping="/index.html" /><!-- 自動掃描controller包中的控制器 --><context:component-scan base-package="cn.mayongfa.api.controller" /><context:component-scan base-package="cn.mayongfa.controller" /><!-- 上傳檔案攔截,設定最大上傳檔案大小 30M=30*1024*1024(B)=31457280 bytes --><bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="maxUploadSize" value="31457280" /></bean>
具體詳見:https://github.com/mafly/SpringDemo/blob/master/WebContent/WEB-INF/springMVC-servlet.xml
我們在web.xml檔案中定義的contextConfigLocation,指定要裝入的 Spring 設定檔,一般檔案都命名為applicationContext.xml,這個檔案中我們可以進行掃描類包、讀取設定檔、資料來源管理、AOP配置、緩衝以及訊息佇列等配置,所以,接下來就建立applicationContext.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:p="http://www.springframework.org/schema/p"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.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"><!-- 將多個設定檔讀取到容器中,交給Spring管理 --><bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:global.properties</value> <value>classpath:jdbc.properties</value> </list> </property></bean><!-- 掃描類包,將標註Spring註解的類自動轉化Bean,同時完成Bean的注入 --><context:component-scan base-package="cn.mayongfa.common" /><context:component-scan base-package="cn.mayongfa.service" /><context:component-scan base-package="cn.mayongfa.dao" /><!--master 配置資料來源 --><bean id="masterDataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"> <property name="driverClassName"> <value>${master.jdbc.driverClassName}</value> </property> <property name="url"> <value>${master.jdbc.url}</value> </property> <property name="username"> <value>${master.jdbc.username}</value> </property> <property name="password"> <value>${master.jdbc.password}</value> </property> ...</