MyBatis+Spring基于接口编程的原理分析.docx
文本预览下载声明
整合Spring3及MyBatis3? 对于整合Spring及Mybatis不作详细介绍,可以参考: MyBatis 3 User Guide Simplified Chinese.pdf,贴出我的主要代码如下:UserMapper Interface: Java代码?package?org.denger.mapper; ????import?org.apache.ibatis.annotations.Param; ??import?org.apache.ibatis.annotations.Select; ??import?org.denger.po.User; ????public?interface?UserMapper?{ ????????@Select(select?*?from?tab_uc_account?where?id=#{userId}) ??????User?getUser(@Param(userId)?Long?userId); ??}??package org.denger.mapper;import org.apache.ibatis.annotations.Param;import org.apache.ibatis.annotations.Select;import org.denger.po.User;public interface UserMapper {@Select(select * from tab_uc_account where id=#{userId})User getUser(@Param(userId) Long userId);}application-context.xml: Xml代码??xml?version=1.0?encoding=UTF-8???beans?xmlns=/schema/beans??????xmlns:xsi=/2001/XMLSchema-instance?xmlns:context=/schema/context??????xmlns:aop=/schema/aop?xmlns:tx=/schema/tx??????xsi:schemaLocation=/schema/beans?/schema/beans/spring-beans-3.0.xsd?/schema/context?/schema/context/spring-context-3.0.xsd?/schema/aop?/schema/aop/spring-aop-2.0.xsd?/schema/tx?/schema/tx/spring-tx-2.0.xsd??????????!--?Provided?by?annotation-based?configuration??--??????context:annotation-config/????????!--JDBC?Transaction??Manage?--??????bean?id=dataSourceProxy?class=org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy??????????constructor-arg??????????????ref?bean=dataSource?/??????????/constructor-arg??????/bean????????!--?The?JDBC?c3p0?dataSource?bean--??????bean?id=dataSource?class=com.mchange.v2.c3p0.ComboPooledDataSource?destroy-method=close??????????property?name=driverClass?value=com.mysql.jdbc.Driver?/??????????property?name=jdbcUrl?value=jdbc:mysql://:3306/noah?/??????????property?name=user?value=root?/??????????property?name=password?value=123456?/??????/bean????????!--MyBatis?integration?with?Spring?as?define?sqlSessionFactory??--??????bean?id=sqlSessionFactory?class=org.mybatis.spring.SqlSessionFactoryBean??????????property?name=dataSourc
显示全部