Timon是基于Java的数据库持久工具,提供SQLMaps以及SQL工具
采用XML定义SQL语句
支持数据库与Java对象之间的映射
支持外部数据缓存,支持Ehcache,Memcached和内置同步缓存
提供SQL语句解析、格式化工具
安装方式
<dependency> <groupId>org.pinae</groupId> <artifactId>timon</artifactId> <version>1.1</version></dependency>实例代码
1.XML配置
<?xml version="1.0" encoding="UTF-8" ?><global key="table" value="person" /><mapper namespaces="org.piane.timon"> <sql name="getPerson"> select * from :table where 1=1 <choose when="id"> and id = :id </choose> </sql></mapper>2.实例代码
public class SQLSessionFactoryDemo { public static void main(String[] args) { SQLSessionFactory sessionFactory = null; SQLBuilder builder = null; try { builder = new SQLBuilder() sessionFactory = new SQLSessionFactory(); SQLSession session = sessionFactory.getSession(); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("id", 1); Person person = (Person)session.one( builder.getSQLByNameWithParameters("org.piane.timon.getPerson", parameters), Person.class); session.close(); } catch (IOException e) { } }}
评论