mybatis学习笔记一mybatis结合spring mvc配置
来源:互联网 发布:战舰世界 爱宕数据 编辑:程序博客网 时间:2024/05/20 00:53
这两天,开始学习mybatis,有点感觉,分享一下,在这里要感谢一号门博客 链接:http://www.yihaomen.com/article/java/426.htm
首先项目示例图给大家看一下:
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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-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/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd" default-autowire="byName" default-lazy-init="false"> <!-- 自动扫描web包 ,将带有注解的类 纳入spring容器管理 --><context:component-scan base-package="com.yihaomen"></context:component-scan><!-- 引入jdbc配置文件 --><bean id="propertyConfigurer"class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="locations"><list><value>classpath:config/jdbc.properties</value></list></property></bean><!-- 配置数据源 one--><bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"><property name="driverClassName" value="${jdbc.driver}"></property><property name="url" value="${jdbc.url}"></property><property name="username" value="${jdbc.username}"></property><property name="password" value="${jdbc.password}"></property> <!-- initialSize: 初始化连接 --><property name="initialSize" value="5" /> <!-- maxIdle: 最大空闲连接 --><property name="maxIdle" value="10" /><property name="minIdle" value="5" /><property name="maxActive" value="15" /><property name="removeAbandoned" value="true" /><property name="removeAbandonedTimeout" value="180" /> <!-- maxWait: 超时等待时间以毫秒为单位 6000毫秒/1000等于60秒 --><property name="maxWait" value="3000" /><property name="validationQuery"><value>SELECT 1</value></property><property name="testOnBorrow"><value>true</value></property></bean> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <bean id="sqlSessionFactoryBeanName" class="org.mybatis.spring.SqlSessionFactoryBean"> <!--dataSource属性指定要用到的连接池--> <property name="dataSource" ref="dataSource"/> <!--configLocation属性指定mybatis的核心配置文件--> <property name="configLocation" value="classpath:config/Configuration.xml" /> <!-- 所有配置的mapper文件 --> <property name="mapperLocations" value="classpath*:com/yihaomen/mapper/*.xml" /> </bean> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.yihaomen.inter" /> </bean> </beans>
jdbc.driver=com.mysql.jdbc.Driverjdbc.url=jdbc:mysql://localhost:3306/mybatis?characterEncoding=utf8jdbc.username=rootjdbc.password=123456
Configuration.xml(主要减少减少类名的长度来设置的,后面会介绍)
<configuration> <typeAliases> <typeAlias alias="User" type="com.yihaomen.model.User"/> </typeAliases> </configuration>
log4j.properties(日志配置)
log4j.rootCategory=info, stdout , Rlog4j.appender.stdout=org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.layout=org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern=[QC] %p [%t] %C.%M(%L) | %m%nlog4j.appender.R=org.apache.log4j.DailyRollingFileAppenderlog4j.appender.R.File=D:/my_log.loglog4j.appender.R.layout=org.apache.log4j.PatternLayoutlog4j.appender.R.layout.ConversionPattern=%d-[TS] %p %t %c - %m%nlog4j.logger.com.ibatis=debuglog4j.logger.com.ibatis.common.jdbc.SimpleDataSource=debuglog4j.logger.com.ibatis.common.jdbc.ScriptRunner=debuglog4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=debuglog4j.logger.java.sql.Connection=debuglog4j.logger.java.sql.Statement=debuglog4j.logger.java.sql.PreparedStatement=debug,stdout
1 0
- mybatis学习笔记一mybatis结合spring mvc配置
- spring mvc+mybatis笔记(一)
- mybatis学习笔记二mybatis结合spring mvc实现(用户登录,数据查询)
- spring MVC+mybatis+spring security笔记<一>
- spring mvc、meven结合mybatis
- mybatis学习 一、MyBatis简介与配置MyBatis+Spring+MySql
- mybatis学习 一、MyBatis简介与配置MyBatis+Spring+MySql
- MyBatis学习(一)MyBatis简介与配置MyBatis+Spring+MySql
- Mybatis学习(一)MyBatis简介与配置MyBatis+Spring+MySql
- spring+spring-mvc+mybatis配置
- spring+spring mvc+mybatis配置
- spring+spring mvc + mybatis + maven 项目框架搭建笔记<一>
- MyBatis学习总结(一):配置Spring+Mybatis+MySql
- jee、spring、spring mvc、mybatis 学习(一)
- spring mvc+mybatis笔记(二)
- spring mvc+mybatis笔记(三)
- 电商平台学习笔记(一)——Spring MVC+Mybatis分页插件
- Spring MyBatis 学习笔记
- iOS 类别和扩展(Categories和Extensions)
- eclipse maven配置
- 转为json数据、json-lib和google gson对比
- IOS-使用AVAudioPlayer播放音乐文件无声音
- Cocos2dx引擎9-注册事件监听器
- mybatis学习笔记一mybatis结合spring mvc配置
- jvm(7)-虚拟机类加载机制
- dpdk初识
- Andriod中Style/Theme原理以及Activity界面文件选取过程浅析
- 手机卫士 第九天
- 简单的JSP交互程序
- php - 字符串内容为数组如何进行格式转换为数组
- 隐藏用户
- android studio显示设置(外观和字体)