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表示实际传送的字节数。