java 持久框架mybatis的初步学习

什么是 MyBatis?

MyBatis 是支持普通 SQL 查询,存储过程和高级映射的优秀持久层框架。MyBatis 消除 了几乎所有的 JDBC 代码和参数的手工设置以及结果集的检索。MyBatis 使用简单的 XML 或注解用于配置和原始映射,将接口和 Java 的 POJOs(Plain Old Java Objects,普通的 Java 对象)映射成数据库中的记录。

与Hibernate比较

Mybatis官方架构图

相关入门知识见官方文档(有中文)

下面是一个spring+mybatis用注解的方式基于ehcache实现二级缓存的简单例子

mybatis-configuration.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:mvc=”http://www.springframework.org/schema/mvc” xmlns:context=”http://www.springframework.org/schema/context”xmlns:util=”http://www.springframework.org/schema/util” xmlns:aop=”http://www.springframework.org/schema/aop”xmlns:ehcache=”http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring”xsi:schemaLocation=” http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context/spring-context-3.0.xsd”><context:component-scan base-package=”com.dempe.summer.app.user” /><!– Enables the Spring MVC @Controller programming model –><mvc:annotation-driven /><ehcache:annotation-driven cache-manager=”ehCacheManager” /><bean destroy-method=”close”><property value=”com.mysql.jdbc.Driver” /><property value=”jdbc:mysql://172.30.254.38:5000/test” /><property value=”azheng” /><property value=”123″ /></bean><bean><property ref=”dataSource” /></bean><bean><property value=”com.dempe.summer.app.user.persist” /></bean><bean><property value=”classpath:ehcache-mybatis.xml” /></bean></beans> ,都可以…孔子的,老子的. 孙子的…都可以

java 持久框架mybatis的初步学习

相关文章:

你感兴趣的文章:

标签云: