pom.xml 配置:
詳解: https://www.cnblogs.com/Nick-Hu/p/7288198.html
/**modelVersion:pom文件的模型版本
**關於group id和artifact id,爲了便於多人多模塊協同開發管理(以後會講),建議使用以下命名規範
**group id:com.公司名.項目名
**artifact id:功能模塊名
**packaging:項目打包的後綴,war是web項目發佈用的,默認爲jar
**version: artifact模塊的版本,說白了就是你的項目版本號
**group id + artifact id +version :項目在倉庫中的座標
**<!--項目描述名-->
**<name></name>
**<!--項目地址-->
**<url></url>
**/
<!-- 指定當前pom的版本 -->
<modelVersion>4.0.0</modelVersion>
<!-- 一、項目的座標信息-->
<groupId>反寫的公司網址+項目名</groupId>
<artifactId>項目名+模塊名</artifactId>
<!--
第一個o:大版本:號
第二個0:分支版本號
第三個0:小版本號
版本類型劃分:1.SNAPSHOT(快照)
2.alpha(內測)
3.beta(公測)
4.Release(穩定)
5.GA(正式)
-->
<version>0.0.1SNAPSHOT</version>
<!--maven項目打包方式:默認:jar,可指定war、zip、pom--->
<packaging></packaging>
<!--項目描述名-->
<name></name>
<!--項目地址-->
<url></url>
<!--項目描述-->
<description></description>
<!--開發人員信息-->
<developers></developers>
<!--許可證信息-->
<licenses></licenses>
<!--組織信息-->
<organization></organization>
/**dependency:引入資源jar包到本地倉庫,要引入更多資源就在<dependencies>中繼續增加<dependency>
**group id+artifact id+version:資源jar包在倉庫中的座標
**scope:作用範圍。
**/
<!--二、依賴列表-->
<dependencies>
<!--依賴座標-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<type></type>
<!-- 依賴範圍:test-->
<scope>test</scope>
<!--設置依賴是否可選:true/false默認是後者-->
<optional>false</optional>
<!--排除依賴傳遞列表-->
<exclusions>
<!--排除部分不需要的依賴-->
<exclusion></exclusion>
</exclusions>
</dependency>
</dependencies>
/**build:項目構建時的配置
**finalName:在瀏覽器中的訪問路徑,如果將它改成helloworld,再執行maven--update,
**這時運行項目的訪問路徑是http://localhost:8080/helloworld/
**而不是項目名的 http://localhost:8080/test
**plugins:插件
**group id+artifact id+version:插件在倉庫中的座標
**/
<build>
<finalName>mmall</finalName>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>
<!-- geelynote maven的核心插件之-complier插件默認只支持編譯Java 1.4,因此需要加上支持高版本jre的配置,在pom.xml裏面加上 增加編譯插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
<compilerArguments>
<extdirs>${project.basedir}/src/main/webapp/WEB-INF/lib</extdirs>
</compilerArguments>
</configuration>
</plugin>
</plugins>
</build>
web.xml配置詳解:
//xml的版本和編碼格式
<?xml version="1.0" encoding="UTF-8"?>
/**
* This is the XML Schema for the Servlet 2.5 deployment descriptor.
* The deployment descriptor must be named "WEB-INF/web.xml" in the
* web application's war file. All Servlet deployment descriptors
* must indicate the web application schema by using the Java EE
* namespace:
*
* http://java.sun.com/xml/ns/javaee
*
* and by indicating the version of the schema by
* using the version element as shown below:
* <web-app xmlns="http://java.sun.com/xml/ns/javaee"
* xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
* xsi:schemaLocation="..."
* version="2.5">
...
* </web-app>
* The instance documents may indicate the published version of
* the schema using the xsi:schemaLocation attribute for Java EE
* namespace with the following location:
**/
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<!-- icon元素用來表示Web應用的一個和兩個圖像文件的位置。 -->
<icon></icon>
<!-- display-name元素用來標記這個特定的Web應用的一個名稱。 -->
<display-name></display-name>
<!-- description元素給出與此有關的說明性文本。 -->
<description></description>
<!-- context-param元素聲明應用範圍內的初始化參數 -->
<context-param></context-param>
/**
* Servlet中的過濾器Filter是實現了javax.servlet.Filter接口的服務器端程序,
* 主要的用途是過濾字符編碼、做一些業務邏輯判斷等。
* 其工作原理是,只要你在web.xml文件配置好要攔截的客戶端請求,它都會幫你攔截到請求,
* 此時你就可以對請求或響應(Request、Response)統一設置編碼,簡化操作;
* 它是隨你的web應用啓動而啓動的,只初始化一次,
* 以後就可以攔截相關請求,只有當你的web應用停止或重新部署的時候才銷燬.
* Filter對用戶請求進行預處理,接着將請求交給Servlet進行處理並生成響應,最後Filter再對服務器響應進行後處理
**/
<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>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- listener 對事件監聽程序的支持,事件監聽程序在建立、修改和刪除會話或servlet環境時得到通知。Listener元素指出事件監聽程序類。 -->
<listener></listener>
<!--https://www.cnblogs.com/huangjianping/p/7499060.html -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext.xml
</param-value>
</context-param>
<!-- https://www.cnblogs.com/wql025/p/4804977.html -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
applicationContext.xml配置詳解:
/**
*表示啓動spring的組件掃描功能(從spring2.5版本開始)。
*即掃描base-package包或者子包下面的Java文件,
*如果掃描到有@controller、@Service、@Repository、@Component等註解的java類,
*就會將這些bean註冊到工廠中。還可以使用分號來分隔多個掃描包。
**/
/**如果在配置文件中配置了<context:component-scan />,
*就不用在配置<context:annotation-config/>,
*因爲前者已經包含了後者。
*<context:annotation-config/>的作用是向spring容器注入AutowiredAnnotationBeanPostProcessor、
*CommonAnnotationBeanPostProcessor、PersistenceAnnotationBeanPostProcessor
*及RequiredAnnotationBeanPostProcessor 四個beanPostProcessor。從而使得@Autowired等註解生效。
**/
<context:component-scan base-package=""/>
Spring除了支持Schema方式配置AOP,還支持註解方式:使用@AspectJ風格的切面聲明。
啓用對@AspectJ的支持:Spring默認不支持@AspectJ風格的切面聲明,爲了支持需要使用如下配置:
配置代碼如下:
<aop:aspectj-autoproxy/>
<!--設置需要加載的屬性文件-->
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="order" value="2"/>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="locations">
<list>
<value>classpath:datasource.properties</value>
</list>
</property>
<property name="fileEncoding" value="utf-8"/>
</bean>
<!-- 數據庫配置-->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${db.driverClassName}"/>
<property name="url" value="${db.url}"/>
<property name="username" value="${db.username}"/>
<property name="password" value="${db.password}"/>
<!-- 連接池啓動時的初始值 -->
<property name="initialSize" value="${db.initialSize}"/>
<!-- 連接池的最大值 -->
<property name="maxActive" value="${db.maxActive}"/>
<!-- 最大空閒值.當經過一個高峯時間後,連接池可以慢慢將已經用不到的連接慢慢釋放一部分,一直減少到maxIdle爲止 -->
<property name="maxIdle" value="${db.maxIdle}"/>
<!-- 最小空閒值.當空閒的連接數少於閥值時,連接池就會預申請去一些連接,以免洪峯來時來不及申請 -->
<property name="minIdle" value="${db.minIdle}"/>
<!-- 最大建立連接等待時間。如果超過此時間將接到異常。設爲-1表示無限制 -->
<property name="maxWait" value="${db.maxWait}"/>
<!--#給出一條簡單的sql語句進行驗證 -->
<!--<property name="validationQuery" value="select getdate()" />-->
<property name="defaultAutoCommit" value="${db.defaultAutoCommit}"/>
<!-- 回收被遺棄的(一般是忘了釋放的)數據庫連接到連接池中 -->
<!--<property name="removeAbandoned" value="true" />-->
<!-- 數據庫連接過多長時間不用將被視爲被遺棄而收回連接池中 -->
<!--<property name="removeAbandonedTimeout" value="120" />-->
<!-- #連接的超時時間,默認爲半小時。 -->
<property name="minEvictableIdleTimeMillis" value="${db.minEvictableIdleTimeMillis}"/>
<!--# 失效檢查線程運行時間間隔,要小於MySQL默認-->
<property name="timeBetweenEvictionRunsMillis" value="40000"/>
<!--# 檢查連接是否有效-->
<property name="testWhileIdle" value="true"/>
<!--# 檢查連接有效性的SQL語句-->
<property name="validationQuery" value="SELECT 1 FROM dual"/>
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mapperLocations" value="classpath*:mappers/*Mapper.xml"></property>
<!-- 分頁插件 -->
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageHelper">
<property name="properties">
<value>
dialect=mysql
</value>
</property>
</bean>
</array>
</property>
</bean>
<!-- 配置mapper接口 -->
<bean name="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.mmall.dao"/>
</bean>
<!-- 使用@Transactional進行聲明式事務管理需要聲明下面這行 -->
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />
<!-- 事務管理 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
<property name="rollbackOnCommitFailure" value="true"/>
</bean>
Mybatis-Generator配置詳解:
<!--Mybatis-Generator的配置-->
<generatorConfiguration>
<!--導入屬性配置-->
<properties resource="datasource.properties"></properties>
<!--指定特定數據庫的jdbc驅動jar包的位置-->
<classPathEntry location="${db.driverLocation}"/>
<context id="default" targetRuntime="MyBatis3">
<!-- optional,旨在創建class時,對註釋進行控制 -->
<commentGenerator>
<property name="suppressDate" value="true"/>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!--jdbc的數據庫連接 -->
<jdbcConnection
driverClass="${db.driverClassName}"
connectionURL="${db.url}"
userId="${db.username}"
password="${db.password}">
</jdbcConnection>
<!-- 非必需,類型處理器,在數據庫類型和java類型之間的轉換控制-->
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!-- Model模型生成器,用來生成含有主鍵key的類,記錄類 以及查詢Example類
targetPackage 指定生成的model生成所在的包名
targetProject 指定在該項目下所在的路徑
-->
<!--<javaModelGenerator targetPackage="com.mmall.pojo" targetProject=".\src\main\java">-->
<javaModelGenerator targetPackage="com.mmall.pojo" targetProject="./src/main/java">
<!-- 是否允許子包,即targetPackage.schemaName.tableName -->
<property name="enableSubPackages" value="false"/>
<!-- 是否對model添加 構造函數 -->
<property name="constructorBased" value="true"/>
<!-- 是否對類CHAR類型的列的數據進行trim操作 -->
<property name="trimStrings" value="true"/>
<!-- 建立的Model對象是否 不可改變 即生成的Model對象不會有 setter方法,只有構造方法 -->
<property name="immutable" value="false"/>
</javaModelGenerator>
<!--mapper映射文件生成所在的目錄 爲每一個數據庫的表生成對應的SqlMap文件 -->
<!--<sqlMapGenerator targetPackage="mappers" targetProject=".\src\main\resources">-->
<sqlMapGenerator targetPackage="mappers" targetProject="./src/main/resources">
<property name="enableSubPackages" value="false"/>
</sqlMapGenerator>
<!-- 客戶端代碼,生成易於使用的針對Model對象和XML配置文件 的代碼
type="ANNOTATEDMAPPER",生成Java Model 和基於註解的Mapper對象
type="MIXEDMAPPER",生成基於註解的Java Model 和相應的Mapper對象
type="XMLMAPPER",生成SQLMap XML文件和獨立的Mapper接口
-->
<!-- targetPackage:mapper接口dao生成的位置 -->
<!--<javaClientGenerator type="XMLMAPPER" targetPackage="com.mmall.dao" targetProject=".\src\main\java">-->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.mmall.dao" targetProject="./src/main/java">
<!-- enableSubPackages:是否讓schema作爲包的後綴 -->
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<!--①屬性
schema即爲數據庫名,tableName爲對應的數據庫表,domainObjectName是要生成的實體類。
若要生成例子可將enableCountByExample等設爲true, 就會生成一個對應domainObjectName的Example類,false則不生成,默認策略是true。
類似的還有enableUpdateByExample、enableDeleteByExample、enableSelectByExample、selectByExampleQueryId屬性。
②子標籤
若要對某些數據庫字段進行操作,可以在table標籤中加入如下標籤
1、忽略某個字段
<ignoreColumn column="name" />
2、無論數據庫字段是何類型,生成的類屬性都是varchar
<columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" /-->
<table tableName="mmall_shipping" domainObjectName="Shipping" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="mmall_cart" domainObjectName="Cart" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="mmall_cart_item" domainObjectName="CartItem" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="mmall_category" domainObjectName="Category" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="mmall_order" domainObjectName="Order" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="mmall_order_item" domainObjectName="OrderItem" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="mmall_pay_info" domainObjectName="PayInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="mmall_product" domainObjectName="Product" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
<columnOverride column="detail" jdbcType="VARCHAR" />
<columnOverride column="sub_images" jdbcType="VARCHAR" />
</table>
<table tableName="mmall_user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<!-- geelynote mybatis插件的搭建 -->
</context>
</generatorConfiguration>
超文本傳輸協議講解:
HTTP報文由從客戶機到服務器的請求和從服務器到客戶機的響應構成。請求報文格式如下:
請求行 - 通用信息頭 - 請求頭 - 實體頭 - 報文主體
應答報文格式如下:
狀態行 - 通用信息頭 - 響應頭 - 實體頭 - 報文主體
通常HTTP消息包括客戶機向服務器的請求消息和服務器向客戶機的響應消息。這兩種類型的消息由一個起始行,一個或者多個頭域,
一個指示頭域結束的空行和可選的消息體組成。HTTP的頭域包括通用頭域,請求頭域,響應頭域和實體頭域四個部分。
一.通用頭域
1.Cache-Control指定請求和響應遵循的緩存機制。
2.Keep-Alive功能使客戶端到服務器端的連接持續有效,當出現對服務器的後繼請求時,Keep-Alive功能避免了建立或者重新建立連接。
KeepAliveTime 值控制 TCP/IP 嘗試驗證空閒連接是否完好的頻率。如果這段時間內沒有活動,則會發送保持活動信號。如果網絡工作正常,而且接收方是活動的,它就會響應。
3.Date頭域表示消息發送的時間,時間的描述格式由rfc822定義。例如,Date:Mon,31Dec200104:25:57GMT。
4.Pragma頭域用來包含實現特定的指令,最常用的是Pragma:no-cache。在HTTP/1.1協議中,它的含義和Cache-Control:no-cache相同。
二。請求頭域
MethodSPRequest-URISPHTTP-VersionCRLFMethod表示對於Request-URI完成的方法,這個字段是大小寫敏感的,
包括OPTIONS、GET、HEAD、POST、PUT、DELETE、TRACE。方法GET和HEAD應該被所有的通用WEB服務器支持,
其他所有方法的實現是可選的。GET方法取回由Request-URI標識的信息。
HEAD方法也是取回由Request-URI標識的信息,只是可以在響應時,不返回消息體。
POST方法可以請求服務器接收包含在請求中的實體信息(實體頭),可以用於提交表單,向新聞組、BBS、郵件羣組和數據庫發送消息。
SP表示空格。Request-URI遵循URI格式,在此字段爲星號(*)時,
說明請求並不用於某個特定的資源地址,而是用於服務器本身。HTTP-Version表示支持的HTTP版本,例如爲HTTP/1.1。
三。響應頭域
HTTP-VersionSPStatus-CodeSPReason-PhraseCRLF
HTTP-Version表示支持的HTTP版本,例如爲HTTP/1.1。Status-Code是一個三個數字的結果代碼。Reason-Phrase給Status-Code提供一個簡單的文本描述。Status-Code主要用於機器自動識別,Reason-Phrase主要用於幫助用戶理解。Status-Code的第一個數字定義響應的類別,後兩個數字沒有分類的作用。第一個數字可能取5個不同的值:
1xx:信息響應類,表示接收到請求並且繼續處理
2xx:處理成功響應類,表示動作被成功接收、理解和接受
3xx:重定向響應類,爲了完成指定的動作,必須接受進一步處理
4xx:客戶端錯誤,客戶請求包含語法錯誤或者是不能正確執行
5xx:服務端錯誤,服務器不能正確執行一個正確的請求
響應頭域允許服務器傳遞不能放在狀態行的附加信息,這些域主要描述服務器的信息和Request-URI進一步的信息
四。實體頭域
請求消息和響應消息都可以包含實體信息,實體信息一般由實體頭域和實體組成。實體頭域包含關於實體的原信息,
實體頭包括Allow、Content-Base、Content-Encoding、Content-Language、Content-Length、Content-Location、Content-MD5、
Content-Range、Content-Type、Etag、Expires、Last-Modified、extension-header。extension-header允許客戶端定義新的實體頭,
但是這些域可能無法被接受方識別。實體可以是一個經過編碼的字節流,它的編碼方式由Content-Encoding或Content-Type定義,
它的長度由Content-Length或Content-Range定義。
1.Content-Type實體頭
Content-Type實體頭用於向接收方指示實體的介質類型,指定HEAD方法送到接收方的實體介質類型,或GET方法發送的請求介質類型
2.Content-Range實體頭
Content-Range實體頭用於指定整個實體中的一部分的插入位置,他也指示了整個實體的長度。
在服務器向客戶返回一個部分響應,它必須描述響應覆蓋的範圍和整個實體長度。一般格式:
Content-Range:bytes-unitSPfirst-byte-pos-last-byte-pos/entity-legth
例如,傳送頭500個字節次字段的形式:Content-Range:bytes0-499/1234如果一個http消息包含此節(例如,對範圍請求的響應或對一系列範圍的重疊請求),
Content-Range表示傳送的範圍,Content-Length表示實際傳送的字節數。
3.Last-modified實體頭
Last-modified實體頭指定服務器上保存內容的最後修訂時間。
例如,傳送頭500個字節次字段的形式:Content-Range:bytes0-499/1234如果一個http消息包含此節(例如,對範圍請求的響應或對一系列範圍的重疊請求),
Content-Range表示傳送的範圍,Content-Length表示實際傳送的字節數。