mybatis集成配置,框架搭建
分类:关于美高梅

springmvc+mybatis集成配置,springmvc+mybatis

简简单单之美,springmvc,mybatis就是四个很好的回顾集成方案,可以满足日常的类别须求。闲暇时光把品种配置文件分享出来,供大家参看:

 

1.率先大家来看下依赖的pom:

图片 1 1 <!-- spring --> 2 <dependency> 3 <groupId>org.springframework</groupId> 4 <artifactId>spring-core</artifactId> 5 <version>${spring.version}</version> 6 </dependency> 7 8 <dependency> 9 <groupId>org.springframework</groupId> 10 <artifactId>spring-beans</artifactId> 11 <version>${spring.version}</version> 12 </dependency> 13 14 <dependency> 15 <groupId>org.springframework</groupId> 16 <artifactId>spring-context</artifactId> 17 <version>${spring.version}</version> 18 </dependency> 19 20 <dependency> 21 <groupId>org.springframework</groupId> 22 <artifactId>spring-tx</artifactId> 23 <version>${spring.version}</version> 24 </dependency> 25 26 <dependency> 27 <groupId>org.springframework</groupId> 28 <artifactId>spring-web</artifactId> 29 <version>${spring.version}</version> 30 </dependency> 31 32 <dependency> 33 <groupId>org.springframework</groupId> 34 <artifactId>spring-webmvc</artifactId> 35 <version>${spring.version}</version> 36 </dependency> 37 38 <dependency> 39 <groupId>org.springframework</groupId> 40 <artifactId>spring-jdbc</artifactId> 41 <version>${spring.version}</version> 42 </dependency> 43 44 <dependency> 45 <groupId>org.springframework</groupId> 46 <artifactId>spring-test</artifactId> 47 <version>${spring.version}</version> 48 <scope>test</scope> 49 </dependency> 50 51 <!-- mybatis 包 --> 52 <dependency> 53 <groupId>org.mybatis</groupId> 54 <artifactId>mybatis</artifactId> 55 <version>3.2.8</version> 56 </dependency> 57 58 <!--mybatis spring 插件 --> 59 <dependency> 60 <groupId>org.mybatis</groupId> 61 <artifactId>mybatis-spring</artifactId> 62 <version>1.2.2</version> 63 </dependency> 64 65 <!-- mysql连接 --> 66 <dependency> 67 <groupId>mysql</groupId> 68 <artifactId>mysql-connector-java</artifactId> 69 <version>5.1.34</version> 70 </dependency> 71 72 <!-- 数据源 --> 73 <dependency> 74 <groupId>com.alibaba</groupId> 75 <artifactId>druid</artifactId> 76 <version>1.0.12</version> 77 </dependency> 78 79 <dependency> 80 <groupId>org.aspectj</groupId> 81 <artifactId>aspectjweaver</artifactId> 82 <version>1.8.4</version> 83 </dependency> 84 85 <!-- log4j --> 86 <dependency> 87 <groupId>log4j</groupId> 88 <artifactId>log4j</artifactId> 89 <version>1.2.17</version> 90 </dependency> 91 92 <!-- servlet --> 93 <dependency> 94 <groupId>javax.servlet</groupId> 95 <artifactId>servlet-api</artifactId> 96 <version>3.0-alpha-1</version> 97 </dependency> 98 99 <dependency> 100 <groupId>javax.servlet</groupId> 101 <artifactId>jstl</artifactId> 102 <version>1.2</version> 103 </dependency> 104 105 <!-- json --> 106 <dependency> 107 <groupId>org.codehaus.jackson</groupId> 108 <artifactId>jackson-mapper-asl</artifactId> 109 <version>1.9.13</version> 110 </dependency> 111 112 <dependency> 113 <groupId>com.alibaba</groupId> 114 <artifactId>fastjson</artifactId> 115 <version>1.2.3</version> 116 </dependency> 117 118 <dependency> 119 <groupId>com.fasterxml.jackson.core</groupId> 120 <artifactId>jackson-annotations</artifactId> 121 <version>${jackson.version}</version> 122 </dependency> 123 124 <dependency> 125 <groupId>com.fasterxml.jackson.core</groupId> 126 <artifactId>jackson-core</artifactId> 127 <version>${jackson.version}</version> 128 </dependency> 129 130 <dependency> 131 <groupId>com.fasterxml.jackson.core</groupId> 132 <artifactId>jackson-databind</artifactId> 133 <version>${jackson.version}</version> 134 </dependency> 135 <!-- 文件上传 --> 136 <dependency> 137 <groupId>commons-io</groupId> 138 <artifactId>commons-io</artifactId> 139 <version>2.4</version> 140 </dependency> 141 142 <dependency> 143 <groupId>commons-fileupload</groupId> 144 <artifactId>commons-fileupload</artifactId> 145 <version>1.2.2</version> 146 </dependency> View Code

spring 选拔的是4.1.4的版本,依据系统必要我们得以选用本人符合的版本。

2.有关的安插文件:

    a)spring.xml

图片 2 1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="" 3 xmlns:xsi="" xmlns:context="" 4 xsi:schemaLocation=" 5 6 7 ; 8 9 <!--引进配置属性文件 --> 10 <context:property-placeholder location="classpath:config.properties" /> 11 12 <!--自动扫描含有@Service将其注入为bean --> 13 <context:component-scan base-package="com.demo.report.web.service" /> View Code

    b)spring-mvc.xml

图片 3 1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="" 3 xmlns:mvc="" xmlns:xsi="" 4 xmlns:p="" xmlns:context="" 5 xsi:schemaLocation=" 6 7 8 9 10 ; 11 12 <!-- 自动扫描controller包下的全体类,假如@Controller注入为bean --> 13 <context:component-scan base-package="com.demo.report.web.controller" /> 14 15 <!-- 防止IE实行AJAX时,重回JSON现身下载文件 --> 16 <bean id="mapping杰克逊HttpMessageConverter" 17 class="org.springframework.http.converter.json.Mapping杰克逊2HttpMessageConverter"> 18 <property name="supportedMediaTypes"> 19 <list> 20 <value>text/html;charset=UTF-8</value> 21 </list> 22 </property> 23 </bean> 24 25 <!-- 运行Spring MVC的笺注成效,完结需要和注释POJO的照耀 --> 26 <bean 27 class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> 28 <property name="messageConverters"> 29 <list> 30 <!-- json转换器 --> 31 <ref bean="mappingJacksonHttpMessageConverter" /> 32 </list> 33 </property> 34 </bean> 35 36 <!-- 对模型视图名称的分析,即在模型视图名称增多前后缀 --> 37 <bean 38 class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 39 <property name="viewClass" 40 value="org.springframework.web.servlet.view.JstlView" /> 41 <property name="prefix" value="" /> 42 <property name="suffix" value="" /> 43 </bean> 44 45 <!-- 配置多文件上传 46 <bean id="multipartResolver" 47 class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> 48 <property name="defaultEncoding"> 49 <value>UTF-8</value> 50 </property> 51 <property name="maxUploadSize"> 52 <value>32505856</value> 53 </property> 54 <property name="maxInMemorySize"> 55 <value>4096</value> 56 </property> 57 </bean>--> 58 59 </beans> View Code

    c)spring-mybatis.xml

图片 4 1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="" 3 xmlns:xsi="" xmlns:tx="" 4 xmlns:aop="" 5 xsi:schemaLocation=" 6 7 8 9 10 11 12 "> 13 14 <!-- 配置数据源 使用的是Druid数据源 --> 15 <bean name="dataSource" class="com.alibaba.druid.pool.DruidDataSource" 16 init-method="init" destroy-method="close"> 17 <property name="url" value="${jdbc.url}" /> 18 <property name="username" value="${jdbc.username}" /> 19 <property name="password" value="${jdbc.password}" /> 20 21 <!-- 开始化连接大小 --> 22 <property name="initialSize" value="0" /> 23 <!-- 连接池最大应用连接数量 --> 24 <property name="maxActive" value="20" /> 25 26 <!-- 连接池最小空闲 --> 27 <property name="minIdle" value="0" /> 28 <!-- 获取连接最大等待时间 --> 29 <property name="maxWait" value="60000" /> 30 <property name="poolPreparedStatements" value="true" /> 31 <property name="maxPoolPreparedStatementPerConnectionSize" 32 value="33" /> 33 <!-- 用来质量评定有效sql --> 34 <property name="validationQuery" value="${validationQuery}" /> 35 <property name="testOnBorrow" value="false" /> 36 <property name="testOnReturn" value="false" /> 37 <property name="testWhileIdle" value="true" /> 38 <!-- 配置间距多长期才进行贰次检测,检查评定供给关闭的悠闲连接,单位是阿秒 --> 39 <property name="timeBetweenEvictionRunsMillis" value="60000" /> 40 <!-- 配置一个三番五次在池中幽微生存的光阴,单位是纳秒 --> 41 <property name="minEvictableIdleTimeMillis" value="25200100" /> 42 <!-- 打开removeAbandoned功能 --> 43 <property name="removeAbandoned" value="true" /> 44 <!-- 1800秒,也就是30分钟 --> 45 <property name="removeAbandonedTimeout" value="1800" /> 46 <!-- 关闭abanded连接时输出错误日志 --> 47 <property name="logAbandoned" value="true" /> 48 <!-- 监察和控制数据库 --> 49 <property name="filters" value="mergeStat" /> 50 </bean> 51 52 <!-- myBatis文件 --> 53 <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> 54 <property name="dataSource" ref="dataSource" /> 55 <!-- 自动扫描entity目录, 省掉Configuration.xml里的手工业配置 --> 56 <property name="mapperLocations" value="classpath:com/demo/report/web/mapper/*.xml" /> 57 </bean> 58 59 <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> 60 <property name="basePackage" value="com.feidai.report.web.mapper" /> 61 <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" /> 62 </bean> 63 64 <!-- 配置事务管理器 --> 65 <bean id="transactionManager" 66 class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 67 <property name="dataSource" ref="dataSource" /> 68 </bean> View Code

    d)web.xml

图片 5 1 <display-name>springmvc_mybatis_demo</display-name> 2 3 <context-param> 4 <param-name>contextConfigLocation</param-name> 5 <param-value>classpath:spring.xml,classpath:spring-mybatis.xml</param-value> 6 </context-param> 7 8 <filter> 9 <filter-name>encodingFilter</filter-name> 10 <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 11 <init-param> 12 <param-name>encoding</param-name> 13 <param-value>utf-8</param-value> 14 </init-param> 15 <init-param> 16 <param-name>forceEncoding</param-name> 17 <param-value>true</param-value> 18 </init-param> 19 </filter> 20 <filter-mapping> 21 <filter-name>encodingFilter</filter-name> 22 <url-pattern>/*</url-pattern> 23 </filter-mapping> 24 25 <listener> 26 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 27 </listener> 28 29 <!-- 幸免spring内部存款和储蓄器溢出监听器 --> 30 <listener> 31 <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class> 32 </listener> 33 34 <servlet> 35 <description>spring mvc servlet</description> 36 <servlet-name>rest</servlet-name> 37 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 38 <init-param> 39 <param-name>contextConfigLocation</param-name> 40 <param-value> 41 classpath:spring-mvc.xml 42 </param-value> 43 </init-param> 44 <load-on-startup>1</load-on-startup> 45 </servlet> 46 <servlet-mapping> 47 <servlet-name>rest</servlet-name> 48 <url-pattern>/</url-pattern> 49 </servlet-mapping> 50 51 <servlet> 52 <servlet-name>DruidStatView</servlet-name> 53 <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class> 54 </servlet> 55 <servlet-mapping> 56 <servlet-name>DruidStatView</servlet-name> 57 <url-pattern>/druid/*</url-pattern> 58 </servlet-mapping> 59 60 <!-- 配置session超时时间,单位分钟--> 61 <session-config> 62 <session-timeout>30</session-timeout> 63 </session-config> 64 65 <welcome-file-list> 66 <welcome-file>index.jsp</welcome-file> 67 </welcome-file-list> View Code

选用了druid的数据源,在web中的详细安插能够参见代码。

 

轻易之美,springmvc,mybatis便是三个很好的轻便集成方案,能够知足常常的种类必要。闲暇时光把项...

初藳链接: 

springmvc+mybatis整合,springmvcmybatis

maven 依赖

 

<!-- springmvc -->
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-webmvc</artifactId>
  <version>4.3.2.RELEASE</version>
</dependency>

<!-- mybatis -->
<dependency>
  <groupId>org.mybatis</groupId>
  <artifactId>mybatis-spring</artifactId>
  <version>1.3.0</version>
</dependency>
<dependency>
  <groupId>org.mybatis</groupId>
  <artifactId>mybatis</artifactId>
  <version>3.4.1</version>
</dependency>
<dependency>
  <groupId>org.aspectj</groupId>
  <artifactId>aspectjweaver</artifactId>
  <version>1.9.0.BETA-1</version>
</dependency>

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-context-support</artifactId>
  <version>4.3.0.RELEASE</version>
</dependency>

<!-- 数据库连接 -->
<dependency>
  <groupId>com.alibaba</groupId>
  <artifactId>druid</artifactId>
  <version>1.0.26</version>
</dependency>
<dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
  <version>5.1.25</version>
</dependency>

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-jdbc</artifactId>
  <version>4.2.5.RELEASE</version>
</dependency>

<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>javax.servlet-api</artifactId>
  <version>3.0.1</version>
  <scope>provided</scope>
</dependency>
<dependency>
  <groupId>javax.servlet.jsp</groupId>
  <artifactId>jsp-api</artifactId>
  <version>2.2</version>
</dependency>
<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>jstl</artifactId>
  <version>1.2</version>
</dependency>

<dependency>
  <groupId>commons-logging</groupId>
  <artifactId>commons-logging</artifactId>
  <version>1.2</version>
</dependency>
<dependency>
  <groupId>org.apache.commons</groupId>
  <artifactId>com.springsource.org.apache.commons.fileupload</artifactId>
  <version>1.2.1</version>
</dependency>

 

web.xml

 

<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:spring-mybatis.xml</param-value>
</context-param>

<listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
  <servlet-name>springmvc</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring-mvc.xml</param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
  <async-supported>true</async-supported>
</servlet>
<servlet-mapping>
  <servlet-name>springmvc</servlet-name>
  <url-pattern>/</url-pattern>
</servlet-mapping>

 

 

spring-mvc.xml

<beans xmlns=""
xmlns:xsi="" xmlns:p=""
xmlns:context=""
xmlns:mvc=""
xsi:schemaLocation="





;

<!-- 声明扫描的限定,四个用逗号隔绝 -->
<context:component-scan base-package="com.xxx">
<context:include-filter type="annotation"
expression="org.springframework.stereotype.Controller" />
<context:include-filter type="annotation"
expression="org.springframework.web.bind.annotation.ControllerAdvice" />
</context:component-scan>

<mvc:annotation-driven />
<!-- 当在web.xml 中 DispatcherServlet使用 <url-pattern>/</url-pattern> 映射时,能映照静态财富 -->
<mvc:default-servlet-handler />

<!-- 静态能源映射 -->
<mvc:resources mapping="/static/**" location="/static/" />

<!-- 私下认可的视图深入深入分析器 在上方的深入剖析错误时接纳 (暗中认可使用html)- -->
<bean id="defaultViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:order="1">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="contentType" value="text/html" />
<property name="prefix" value="" />
<property name="suffix" value=".jsp" />
</bean>

<!-- 调节器万分管理 -->
<bean id="exceptionHandlerExceptionResolver"
class="org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver">
</bean>

<!-- SpringMVC上传文件时,供给配置MultipartResolver处理器 -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8" />
</bean>
</beans>

 

spring-mybatis.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""
xmlns:xsi=""
xmlns:aop=""
xmlns:tx=""
xmlns:context=""
xsi:schemaLocation="



;

<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<!-- 基本天性 url、user、password -->
<property name="url" value="jdbc:mysql://127.0.0.1:3306/springtest" />
<property name="username" value="root" />
<property name="password" value="123456" />
</bean>

<!-- <bean id="log-filter" class="com.alibaba.druid.filter.logging.Slf4jLogFilter"> -->
<!-- <property name="statementExecutableSqlLogEnable" value="true"/> -->
<!-- </bean> -->

<!-- (事务管理) -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>

<!-- 成立SqlSessionFactory,同期钦命数量源 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<!-- <property name="configLocation" value="classpath:/mybatis.xml"/> -->
<property name="mapperLocations" >
<value>classpath:com/xxx/**/mapper/*.xml</value>
<!-- mapper.xml若果存在八个包下可正如配置 -->
<!-- <array> -->
<!-- <value></value> -->
<!-- <value></value> -->
<!-- </array> -->
</property>
</bean>

<!-- Mapper接口所在包名,Spring会自动搜索其下的Mapper 假诺包有多个,次类也可安排四个 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.xxx"/>
<property name="markerInterface" value="com.xxx.MybatisMapper"/>
</bean>

<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" propagation="SUPPORTS" read-only="true"/><!--当只供给调用一遍dao-->
<tx:method name="find*" propagation="SUPPORTS" read-only="true"/><!--当必要经过三个dao获取数据时-->
<tx:method name="list*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="*" propagation="REQUIRED" rollback-for="java.lang.Exception"/>
</tx:attributes>
</tx:advice>

<aop:config expose-proxy="true" proxy-target-class="true">
<!-- 只对工作逻辑层实行事务 有五个包可用 || 连接 -->
<aop:pointcut id="txPointcut" expression="execution(* com.xxx.*..service..*+.*(..))"/>
<aop:advisor id="txAdvisor" advice-ref="txAdvice" pointcut-ref="txPointcut"/>
</aop:config>

</beans>

 

maven 依赖 !-- springmvc -- dependency groupIdorg.springframework/groupId artifactIdspring-webmvc/artifactId version4.3.2.RELEASE/versi...

小结下怎么用那七个常用框架搭建一个Java Web工程,方便现在更迅捷的开垦工程。首先得用maven搭建三个多模块的web工程,这里不再赘述,请仿效早先的总括:用Maven命令行创制多模块Web项目

本篇小说重要内容是介绍如何使用AMDliJ IDEA创制spring+ SpringMVC + MyBatis项目,上边会提交项目搭建的详尽步骤甚至有关的布局文件。

率初阶入那些框架所需的maven正视:

 

<spring.version>3.2.2.RELEASE</spring.version>
<v.velocity>1.6.3</v.velocity>
<v.velocity.tool>1.2</v.velocity.tool>
<jdbc.driver.version>5.1.15</jdbc.driver.version>

=======================================前言

<!-- ibatis begin -->
<dependency>
    <groupId>org.apache.ibatis</groupId>
    <artifactId>ibatis-sqlmap</artifactId>
    <version>2.3.4.726</version>
</dependency>

基本概念: 仿效链接() 

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>${jdbc.driver.version}</version>
</dependency>
<!-- ibatis end -->

Spring 

        Spring是多个开源框架,Spring是于二〇〇〇 年兴起的一个轻量级的Java 开荒框架,由Rod 约翰逊 在其小说Expert One-On-One J2EE Development and Design中论述的生龙活虎对眼光和原型衍生而来。它是为了消除集团应用开拓的繁琐而创设的。Spring使用基本的JavaBean来形成从前只可能由EJB完毕的事体。可是,Spring的用处不唯有限于服务器端的成本。从简单性、可测试性和松耦合的角度来讲,任何Java应用都足以从Spring中受益。 轻便的话,Spring是多少个轻量级的支配反转(IoC)和面向切面(AOP)的容器框架。

 

<!-- spring begin -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-orm</artifactId>
    <version>${spring.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>${spring.version}</version>
</dependency>

SpringMVC

        Spring MVC属于SpringFrameWork的持续产品,已经融合在Spring Web Flow里面。Spring MVC 抽离了控制器、模型对象、分派器以致管理程序对象的剧中人物,这种分离让它们更易于开展定制。

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>${spring.version}</version>
</dependency>
<dependency>
    <artifactId>spring-context</artifactId>
    <groupId>org.springframework</groupId>
    <version>${spring.version}</version>
</dependency>

  MyBatis

       MyBatis 本是apache的二个开源项目iBatis, 二〇〇八年这些类型由apache software foundation 迁移到了google code,而且改名叫MyBatis 。MyBatis是四个基于Java的持久层框架。iBATIS提供的持久层框架饱含SQL Maps和Data Access Objects(DAO)MyBatis 肃清了差不离全数的JDBC代码和参数的手工业安装以致结果集的查找。MyBatis 使用轻松的 XML或阐明用于配置和原始映射,将接口和 Java 的POJOs(Plain Old Java Objects,普通的 Java对象)映射成数据库中的记录。

======================================前言完

 

 

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>${spring.version}</version>
</dependency>

1. 创建maven项目

 

1.1  File -> New Module,进入创造项目窗口。

图片 6

 

 

 

1.2  点击Next,填写GroupId、ArtifactId和Version

图片 7

 

 

 

1.3  接着下一步,这里要求注在Properties中增加三个参数 archetypeCatalog=internal,不加那一个参数,在maven生成骨架的时候将会非常的慢,一时候直接卡住。来自英特网的讲明:

archetypeCatalog代表插件使用的archetype元数据,不加这几个参数时默感到remote,local,即主题饭店archetype元数据,由于中心

仓库的archetype太多了于是产生比非常的慢,钦点internal来表示仅使用其五月数据。

 

 

 

 

 

图片 8

1.4  填写Module name

图片 9

1.5  生成maven的种类骨架之后,我们还索要手动在 src/main 下制造java目录。今后能够直接编写了,笔者把品种所急需的公文都编写制定成功未来,项指标工程结构如图。

图片 10

 

 

      到此停止,项目标框架基本搭建完毕,上边注重说一下品类的配备文件

 

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>${spring.version}</version>
</dependency>

2.  门类配置文件

 

 2.1   这里运用maven来引进项目所要求的jar包,所以也就无需手动来治本jar包了。

 

pom.xml

 

[html] view plain copy

 

  1. <project xmlns="" xmlns:xsi=""  
  2.   xsi:schemaLocation=" ;  
  3.   <modelVersion>4.0.0</modelVersion>  
  4.   <groupId>com.heitian.web</groupId>  
  5.   <artifactId>web-ssm</artifactId>  
  6.   <packaging>war</packaging>  
  7.   <version>1.0-SNAPSHOT</version>  
  8.   <name>web-ssm Maven Webapp</name>  
  9.   <url>;  
  10.   <properties>  
  11.     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
  12.     <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>  
  13.   
  14.     <!-- spring版本号 -->  
  15.     <spring.version>4.2.5.RELEASE</spring.version>  
  16.   
  17.     <!-- mybatis版本号 -->  
  18.     <mybatis.version>3.2.8</mybatis.version>  
  19.   
  20.     <!-- mysql驱动版本号 -->  
  21.     <mysql-driver.version>5.1.29</mysql-driver.version>  
  22.   
  23.     <!-- log4j日志包版本号 -->  
  24.     <slf4j.version>1.7.18</slf4j.version>  
  25.     <log4j.version>1.2.17</log4j.version>  
  26.   
  27.   </properties>  
  28.   
  29.   
  30.   <dependencies>  
  31.     <!-- 添加jstl依赖 -->  
  32.     <dependency>  
  33.       <groupId>jstl</groupId>  
  34.       <artifactId>jstl</artifactId>  
  35.       <version>1.2</version>  
  36.     </dependency>  
  37.   
  38.     <dependency>  
  39.       <groupId>javax</groupId>  
  40.       <artifactId>javaee-api</artifactId>  
  41.       <version>7.0</version>  
  42.     </dependency>  
  43.   
  44.     <!-- 添加junit4依赖 -->  
  45.     <dependency>  
  46.       <groupId>junit</groupId>  
  47.       <artifactId>junit</artifactId>  
  48.       <version>4.11</version>  
  49.       <!-- 钦定范围,在测验时才会加载 -->  
  50.       <scope>test</scope>  
  51.     </dependency>  
  52.   
  53.     <!-- 加多spring宗旨正视 -->  
  54.     <dependency>  
  55.       <groupId>org.springframework</groupId>  
  56.       <artifactId>spring-core</artifactId>  
  57.       <version>${spring.version}</version>  
  58.     </dependency>  
  59.     <dependency>  
  60.       <groupId>org.springframework</groupId>  
  61.       <artifactId>spring-web</artifactId>  
  62.       <version>${spring.version}</version>  
  63.     </dependency>  
  64.     <dependency>  
  65.       <groupId>org.springframework</groupId>  
  66.       <artifactId>spring-oxm</artifactId>  
  67.       <version>${spring.version}</version>  
  68.     </dependency>  
  69.     <dependency>  
  70.       <groupId>org.springframework</groupId>  
  71.       <artifactId>spring-tx</artifactId>  
  72.       <version>${spring.version}</version>  
  73.     </dependency>  
  74.     <dependency>  
  75.       <groupId>org.springframework</groupId>  
  76.       <artifactId>spring-jdbc</artifactId>  
  77.       <version>${spring.version}</version>  
  78.     </dependency>  
  79.     <dependency>  
  80.       <groupId>org.springframework</groupId>  
  81.       <artifactId>spring-webmvc</artifactId>  
  82.       <version>${spring.version}</version>  
  83.     </dependency>  
  84.     <dependency>  
  85.       <groupId>org.springframework</groupId>  
  86.       <artifactId>spring-context</artifactId>  
  87.       <version>${spring.version}</version>  
  88.     </dependency>  
  89.     <dependency>  
  90.       <groupId>org.springframework</groupId>  
  91.       <artifactId>spring-context-support</artifactId>  
  92.       <version>${spring.version}</version>  
  93.     </dependency>  
  94.     <dependency>  
  95.       <groupId>org.springframework</groupId>  
  96.       <artifactId>spring-aop</artifactId>  
  97.       <version>${spring.version}</version>  
  98.     </dependency>  
  99.   
  100.     <dependency>  
  101.       <groupId>org.springframework</groupId>  
  102.       <artifactId>spring-test</artifactId>  
  103.       <version>${spring.version}</version>  
  104.     </dependency>  
  105.   
  106.     <!-- 添加mybatis依赖 -->  
  107.     <dependency>  
  108.       <groupId>org.mybatis</groupId>  
  109.       <artifactId>mybatis</artifactId>  
  110.       <version>${mybatis.version}</version>  
  111.     </dependency>  
  112.   
  113.     <!-- 增多mybatis/spring整合包重视 -->  
  114.     <dependency>  
  115.       <groupId>org.mybatis</groupId>  
  116.       <artifactId>mybatis-spring</artifactId>  
  117.       <version>1.2.2</version>  
  118.     </dependency>  
  119.   
  120.     <!-- 增添mysql驱动注重 -->  
  121.     <dependency>  
  122.       <groupId>mysql</groupId>  
  123.       <artifactId>mysql-connector-java</artifactId>  
  124.       <version>${mysql-driver.version}</version>  
  125.     </dependency>  
  126.     <!-- 增添数据库连接池信赖 -->  
  127.     <dependency>  
  128.       <groupId>commons-dbcp</groupId>  
  129.       <artifactId>commons-dbcp</artifactId>  
  130.       <version>1.2.2</version>  
  131.     </dependency>  
  132.   
  133.     <!-- 添加fastjson -->  
  134.     <dependency>  
  135.       <groupId>com.alibaba</groupId>  
  136.       <artifactId>fastjson</artifactId>  
  137.       <version>1.1.41</version>  
  138.     </dependency>  
  139.   
  140.     <!-- 增加日记相关jar包 -->  
  141.     <dependency>  
  142.       <groupId>log4j</groupId>  
  143.       <artifactId>log4j</artifactId>  
  144.       <version>${log4j.version}</version>  
  145.     </dependency>  
  146.     <dependency>  
  147.       <groupId>org.slf4j</groupId>  
  148.       <artifactId>slf4j-api</artifactId>  
  149.       <version>${slf4j.version}</version>  
  150.     </dependency>  
  151.     <dependency>  
  152.       <groupId>org.slf4j</groupId>  
  153.       <artifactId>slf4j-log4j12</artifactId>  
  154.       <version>${slf4j.version}</version>  
  155.     </dependency>  
  156.   
  157.     <!-- log end -->  
  158.     <!-- 映入JSON -->  
  159.     <dependency>  
  160.       <groupId>org.codehaus.jackson</groupId>  
  161.       <artifactId>jackson-mapper-asl</artifactId>  
  162.       <version>1.9.13</version>  
  163.     </dependency>  
  164.     <!--  -->  
  165.     <dependency>  
  166.       <groupId>com.fasterxml.jackson.core</groupId>  
  167.       <artifactId>jackson-core</artifactId>  
  168.       <version>2.8.0</version>  
  169.     </dependency>  
  170.     <!--  -->  
  171.     <dependency>  
  172.       <groupId>com.fasterxml.jackson.core</groupId>  
  173.       <artifactId>jackson-databind</artifactId>  
  174.       <version>2.8.0</version>  
  175.     </dependency>  
  176.   
  177.     <dependency>  
  178.       <groupId>commons-fileupload</groupId>  
  179.       <artifactId>commons-fileupload</artifactId>  
  180.       <version>1.3.1</version>  
  181.     </dependency>  
  182.   
  183.     <dependency>  
  184.       <groupId>commons-io</groupId>  
  185.       <artifactId>commons-io</artifactId>  
  186.       <version>2.4</version>  
  187.     </dependency>  
  188.   
  189.     <dependency>  
  190.       <groupId>commons-codec</groupId>  
  191.       <artifactId>commons-codec</artifactId>  
  192.       <version>1.9</version>  
  193.     </dependency>  
  194.   </dependencies>  
  195.   
  196.   <build>  
  197.     <finalName>web-ssm</finalName>  
  198.   </build>  
  199. </project>  

 

2.2   新建jdbc.properties文件

 

jdbc.properties

 

[html] view plain copy

 

  1. driverClasss=com.mysql.jdbc.Driver  
  2. jdbcUrl=jdbc:mysql://localhost:3306/db_ssm?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull  
  3. username=root  
  4. password=root  
  5.   
  6. #概念初阶连接数  
  7. initialSize=0  
  8. #概念最洛桑接数  
  9. maxActive=20  
  10. #概念最大空闲  
  11. maxIdle=20  
  12. #概念最小空闲  
  13. minIdle=1  
  14. #概念最长等待时间  
  15. maxWait=60000  

 

2.3  新建log4j 配置文件

 

log4j.properties

 

[html] view plain copy

 

  1. log4j.rootLogger=INFO,Console,File  
  2.   
  3. #调整台日志  
  4. log4j.appender.Console=org.apache.log4j.ConsoleAppender  
  5. log4j.appender.Console.Target=System.out  
  6. log4j.appender.Console.layout=org.apache.log4j.PatternLayout  
  7. log4j.appender.Console.layout.ConversionPattern=[%p][%t][%d{yyyy-MM-dd HH:mm:ss}][%C] - %m%n  
  8.   
  9. #平日文书日志  
  10. log4j.appender.File=org.apache.log4j.RollingFileAppender  
  11. log4j.appender.File.File=logs/ssm.log  
  12. log4j.appender.File.MaxFileSize=10MB  
  13. #出口日志,要是换到DEBUG表示输出DEBUG以上等第日志  
  14. log4j.appender.File.Threshold=ALL  
  15. log4j.appender.File.layout=org.apache.log4j.PatternLayout  
  16. log4j.appender.File.layout.ConversionPattern=[%p][%t][%d{yyyy-MM-dd HH:mm:ss}][%C] - %m%n  

 

2.4  新建springmvc配置文件

 

 

spring-mvc.xml

 

 

[html] view plain copy

 

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns=""  
  3.        xmlns:xsi="" xmlns:p=""  
  4.        xmlns:context=""  
  5.        xmlns:mvc=""  
  6.        xsi:schemaLocation="  
  7.                           
  8.                           
  9.                           
  10.                           
  11.                         ;  
  12.   
  13.     <!-- 自动扫描  @Controller-->  
  14.     <context:component-scan base-package="com.heitian.ssm.controller"/>  
  15.   
  16.     <!--幸免IE试行AJAX时,再次回到JSON现身下载文件 -->  
  17.     <bean id="mappingJacksonHttpMessageConverter"  
  18.           class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">  
  19.         <property name="supportedMediaTypes">  
  20.             <list>  
  21.                 <value>text/html;charset=UTF-8</value>  
  22.             </list>  
  23.         </property>  
  24.     </bean>  
  25.     <!-- 运维SpringMVC的注释成效,完结伏乞和注释POJO的映照 -->  
  26.     <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">  
  27.         <property name="messageConverters">  
  28.             <list>  
  29.                 <ref bean="mappingJacksonHttpMessageConverter"/> <!-- JSON转换器 -->  
  30.             </list>  
  31.         </property>  
  32.     </bean>  
  33.   
  34.   
  35.     <!-- 定义跳转的文件的上下缀 ,视图情势配置 -->  
  36.     <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
  37.         <property name="prefix" value="/WEB-INF/jsp/" />  
  38.         <property name="suffix" value=".jsp"/>  
  39.     </bean>  
  40.   
  41.     <!-- 文件上传配置 -->  
  42.     <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">  
  43.         <!-- 私下认可编码 -->  
  44.         <property name="defaultEncoding" value="UTF-8"/>  
  45.         <!-- 上传文件大小限定为31M,31*1024*1024 -->  
  46.         <property name="maxUploadSize" value="32505856"/>  
  47.         <!-- 内部存款和储蓄器中的最大值 -->  
  48.         <property name="maxInMemorySize" value="4096"/>  
  49.     </bean>  
  50. </beans>  

 

2.5  新建spring和mybatis整合所需的布局文件

 

 

spring-mybatis.xml 

 

[html] view plain copy

 

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns=""  
  3.        xmlns:xsi=""  
  4.        xmlns:context="" xmlns:tx=""  
  5.        xsi:schemaLocation="  
  6.                           
  7.                           
  8.                           
  9.                           
  10.                         ;  
  11.   
  12.     <!-- 自动扫描 -->  
  13.     <context:component-scan base-package="com.heitian.ssm"/>  
  14.   
  15.     <!-- 第豆蔻梢头种艺术:加载五个properties文件 -->  
  16.     <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
  17.         <property name="location" value="classpath:jdbc.properties"/>  
  18.     </bean>  
  19.   
  20.   
  21.     <!-- 次之种艺术:加载多少个properties文件  
  22.     <bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">  
  23.         <property name="locations">  
  24.             <list>  
  25.                 <value>classpath:jdbc.properties</value>  
  26.                 <value>classpath:common.properties</value>  
  27.             </list>  
  28.         </property>  
  29.         <property name="fileEncoding" value="UTF-8"/>  
  30.     </bean>  
  31.     <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">  
  32.         <property name="properties" ref="configProperties"/>  
  33.     </bean>  
  34.     -->  
  35.   
  36.     <!-- 配置数据源 -->  
  37.     <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"  
  38.           destroy-method="close">  
  39.         <property name="driverClassName" value="${driverClasss}"/>  
  40.         <property name="url" value="${jdbcUrl}"/>  
  41.         <property name="username" value="${username}"/>  
  42.         <property name="password" value="${password}"/>  
  43.         <!-- 开头化连接大小 -->  
  44.         <property name="initialSize" value="${initialSize}"></property>  
  45.         <!-- 连接池最大数目 -->  
  46.         <property name="maxActive" value="${maxActive}"></property>  
  47.         <!-- 连接池最大空闲 -->  
  48.         <property name="maxIdle" value="${maxIdle}"></property>  
  49.         <!-- 连接池最小空闲 -->  
  50.         <property name="minIdle" value="${minIdle}"></property>  
  51.         <!-- 获取连接最大等待时间 -->  
  52.         <property name="maxWait" value="${maxWait}"></property>  
  53.     </bean>  
  54.   
  55.     <!-- mybatis和spring完美结合,无需mybatis的配备映射文件 -->  
  56.     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
  57.         <property name="dataSource" ref="dataSource"/>  
  58.         <!-- 自动扫描mapping.xml文件 -->  
  59.         <property name="mapperLocations" value="classpath:mapping/*.xml"></property>  
  60.     </bean>  
  61.   
  62.     <!-- DAO接口所在包名,Spring会自动寻觅其下的类 -->  
  63.     <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">  
  64.         <property name="basePackage" value="com.heitian.ssm.dao"/>  
  65.         <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>  
  66.     </bean>  
  67.   
  68.   
  69.     <!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->  
  70.     <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
  71.         <property name="dataSource" ref="dataSource"/>  
  72.     </bean>  
  73.   
  74.     <!-- (事务管理)transaction manager, use JtaTransactionManager for global tx -->  
  75.     <tx:annotation-driven transaction-manager="transactionManager"/>  
  76. </beans>  

 

2.6  web.xml配置文件

 

web.xml

 

[html] view plain copy

 

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <web-app xmlns=""  
  3.          xmlns:xsi=""  
  4.          xsi:schemaLocation="  
  5.           "  
  6.          version="3.0">  
  7.   
  8.     <display-name>web-ssm</display-name>  
  9.       
  10.     <context-param>  
  11.         <param-name>contextConfigLocation</param-name>  
  12.         <param-value>classpath:spring-mybatis.xml</param-value>  
  13.     </context-param>  
  14.   
  15.     <context-param>  
  16.         <param-name>log4jConfigLocation</param-name>  
  17.         <param-value>classpath:log4j.properties</param-value>  
  18.     </context-param>  
  19.   
  20.     <!-- 编码过滤器 -->  
  21.     <filter>  
  22.         <filter-name>encodingFilter</filter-name>  
  23.         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>  
  24.         <init-param>  
  25.             <param-name>encoding</param-name>  
  26.             <param-value>UTF-8</param-value>  
  27.         </init-param>  
  28.     </filter>  
  29.     <filter-mapping>  
  30.         <filter-name>encodingFilter</filter-name>  
  31.         <url-pattern>/*</url-pattern>  
  32.     </filter-mapping>  
  33.   
  34.     <!-- spring监听器 -->  
  35.     <listener>  
  36.         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
  37.     </listener>  
  38.   
  39.     <!-- 幸免spring内部存款和储蓄器溢出监听器,举个例子quartz -->  
  40.     <listener>  
  41.         <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>  
  42.     </listener>  
  43.   
  44.   
  45.     <!-- spring mvc servlet-->  
  46.     <servlet>  
  47.         <servlet-name>SpringMVC</servlet-name>  
  48.         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
  49.         <init-param>  
  50.             <param-name>contextConfigLocation</param-name>  
  51.             <param-value>classpath:spring-mvc.xml</param-value>  
  52.         </init-param>  
  53.         <load-on-startup>1</load-on-startup>  
  54.         <async-supported>true</async-supported>  
  55.     </servlet>  
  56.     <servlet-mapping>  
  57.         <servlet-name>SpringMVC</servlet-name>  
  58.         <!-- 此处也足以配备成 *.do 形式 -->  
  59.         <url-pattern>/</url-pattern>  
  60.     </servlet-mapping>  
  61.   
  62.     <welcome-file-list>  
  63.         <welcome-file>/index.jsp</welcome-file>  
  64.     </welcome-file-list>  
  65.   
  66.     <!-- session配置 -->  
  67.     <session-config>  
  68.         <session-timeout>15</session-timeout>  
  69.     </session-config>  
  70.   
  71. </web-app>  

 

 

 

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
    <version>${spring.version}</version>
</dependency>

3.  类别配置和配备

 

3.1   File -> Project Structure,走入创制项目配置窗口。

图片 11

 

 

 

3.2  创制一个汤姆cat容器实例,并把项目配置进去

图片 12

    

 

3.3  项目所需配备好项目访谈的根路线,然后运营汤姆cat。

图片 13

 

 

3.4  在浏览器地址栏中输入:

图片 14

 

3.5  项目所需观察图中呈现效果,则象征项目搭建设成功。

 

 

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>${spring.version}</version>
</dependency>
<!-- spring end -->

4.  值得注意的地点

 

搭建好项指标框架之后,运行汤姆cat,如若访谈 现身如下错误:

图片 15

并发这么些颠倒是非是因为少了依靠的jar包,只要在pom文件中增多如下信赖就能够。

[html] view plain copy

 

  1. <!--  -->  
  2.     <dependency>  
  3.       <groupId>com.fasterxml.jackson.core</groupId>  
  4.       <artifactId>jackson-core</artifactId>  
  5.       <version>2.8.0</version>  
  6.     </dependency>  
  7.     <!--  -->  
  8.     <dependency>  
  9.       <groupId>com.fasterxml.jackson.core</groupId>  
  10.       <artifactId>jackson-databind</artifactId>  
  11.       <version>2.8.0</version>  
  12.     </dependency>  

    5. 档期的顺序下载地址

 

  项目下载的地点为:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
</dependency>

<dependency>
    <groupId>javax.servlet.jsp</groupId>
    <artifactId>jsp-api</artifactId>
    <version>2.1</version>
    <scope>provided</scope>
</dependency>

<!-- velocity begin -->
<dependency>
    <groupId>org.apache.velocity</groupId>
    <artifactId>velocity</artifactId>
    <version>${v.velocity}</version>
</dependency>
<dependency>
    <groupId>velocity-tools</groupId>
    <artifactId>velocity-tools</artifactId>
    <version>${v.velocity.tool}</version>
</dependency>
<!-- velocity end -->

    web.xml里配置spring和spring mvc 入口

 <servlet>
  <servlet-name>appServlet</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <init-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>classpath:spring-config.xml</param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
 </servlet>

 <servlet-mapping>
  <servlet-name>appServlet</servlet-name>
  <url-pattern>/</url-pattern>
 </servlet-mapping>
    DispatcherServlet是spring mvc的具备诉求入口的servlet。contextConfigLocation参数配置spring的总布置文件地方。倘诺是spring集成struts的话,还必要独自安顿spring的监听器,可是生机勃勃旦是集成spring mvc,则无需下边这段配置了:

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

    spring事务安顿文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""
      xmlns:xsi=""
      xmlns:context=""
      xmlns:aop=""
      xmlns:mvc=""
      xsi:schemaLocation="
   
   
   
   
   
   
      default-autowire="byName">

    <context:component-scan base-package="com.jd.im.**"/>

    <mvc:annotation-driven/>

    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:im-king.properties</value>
                <value>classpath:important.properties</value>
                <value>classpath:jss_config.properties</value>
            </list>
        </property>
    </bean>

    <import resource="spring/spring-config-mvc.xml"></import>
    <import resource="spring/spring-config-datasource.xml"/>
</beans>
    总布局文件里集成了spring mvc配置文件和ibatis数据源的铺排文件。

    spring mvc 配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="" xmlns:xsi="" xmlns:context=""
 xmlns:mvc=""
 xsi:schemaLocation="
     
     
     
     
         ;

 <context:component-scan base-package="com.**.dd.mall.web.controller" />
 <mvc:annotation-driven />
 
 <bean id="dateObjectMapper" class="com.**.dd.mall.web.util.DateObjectMapper"></bean>
 <!-- Json重回 乱码管理 -->
 <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
  <property name="messageConverters">
   <list>
    <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
     <property name="objectMapper" ref="dateObjectMapper"></property>
    </bean>
    <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />
    <bean class="org.springframework.http.converter.StringHttpMessageConverter">
     <property name="supportedMediaTypes">
      <list>
       <value>text/plain;charset=UTF-8</value>
      </list>
     </property>
    </bean>
    <bean class="org.springframework.http.converter.ResourceHttpMessageConverter" />
    <bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter" />
    <bean class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter" />
    <bean class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter" />
   </list>
  </property>
 </bean>

 <mvc:resources mapping="/dist/**" location="/dist/" cache-period="3600" />
 <mvc:resources mapping="/js/**" location="/js/" cache-period="3600" />
 <mvc:resources mapping="/css/**" location="/css/" cache-period="3600" />
 <!--<mvc:resources mapping="/fonts/**" location="/fonts/" cache-period="3600" /> -->
 <mvc:resources mapping="/config.json" location="/" cache-period="3600" />
 <mvc:resources mapping="/image/**" location="/image/" cache-period="3600" />

 <!-- 对转会页面的路线拆解深入分析。prefix:前缀, suffix:后缀 -->
 <bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver">
  <property name="cache" value="true"></property>
  <property name="suffix" value=".vm"></property>
  <property name="prefix" value=""></property>
  <property name="contentType" value="text/html;charset=utf-8"></property>
  <property name="exposeRequestAttributes" value="true"></property>
  <property name="viewClass" value="org.springframework.web.servlet.view.velocity.VelocityLayoutView"></property>
 </bean>

 <bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
  <property name="resourceLoaderPath" value="/WEB-INF/vm/"></property>
  <property name="configLocation" value="classpath:velocity.properties"></property>
 </bean>

 <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
  <property name="maxUploadSize" value="10485760" />
  <property name="defaultEncoding" value="utf-8"></property>
 </bean>

 <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
  <!-- 设置为true以忽视对Accept Header的援救 -->
  <property name="order" value="1" />
  <property name="contentNegotiationManager">
   <bean class="org.springframework.web.accept.ContentNegotiationManager">
    <constructor-arg>
     <bean class="org.springframework.web.accept.PathExtensionContentNegotiationStrategy">
      <constructor-arg>
       <map>
        <entry key="json" value="application/json" />
        <entry key="xml" value="application/xml" />
       </map>
      </constructor-arg>
     </bean>
    </constructor-arg>
   </bean>
  </property>
  <property name="ignoreAcceptHeader" value="true" />
  <!-- 在未曾扩展名时即: "/user/getUser" 时的暗中同意表现情势 -->
  <property name="defaultContentType" value="text/html" />

  <!-- 用于开启 /user/getUser?format=json 的支撑 -->
  <property name="favorParameter" value="true" />
  <property name="defaultViews">
   <list>
    <!-- for application/json -->
    <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
    </bean>
   </list>
  </property>
 </bean>
 
</beans>
    viewResolver和velocityConfig节点钦赐了spring mv再次回到页面用velocity。

    Ibatis配置
    带读写抽离的数据源配置
<?xml version="1.0" encoding="GBK"?>
<beans xmlns=""
      xmlns:xsi="" xmlns:tx=""
      xsi:schemaLocation="
     
       
  "
      default-autowire="byName">

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="${chat.jdbc.driver}"/>
        <property name="url" value="${chat.jdbc.url}"/>
        <property name="username" value="${chat.jdbc.username}"/>
        <property name="password" value="${chat.jdbc.password}"/>
        <property name="maxActive" value="${chat.jdbc.maxActive}"/>
        <!-- sql 心跳 -->
        <property name="testWhileIdle" value="true"/>
        <property name="testOnBorrow" value="false"/>
        <property name="testOnReturn" value="false"/>
        <property name="validationQuery" value="select 1"/>
        <property name="validationQueryTimeout" value="1"/>
        <property name="timeBetweenEvictionRunsMillis" value="60000"/>
        <property name="numTestsPerEvictionRun" value="${chat.jdbc.maxActive}"/>
    </bean>

    <bean id="selectedDataSource" name="selectedDataSource"
          class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="${select.chat.jdbc.driver}"/>
        <property name="url" value="${select.chat.jdbc.url}"/>
        <property name="username" value="${select.chat.jdbc.username}"/>
        <property name="password" value="${select.chat.jdbc.password}"/>
        <property name="maxActive" value="${select.chat.jdbc.maxActive}"/>
        <!-- sql 心跳 -->
        <property name="testWhileIdle" value="true"/>
        <property name="testOnBorrow" value="false"/>
        <property name="testOnReturn" value="false"/>
        <property name="validationQuery" value="select 1"/>
        <property name="validationQueryTimeout" value="1"/>
        <property name="timeBetweenEvictionRunsMillis" value="60000"/>
        <property name="numTestsPerEvictionRun" value="${select.chat.jdbc.maxActive}"/>
    </bean>

    <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
        <property name="configLocations">
            <list>
                <value>classpath:sqlmap-config.xml</value>
            </list>
        </property>
        <property name="dataSource" ref="dataSource"/>
    </bean>

    <bean id="sqlMapClientRead" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
        <property name="configLocations">
            <list>
                <value>classpath:sqlmap-config.xml</value>
            </list>
        </property>
        <property name="dataSource" ref="selectedDataSource"/>
    </bean>

    <bean id="selectDao" class="com.jd.im.king.template.dao.impl.SelectDaoImpl">
        <property name="sqlMapClient" ref="sqlMapClientRead"/>
    </bean>

    <bean id="writeDao" class="com.jd.im.king.template.dao.impl.WriteDaoImpl">
        <property name="sqlMapClient" ref="sqlMapClient"/>
    </bean>

    <bean id="transactionManager"
          class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>

    <tx:annotation-driven transaction-manager="transactionManager"/>

</beans>

    Ibatis的查询信任SqlMapClientFactoryBean那一个指标的布局。那几个目的同一时间钦命了ibatis的总陈设文件和数据源。少年老成共配了五个,一个顶住校读书,叁个顶住写。

    Ibatis总布局文件

<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE sqlMapConfig  PUBLIC "-//iBATIS.com//DTD SQL Map
Config 2.0/" ";

<sqlMapConfig>
    <settings
            cacheModelsEnabled="true"
            enhancementEnabled="true"
            lazyLoadingEnabled="false"
            errorTracingEnabled="true"
            maxRequests="32"
            maxSessions="10"
            maxTransactions="5"
            useStatementNamespaces="true"/>

    <sqlMap resource="sqlmap/word.xml"/>
   
</sqlMapConfig>

    sqlMap节点担负导入分配置文件,也正是sql文件。能够有多少个。

    ibatis的sql分配置文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" ";
<sqlMap namespace="word">
 
 <typeAlias alias="Word" type="com.**.im.RiskKeyWord"/>
 
    <insert id="add" parameterClass="Word">
        INSERT
        INTO key_word(lib_id, word)
        VALUES (#lib_id#, #word:VARCHAR#)
        <selectKey resultClass="int" keyProperty="id">
            select last_insert_id() limit 1
        </selectKey>
    </insert>
 
 <update id="update" parameterClass="Word">
  UPDATE key_word
  SET lib_id = #lib_id#, word = #word:VARCHAR#
  WHERE id = #id#
 </update>
 
 <select id="query" parameterClass="int" resultClass="Word">
  SELECT id, lib_id, word
  FROM key_word
  WHERE  id = #id#
 </select>
 
 <delete id="del" parameterClass="int" >
  DELETE
  FROM key_word
  WHERE  id = #id#
 </delete>
</sqlMap>

    ibatis的分配置文件里都以sql语句。

    至此,这五个框架的搭建完结。

SpringMVC总结篇  http://www.linuxidc.com/Linux/2016-06/132659.htm

Spring+SpringMVC集团飞快支付架构搭建  http://www.linuxidc.com/Linux/2015-09/122942.htm

SpringMVC的乱码管理  http://www.linuxidc.com/Linux/2015-07/120542.htm

Spring MVC+Spring3+Hibernate4开拓条件搭建 http://www.linuxidc.com/Linux/2013-07/87119.htm 

Spring MVC整合Freemarker基于注脚方式 http://www.linuxidc.com/Linux/2013-02/79660.htm 

据说评释的Spring MVC简介 http://www.linuxidc.com/Linux/2012-02/54896.htm

SpringMVC详细示例实战教程 http://www.linuxidc.com/Linux/2015-06/118461.htm

Spring MVC 框架搭建及精解 http://www.linuxidc.com/Linux/2012-01/52740.htm

SpringMVC 至极管理  http://www.linuxidc.com/Linux/2015-06/119049.htm

本文永恒更新链接地址:http://www.linuxidc.com/Linux/2016-10/135846.htm

图片 16

本文由美高梅网址发布于关于美高梅,转载请注明出处:mybatis集成配置,框架搭建

上一篇:没有了 下一篇:没有了
猜你喜欢
热门排行
精彩图文