这个例子比较简单 实现的是spring mvc+jdbctemplate.下面有空会加入hibernate的实现。后续会加入quartz持久化的实现。lucene的简单用法等。

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 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">
<display-name>SSS</display-name>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>webapp.root</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
/WEB-INF/SSS-dao.xml
/WEB-INF/SSS-service.xml
</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
<listener>
<description>springContextListener</description>
<listener-class >org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<description>springContextListener</description>
<listener-class >org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<servlet>
<description>spring filter servlet</description>
<servlet-name>SSS</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/SSS-servlet.xml
/WEB-INF/SSS-controller.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- 在web应用关闭的时候,清除JavaBeans Introspector的监听器;
可以保证在web 应用关闭的时候释放与掉这个web 应用相关的class loader
和由它管理的类 -->
<listener>
<listener-class>
org.springframework.web.util.IntrospectorCleanupListener
</listener-class>
</listener>
<servlet-mapping>
<servlet-name>SSS</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

下面是webxml中提到的所有配置文件xml都是在WEB-INF文件夹下

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:tx="http://www.springframework.org/schema/tx"  xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<!--  <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value=""/>
<property name="url" value=""/>
<property name="username" value=""/>
<property name="password" value=""/>
</bean>
-->
<context:property-placeholder location="classpath:*.properties" />
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${c3p0.driverClass}"/>
<property name="jdbcUrl" value="${c3p0.jdbcUrl}"/>
<property name="user" value="${c3p0.user}"/>
<property name="password" value="${c3p0.password}"/>
<property name="minPoolSize" value="${c3p0.maxPoolSize}"/>
<property name="initialPoolSize" value="${c3p0.initialPoolSize}"/>
<property name="maxPoolSize" value="${c3p0.maxPoolSize}"/>
<property name="maxIdleTime" value="${c3p0.maxIdleTime}"/>
<property name="acquireIncrement" value="${c3p0.acquireIncrement}"/>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" >
<property name="dataSource" ref="dataSource"/>
<property name="fetchSize" value="30"/>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"  />
<!-- <bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
<property name="converters">
<list>
<bean class="com.sss.util.binder.DateFormatConvert"></bean>
</list>
</property>
</bean>
<bean id="webBindingInitializer" class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
<property name="conversionService" ref="conversionService"></property>
</bean>-->
</beans>

SSS-controller.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:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans  
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd 
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
    ">
    <bean id="methodNameResolver" class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver ">
     <property name="paramName" value="method"></property>   
    </bean>
   <bean name="/test/testController.do" class="com.sss.controller.TestController">
     <property name="methodNameResolver">
         <ref bean="methodNameResolver"/>
     </property>   
     <property name="dao" ref="testDao"/>
   </bean>
   <bean name="/jsp/userInfoController.do" class="com.sss.controller.UserInfoController">
       <property name="methodNameResolver">
           <ref bean="methodNameResolver"/>
       </property>
       <property name="userInfoService" ref="userInfoService"></property>
   </bean>
   
</beans>

SSS-dao.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:tx="http://www.springframework.org/schema/tx"  xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans  
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd 
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-2.5.xsd  
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
    http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
   <bean id="testDao" class="com.sss.dao.TestDAO" scope="prototype">
       <property name="jdbcTemplate" ref="jdbcTemplate"/>
   </bean>
   <bean id="userInfoDao" class="com.sss.dao.impl.UserInfoDAOImpl" scope="prototype">
       <property name="jdbcTemplate" ref="jdbcTemplate"/>
   </bean>
  
</beans>

SSS-service.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:tx="http://www.springframework.org/schema/tx"  xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans  
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd 
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-2.5.xsd  
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
    http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
   <bean id="userInfoService" class="com.sss.service.impl.UserInfoServiceImpl">
       <property name="userInfoDao" ref="userInfoDao"></property>
   </bean>
  
</beans>

SSS-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:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans  
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd 
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
    ">
    <bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value=""></property>
        <property name="suffix" value=""></property>
    </bean>
    <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping">
        <property name="interceptors">
            <list>
    <bean class="com.sss.intorceptor.MyIntorceptor"></bean>               
            </list>
        </property>
    </bean>
   
 <!--spring mvc 3 支持convert接口的强类型转换,但是2.x不支持,只支持PropertyEditor的实现
 <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
        <property name="webBindingInitializer" ref="webBindingInitializer"></property>
    </bean> -->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
  <!--设置上传文件的最大尺寸为10MB-->
    <property name="maxUploadSize">
      <value>10485760</value>
    </property>
   </bean>
   
</beans>

代码直接见附件源码下载地址

年终总结spring mvc 代码篇结合之前写的相关推荐

  1. Spring MVC使用篇(八)—— 处理器(Handler)方法的返回值

    文章目录 1.演示项目环境搭建 1.1 演示项目工程结构 1.2 演示项目依赖的基础jar包 1.3 配置web.xml 1.4 配置Spring MVC核心配置文件 2.返回ModelAndView ...

  2. Spring MVC代码实例系列-06:Spring MVC配置Hibernate-Validator以及自定义校验注解

    超级通道 :Spring MVC代码实例系列-绪论 本章主要记录,如何在Spring MVC中添加Hibernate-Validator以及自定义校验注解.本章主要涉及的技术点有: javax.val ...

  3. 2012年终总结----spring mvc

    今年在工作中使用到了spring的mvc,工作的单位从spring1.x开始就使用了其mvc.项目的组合方式都是围绕spring进行的,如spring mvc+hibernate.或者是直接使用spr ...

  4. Spring MVC分析篇——HandleMapping

      Sping MVC是一个web开发框架,用于处理Http请求,那首先要做的第一件事情就是要为每个url找到对应的java类及方法.至于寻找的方式就有很多了,简单的做法,可以用一个Map保存所有ur ...

  5. 迷你版Spring MVC 实现

    2019独角兽企业重金招聘Python工程师标准>>> 迷你版Spring MVC 实现 本文参考自 写出我的第一个框架:迷你版Spring MVC ,写这篇文章用于个人学习的记录. ...

  6. 《Spring揭秘》读书笔记 3:Spring MVC

    22 迈向Spring MVC的旅程 [参考]Java Web开发历程. 1) Servlet独行天下的时代. 一个Servlet对应处理一个Web请求.Servlet什么都做. 2) 繁盛一时的JS ...

  7. Java之Spring mvc详解(非原创)

    文章大纲 一.Spring mvc介绍 二.Spring mvc代码实战 三.项目源码下载 四.参考文章 一.Spring mvc介绍 1. 什么是springmvc   springmvc是spri ...

  8. jsp ajax三级联动,Spring MVC+JSP实现三级联动

    initProvinces(); });/** * 获取省列表*/function initProvinces() { $('#province').empty(); $.ajax({ type :& ...

  9. Spring MVC测试框架入门–第1部分

    最新推出的主要Spring框架是Spring MVC测试框架,Spring Guys声称它是"一流的JUnit支持,可通过流畅的API测试客户端和服务器端Spring MVC代码" ...

最新文章

  1. linux检查正则表达式,正则表达式及Linux文本检查工具
  2. CCNet 的 Build 流程
  3. moveTaskToback退后台
  4. Android 开发工程师面试指南
  5. virtualbox+vagrant学习-2(command cli)-27-vagrant connect命令
  6. 匿名管道和pipe函数
  7. android+后台+拍照,Android相机无法从后台服务拍照
  8. Advance Installer安装问题
  9. 点云数据常用处理:python实现
  10. 层次分析法(附实例)
  11. 含重根的三阶实对称矩阵的快速对角化方法
  12. 微信支付——委托代扣介绍
  13. css类命名_标题CSS:CSS类命名的简单方法
  14. 浏览器被360劫持解决办法
  15. VS2005错误 error PRJ0003 生成 cmd.exe 时出错
  16. Galaxy Tab3 10.1如何开启被隐藏的开发者选项?
  17. 京东回应大面积裁员传闻:系造谣 已报案
  18. redhat开机自动连接网络设置
  19. 王者荣耀怎么删除在服务器上建立的账号,王者荣耀账号怎么注销 王者荣耀账号注销方法...
  20. 阅读真题 | 真题阅读 做题记录 二

热门文章

  1. 互联网自媒体平台大全,你知道多少?
  2. vue使用postcss-pxtorem px转rem
  3. python实现编辑距离算法
  4. 新型 tomcat websocket 内存马检测与防护思路探究
  5. 警惕这些房屋千万不可买!买了一切都完了!
  6. 网络扫盲——NAT(网络地址转换)
  7. C语言实验10_文件
  8. 【洛谷】P1003 铺地毯
  9. jQuery实习图片的上传保存处理
  10. Java写点餐系统(数组篇)