1.项目目录结构

2.项目中用的jar包

3.web.xml(其中主要配置spring与springmvc)

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app id="WebApp_ID">
<!-- spring配置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!-- springmvc配置 -->
<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:springMVC-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>

4.spring配置文件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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:mybatis-spring="http://mybatis.org/schema/mybatis-spring"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring-1.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"> <context:component-scan base-package="com.hxlz">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan> <context:property-placeholder location="classpath:jdbc.properties" /> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="user" value="${jdbc.user}"></property>
<property name="password" value="${jdbc.password}"></property>
<property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
<property name="driverClass" value="${jdbc.driverClass}"></property>
<property name="initialPoolSize" value="${jdbc.initPoolSize}"></property>
<property name="maxPoolSize" value="${jdbc.maxPoolSize}"></property>
</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="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 指定mybatis配置文件 -->
<property name="configLocation" value="classpath:mybatis-config.xml"></property>
</bean> <mybatis-spring:scan base-package="com.hxlz.mapper"/>
</beans>

5.springmvc配置文件springMVC-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: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.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"> <!-- 只扫描标了controller注解的控制器 -->
<context:component-scan base-package="com.hxlz" use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/"></property>
<property name="suffix" value=".jsp"></property>
</bean> <mvc:view-controller path="/" view-name="index"/> <mvc:annotation-driven></mvc:annotation-driven>
<mvc:default-servlet-handler/>
</beans>

6.mybatis配置文件mybatis-config.xml

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="mapUnderscoreToCamelCase" value="true" />
<setting name="lazyLoadingEnabled" value="true"/>
<setting name="aggressiveLazyLoading" value="false"/>
</settings> <typeAliases>
<typeAlias alias="Employee" type="com.hxlz.bean.Employee" />
</typeAliases> </configuration>

7.具体的业务逻辑的代码(https://github.com/MenghuiLiu/SSM/tree/master/mybatis-spring-springmvc)

内附上mybaits整合spring的官方给的demo(https://github.com/mybatis/jpetstore-6)

希望一起成长,交流,学习。

最新文章

  1. Solr 排除查询
  2. [转]java二维码生成与解析代码实现
  3. 【转】phpcms-v9中关于模型的理解
  4. 解读Unity中的CG编写Shader系列五(理论知识)
  5. 关于使用rem单位,calc()进行自适应布局
  6. HR免费选人的网站乐跳网上线
  7. Apache MINA 框架之Handler介绍
  8. uploadify ,前端页面获取值,json,ajax
  9. windows 杀进程软件
  10. CSS3-loading动画(五)
  11. python PIL图像处理
  12. MDS
  13. easyui dialog 中 panel-body 高度太小出现 滚动条 的原因
  14. Python+Selenium 自动化实现实例-处理分页(pagination)
  15. 网络基础&#160;http&#160;会话(session)详解
  16. ABP之展现层(Datatables分页)
  17. 阻止事件冒泡,阻止默认事件,event.stopPropagation()和event.preventDefault(),return false的区别
  18. FineUI 单击菜单页面内容完全刷新,关闭Tab
  19. 【PHP函数】json_decode() ---- 对 JSON 格式的字符串进行解码
  20. U3D 基础

热门文章

  1. JavaScript-DOM续
  2. git(一)
  3. 平衡二叉树 JAVA实现 亲测可用
  4. wince kill 进程
  5. Spark学习之路(七)—— 基于ZooKeeper搭建Spark高可用集群
  6. JavaScript学习笔记(2)
  7. Nginx添加Lua扩展模块
  8. vboxnetctl: no such file or directory
  9. 设计模式-桥接模式(Bridge)
  10. VS2008 专业版试用到期破解 【转】