1. 所需要Jar包.

//Spring3.0.1包

org.springframework.web-3.0.1 系列

//公共包

slf4j-api-1.5.6.jar slf4j-log4j12-1.5.6.jar log4j-1.2.13.jar

commons-logging-1.1.1.jar asm-3.1.jar cglib-2.2.jar

//mybatis与Spring的整合所需的包

mybatis-3.0.5.jar

aopalliance-1.0.jar

mybatis-spring-1.0.1.jar

mybatis-generator-core-1.3.1.jar(mybatis代码生成器包)

//jdbc driven

mysql-connector-java-3.1.6-bin.jar

//JSR验证-Hibernate validate 4.1

hibernate-validator-4.1.0.Final.jar

validation-api-1.0.0.GA.jar

//Spring Json 支持包

jackson-all-1.8.1.jar



2. web.xml配置

Servlet配置

org.springframework.web.servlet.DispatcherServlet

init-param配置servlet初始化文件.

以及servlet-mapping配置.

应用路径配置

webAppRootKey

Log4j配置

Log4jConfigLocation

Log4jRefreshInterval

Spring上下文配置

contextConfigLocation

Spring字符集过滤器配置

org.springframework.web.filter.CharacterEncodingFilter

Spring监听器配置

org.springframework.web.context.ContextLoaderListener

log4j监听器配置

org.springframework.web.util.Log4jConfigListener



3. spring mvc - servlet.xml配置

启动mvc注解驱动

<mvc:annotation-driven/>

组件scanner主要是自动去注入指定包里的对象

<context:component-scan

base-package="com.los.mvc.controller"/>

ViewResolver & View 映射关系

InternalResourceViewResolver 基于resource对jsp/jstl的支持

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<property name="prefix" value="/WEB-INF/views/"/>

<property name="suffix" value=".jsp"/>

<!-- InternalResourceViewResolver viewClass默认值就是JstlView -->

<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>

</bean>

自定义拦截器配置

<mvc:interceptors>

<mvc:interceptor>

<mvc:mapping path="/json*"/>

<bean class="com.los.mvc.interceptor.MyInterceptor"></bean>

</mvc:interceptor>

</mvc:interceptors>

国际化配置

<bean ,groups = GroupB.class)

如果@NotEmpty验证失败了,就不会继续验证@Size

相关文章: