ssm整合
一、引入所有的jar包
1. mysql数据库驱动jar
mysql-connector-java-5.1.46.jar
2. mybatis 的jar包
mybatis-3.2.2.jar
3. spring的核心jar。
commons-logging-1.1.3.jar
spring-beans-4.2.2.RELEASE.jar
spring-context-4.2.2.RELEASE.jar
spring-core-4.2.2.RELEASE.jar
spring-expression-4.2.2.RELEASE.jar
4. spring的注解。
spring-aop-4.2.2.RELEASE.jar
5. 事物处理。
spring-jdbc-4.2.2.RELEASE.jar
spring-tx-4.2.2.RELEASE.jar
com.springsource.org.aopalliance-1.0.0.jar
com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar
6. 数据源的jar包
c3p0-0.9.1.1.jar
7. springmvc的jar包。
spring-web-4.2.2.RELEASE.jar
spring-webmvc-4.2.2.RELEASE.jar
8. spring与mybatis整合的jar包
mybatis-spring-1.3.0.jar
二、配置文件
1.spring配置文件<?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:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd"> <!-- 包扫描 --> <context:component-scan base-package="com.zhiyou.cyf"/> <!-- 引入属性文件 --> <context:property-placeholder location="classpath:db.properties" /> <!-- 定义数据源 使用的是c3p0 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="user" value="${name}"></property> <property name="password" value="${password}"></property> <property name="driverClass" value="${driver}"></property> <property name="jdbcUrl" value="${url}"></property> </bean> <!-- 定义一个SessionFactory工厂类的bean,把mybatis配置文件放进来,这里不额外引用mybatis文件 --> <bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"></property> <!-- 为该包下的实体类起别名 --> <!-- <property name="typeAliasesPackage" value="com.zhiyou.cyf.bean"></property> --> <!-- 加载mybatis的映射文件 --> <property name="mapperLocations" value="classpath:com/zhiyou/cyf/mapper/*.xml"></property> <!-- 如果使用mybatis配置文件 --> <!-- <property name="configLocation" value=""></property> --> </bean> <!-- 配置mybatis接口的实现类userDao=session.getMapper(UserDao.class) --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 注意这里的属性是value -->
<property name="sqlSessionFactoryBeanName" value="sessionFactory"></property> <property name="basePackage" value="com.zhiyou.cyf.dao"></property> </bean> <!-- 事务管理 --> <bean id="tm" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property> </bean> <!-- 事务管理方式设置 --> <tx:advice id="advice" transaction-manager="tm"> <tx:attributes> <tx:method name="select*" read-only="true"/> <tx:method name="*"/> </tx:attributes> </tx:advice> <!-- 切面的配置 --> <aop:config> <aop:pointcut expression="execution(* com.zhiyou.cyf.service.*.*(..))" id="pointcut"/> <aop:advisor advice-ref="advice" pointcut-ref="pointcut"/> </aop:config> </beans>
2.springmvc配置文件
<?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.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd"> <!-- 开启包扫描 --> <context:component-scan base-package="com.zhiyou.cyf.controller"/> <!-- 开启注解 --> <mvc:annotation-driven/> <!-- 释放静态资源 --> <mvc:default-servlet-handler/> <!-- 视图解析器 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/view/user/"/> <property name="suffix" value=".jsp"/> </bean> </beans>
3.web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> <display-name>ssm</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <filter> <filter-name>encoding</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> </filter> <filter-mapping> <filter-name>encoding</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- The front controller of this Spring Web application, responsible for handling all application requests --> <servlet> <servlet-name>springDispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <!-- 配置springmvc文件的路径 --> <param-value>classpath:springmvc-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <!-- Map all requests to the DispatcherServlet for handling --> <servlet-mapping> <servlet-name>springDispatcherServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!-- needed for ContextLoaderListener --> <context-param> <param-name>contextConfigLocation</param-name> <!-- 指定spring配置文件的路径 --> <param-value>classpath:applicationContext.xml</param-value> </context-param> <!-- Bootstraps the root web application context before servlet initialization --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> </web-app>
原文地址:https://www.cnblogs.com/psxfd4/p/11495019.html
- Android终端上视频转GIF的实现及GIF质量讨论
- Android手机上用户操作模拟方法的研究与实现
- Firefox内存释放重用漏洞高级利用(Pwn2Own2014、CVE-2014-1512)
- android 线程那点事
- android 向webview传值
- 用搜索神器Everything定位Webshell木马后门
- 终端图像处理系列 - OpenGL ES 2.0 - 3D基础(矩阵投影)
- XssHtml – 基于白名单的富文本XSS过滤类
- fireeyee解剖新型Android恶意软件
- WordPress系统暴力破解测试工具 – wpbf
- RecyclerView notifyItem闪烁的问题
- 独家: iOS是如何收集用户的地理信息的
- Hygieia 为何物?DevOps 利器也
- 汽车攻击离你很近:一分钟变成汽车黑客
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 致开发人员:沉迷面向对象编程不可自拔?函数式编程了解一下
- MySQL空间函数实现位置打卡
- 单细胞交响乐8-marker基因检测
- 用TensorFlow.js在浏览器中进行实时语义分割 | MixLab算法系列
- python实现高性能mock服务
- 数据可视、语义分割、T_Youtube、智能调酒 | Mixlab人工智能合集
- Appium自动化测试框架探索与实践
- 交叉验证和超参数调整:如何优化你的机器学习模型
- 编写Docker Compose时要注意的五大常见错误
- 详解DBSCAN聚类
- 机器学习入门:偏差和方差
- Python中得可视化:使用Seaborn绘制常用图表
- 聊聊RespServer
- Spring 源码第 8 篇,各种属性的解析
- 手把手教你开发微信公众号后台