1、在 src 下添加 jdbc.properties 配置文件,配置数据库的连接信息:
注意key和以前的区别
2、在 src 下添加 mybatis-conf.xml 配置文件,配置需要单独配置的MyBatis的设置:
contextConfigLocation classpath:applicationContext.xml
Spring监听器 org.springframework.web.context.ContextLoaderListener #(mysql-connection-java-5.x.jar以前的写法) #jdbc.driver=com.mysql.jdbc.Driver #jdbc.url=jdbc:mysql://localhost:3306/dbname? useUnicode=true&characterEncoding=utf8 #jdbc.username=root #jdbc.password=root #(mysql-connection-java-6.x.jar以后的写法) jdbc.driver=com.mysql.cj.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/base_admin?characterEncoding=UTF- 8&serverTimezone=Asia/Shanghai&useSSL=false jdbc.username=root jdbc.password=root
3、在Spring的配置文件 applicationContext.xml 中整合Spring和MyBatis:完整代码:
属性 类型 默认值 说明 propagation Propagation 枚举 REQUIRED 事务传播属性 isolation isolation枚 举 DEFAULT(所用数据库默 认级别) 事务隔离级别 readonly boolean false 是否采用优化的只 读事务 timeout int -1 超时(秒) rollbackFor Class[] {} 需要回滚的异常类 rollbackForClassName String[] {} 需要回滚的异常类 名 noRollbackFor Class[] {} 不需要回滚的异常 类 noRollbackForClassName String[] {} 不需要回滚的异常 类名