AbatorForEclipse插件使用总结
插件装好后,我们来使用看看:
1,新建一个工程AbatorTest,点击右键,新建一个abatorConfig.xml,如图:
建好后如下图:
2,
我这里是用的mysql,修改abatisconfig.xml文件如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE abatorConfiguration PUBLIC
"-//Apache Software Foundation//DTD Abator for iBATIS Configuration 1.0//EN"
"http://ibatis.apache.org/dtd/abator-config_1_0.dtd" >
<abatorConfiguration >
<abatorContext>
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/otm" userId="root" password="sa" >
<classPathEntry location="D:\apache-tomcat-6.0.20\webapps\ibatis_stu\WEB-INF\lib\mysql-connector-java-5.1.7-bin.jar" />
</jdbcConnection>
<javaModelGenerator targetPackage="com.test.dto" targetProject="AbatorTest" >
</javaModelGenerator>
<sqlMapGenerator targetPackage="com.test.sqlmap" targetProject="AbatorTest" />
<daoGenerator targetPackage="com.test.dao" targetProject="AbatorTest" type="GENERIC-CI" />
<table? tableName="customer" >
<generatedKey column="ID" sqlStatement="select LAST_INSERT_ID()" identity="true" />
</table>
<table? tableName="orders"/>
</abatorContext>
</abatorConfiguration>
建立数据库和表信息如下:
create database otm;
use otm
----测试onetomany
/*==============================================================*/
/* Table: customer????????????????????????????????????????????? */
/*==============================================================*/
create table customer
(
id?????????????????? bigint not null,
address????????????? varchar(120),
postcode???????????? varchar(6),
sex????????????????? varchar(2),
name???????????????? varchar(24),
primary key (id)
);
alter table customer comment '客户';
/*==============================================================*/
/* Table: orders??????????????????????????????????????????????? */
/*==============================================================*/
create table orders
(
id?????????????????? bigint not null,
code???????????????? varchar(24),
customerId?????????? bigint not null,
primary key (id)
);
alter table orders comment '订单';
alter table orders add constraint FK_rf1 foreign key (customerId)
references customer (id) on delete restrict on update restrict;
select * from orders;
select * from customer
select LAST_INSERT_ID()
3,选择abatorConfig.xml文件,工程结构图如下:
4,我们在使用之前先要配好SqlMapConfig.xml,这里没有整合其他框架,最原始的了:
sqlmapconfig.xml内容如下;
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<properties resource="jdbc.properties" />
<settings cacheModelsEnabled="true" errorTracingEnabled="true"
enhancementEnabled="true" lazyLoadingEnabled="true" maxRequests="32"
maxSessions="10" maxTransactions="5" useStatementNamespaces="true" />
<!--
Configure a built-in transaction manager. If you're using an app
server, you probably want to use its transaction manager and a managed
datasource
-->
<transactionManager type="JDBC" commitRequired="false">
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="${jdbc.driver}" />
<property name="JDBC.ConnectionURL" value="${jdbc.url}" />
<property name="JDBC.Username" value="${jdbc.username}" />
<property name="JDBC.Password" value="${jdbc.password}" />
</dataSource>
</transactionManager>
<!--
List the SQL Map XML files. They can be loaded from the classpath, as
they are here (com.domain.data...)
-->
<sqlMap resource="com/test/sqlmap/customer_SqlMap.xml" />
<sqlMap resource="com/test/sqlmap/orders_SqlMap.xml" />
<!-- List more here...-->
</sqlMapConfig>
jdbc.proteries文件中内容如下:
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/otm
jdbc.username=root
jdbc.password=sa
为了让控制太能出现sql语句方便我们调试,log4j.properties文件中内容如下:
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n
log4j.logger.com.ibatis=debug
log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=debug
log4j.logger.com.ibatis.common.jdbc.ScriptRunner=debug
log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=debug
log4j.logger.java.sql.Connection=debug
log4j.logger.java.sql.Statement=debug
log4j.logger.java.sql.PreparedStatement=debug,stdout
以Customer为例:
public static void main(String[] args) throws IOException {
// 读取SqlMapConfig的资源配置
Reader reader = Resources.getResourceAsReader("SqlMapConfig.xml");
SqlMapClient sqlMapClient=SqlMapClientBuilder.buildSqlMapClient(reader);
CustomerDAOImpl cus=new CustomerDAOImpl(sqlMapClient);
Customer c=new Customer();
c.setAddress("haha");
c.setName("xixi");
c.setId(new Long(1));
try {
cus.updateByPrimaryKeySelective(c);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
对应的一段配置文件如下:
<update id="abatorgenerated_updateByPrimaryKeySelective" parameterClass="com.test.dto.Customer" >
update customer
<dynamic prepend="set" >
<isNotNull prepend="," property="address"? >
address = #address:VARCHAR#
</isNotNull>
<isNotNull prepend="," property="postcode" >
postcode = #postcode:VARCHAR#
</isNotNull>
<isNotNull prepend="," property="sex" >
sex = #sex:VARCHAR#
</isNotNull>
<isNotNull prepend="," property="name" >
name = #name:VARCHAR#
</isNotNull>
</dynamic>
where id = #id:BIGINT#
</update>
下面是打印出的结果。
log4j:WARN No appenders could be found for logger (com.ibatis.common.jdbc.SimpleDataSource).
log4j:WARN Please initialize the log4j system properly.
2010-03-14 16:13:21,812 DEBUG [java.sql.PreparedStatement] - {pstm-100001} Executing Statement:????? update customer???? set??????????????? address = ???????????????????????????? ,???????? name = ????????????????? where id = ???
2010-03-14 16:13:21,812 DEBUG [java.sql.PreparedStatement] - {pstm-100001} Parameters: [haha, xixi, 1]
2010-03-14 16:13:21,812 DEBUG [java.sql.PreparedStatement] - {pstm-100001} Types: [java.lang.String, java.lang.String, java.lang.Long]
在自动生成pojo类中,对应就有一个xxxexample类,我们在用一下这个类。
public static void main(String[] args) throws IOException {
// 读取SqlMapConfig的资源配置
Reader reader = Resources.getResourceAsReader("SqlMapConfig.xml");
SqlMapClient sqlMapClient=SqlMapClientBuilder.buildSqlMapClient(reader);
CustomerDAOImpl cus=new CustomerDAOImpl(sqlMapClient);
CustomerExample ce=new CustomerExample();
CustomerExample.Criteria cr=ce.createCriteria();
cr.andAddressIsNotNull();
cr.andAddressLike("h");
ce.setOrderByClause("id");
try {
cus.selectByExample(ce);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
在XXXexample类中有个静态的内部内:部分内容如下:
public static class Criteria {
protected List criteriaWithoutValue;
protected List criteriaWithSingleValue;
protected List criteriaWithListValue;
protected List criteriaWithBetweenValue;
protected Criteria() {
super();
criteriaWithoutValue = new ArrayList();
criteriaWithSingleValue = new ArrayList();
criteriaWithListValue = new ArrayList();
criteriaWithBetweenValue = new ArrayList();
}
public boolean isValid() {
return criteriaWithoutValue.size() > 0
|| criteriaWithSingleValue.size() > 0
|| criteriaWithListValue.size() > 0
|| criteriaWithBetweenValue.size() > 0;
}
public List getCriteriaWithoutValue() {
return criteriaWithoutValue;
}
public List getCriteriaWithSingleValue() {
return criteriaWithSingleValue;
}
public List getCriteriaWithListValue() {
return criteriaWithListValue;
}
public List getCriteriaWithBetweenValue() {
return criteriaWithBetweenValue;
}
protected void addCriterion(String condition) {
if (condition == null) {
throw new RuntimeException("Value for condition cannot be null");
}
criteriaWithoutValue.add(condition);
}
protected void addCriterion(String condition, Object value, String property) {
if (value == null) {
throw new RuntimeException("Value for " + property + " cannot be null");
}
Map map = new HashMap();
map.put("condition", condition);
map.put("value", value);
criteriaWithSingleValue.add(map);
}
protected void addCriterion(String condition, List values, String property) {
if (values == null || values.size() == 0) {
throw new RuntimeException("Value list for " + property + " cannot be null or empty");
}
Map map = new HashMap();
map.put("condition", condition);
map.put("values", values);
criteriaWithListValue.add(map);
}
protected void addCriterion(String condition, Object value1, Object value2, String property) {
if (value1 == null || value2 == null) {
throw new RuntimeException("Between values for " + property + " cannot be null");
}
List list = new ArrayList();
list.add(value1);
list.add(value2);
Map map = new HashMap();
map.put("condition", condition);
map.put("values", list);
criteriaWithBetweenValue.add(map);
}
很关键的对应的配置文件部分内容如下:
<sql id="abatorgenerated_Example_Where_Clause"? >
<iterate property="oredCriteria" conjunction="or" prepend="where" removeFirstPrepend="iterate" >
<isEqual property="oredCriteria[].valid" compareValue="true"? >
(
<iterate prepend="and" property="oredCriteria[].criteriaWithoutValue" conjunction="and" >
$oredCriteria[].criteriaWithoutValue[]$
</iterate>
<iterate prepend="and" property="oredCriteria[].criteriaWithSingleValue" conjunction="and"? >
$oredCriteria[].criteriaWithSingleValue[].condition$
#oredCriteria[].criteriaWithSingleValue[].value#
</iterate>
<iterate prepend="and" property="oredCriteria[].criteriaWithListValue" conjunction="and" >
$oredCriteria[].criteriaWithListValue[].condition$
<iterate property="oredCriteria[].criteriaWithListValue[].values" open="(" close=")" conjunction="," >
#oredCriteria[].criteriaWithListValue[].values[]#
</iterate>
</iterate>
<iterate prepend="and" property="oredCriteria[].criteriaWithBetweenValue" conjunction="and" >
$oredCriteria[].criteriaWithBetweenValue[].condition$
#oredCriteria[].criteriaWithBetweenValue[].values[0]# and
#oredCriteria[].criteriaWithBetweenValue[].values[1]#
</iterate>
)
</isEqual>
</iterate>
</sql>
下载:http://download.csdn.net/user/fatbear007
AbatorForEclipse插件使用总结的更多相关文章
- Angular杂谈系列1-如何在Angular2中使用jQuery及其插件
jQuery,让我们对dom的操作更加便捷.由于其易用性和可扩展性,jQuer也迅速风靡全球,各种插件也是目不暇接. 我相信很多人并不能直接远离jQuery去做前端,因为它太好用了,我们以前做的东西大 ...
- Jenkins 安装的HTML Publisher Plugin 插件无法展示ant生成的JunitReport报告
最近在做基于jenkins ant junit 的测试持续集成,单独ant junit生成的junitreport报告打开正常,使用Jenkins的HTML Publisher Plugin 插件无 ...
- 常用 Gulp 插件汇总 —— 基于 Gulp 的前端集成解决方案(三)
前两篇文章讨论了 Gulp 的安装部署及基本概念,借助于 Gulp 强大的 插件生态 可以完成很多常见的和不常见的任务.本文主要汇总常用的 Gulp 插件及其基本使用,需要读者对 Gulp 有一个基本 ...
- solr服务中集成IKAnalyzer中文分词器、集成dataimportHandler插件
昨天已经在Tomcat容器中成功的部署了solr全文检索引擎系统的服务:今天来分享一下solr服务在海量数据的网站中是如何实现数据的检索. 在solr服务中集成IKAnalyzer中文分词器的步骤: ...
- 使用Visual Studio SDK制作GLSL词法着色插件
使用Visual Studio SDK制作GLSL词法着色插件 我们在Visual Studio上开发OpenGL ES项目时,避免不了写Shader.这时在vs里直接编辑shader就会显得很方便. ...
- 工欲善其事,必先利其器 之 VS2013全攻略(安装,技巧,快捷键,插件)!
如有需要WPF工具的朋友可以移步 工欲善其事,必先利其器 之 WPF篇: 随着开发轨迹来看高效WPF开发的工具和技巧 之前一篇<c++的性能, c#的产能?!鱼和熊掌可以兼得,.NET NATI ...
- Jquery mobiscroll 移动设备(手机)wap日期时间选择插件以及滑动、滚动插件
Jquery Mobiscroll是一个用于触摸设备(Android phones, iPhone, iPad, Galaxy Tab)的日期和时间选择器jQuery插件.以及各种滑动插件 可以让用户 ...
- 10个最好用的HTML/CSS 工具、插件和资料库
大家在使用HTML/CSS开发项目的过程中,有使用过哪些工具,插件和库?下面介绍的10种HTML/CSS工具,插件和资料库,是国外程序员经常用到的. Firebug Lite FirebugLite ...
- 在Sublime Text 3上安装代码格式化插件CodeFormatter
1.了解CodeFormatter插件 在Sublime Text 3中编写代码,为了能让我们的代码格式变得漂亮整洁,需要一个能自动格式代码的插件.这里发现CodeFormatter插件不错,它能支持 ...
随机推荐
- 如何在JTable中动态添加一行
JTable tbImage = new JTable(5,5);//create a dummy tableDefaultTableModel dtm=(DefaultTableModel)tbIm ...
- Android之LogUtil
提供debug与release的时候是否屏蔽打印信息,把信息选择性的进行保存,可以是否自动保存crash的堆栈信息.来自github上的一个开源项目,https://github.com/syxc/L ...
- 安卓下查看kmsg内核日志
cat /proc/kmsg <6>[ 2601.360] c0@A7 lm3695_early_suspend 247<6>[ 2601.380] c1@A7 gp2ap_e ...
- 微博与Redis系统技术文章记录
Redis 持久化,有两种: rdb 和 aof, rdb是记录一段时间内的操作,一盘的配置是一段时间内操作超过多少次就持久化. aof可以实现每次操作都持久化. 这里我们使用aof. 配置方式,打开 ...
- ubuntu 12.04 安装无线网卡驱动
安装ubuntu 12.04后,无线网卡不可用,采用以下方式解决: 1.在终端中运行如下命令,重新安装b43相关的全部驱动和firmware: sudo apt-get install bcmwl-k ...
- Spark RDD关联操作小结
前言 Spark的rdd之间的关系需要通过一些特定的操作来实现, 操作比较多也,特别是一堆JOIN也挺容易让人产生混乱的. 因此做了下小结梳理一下. 准备数据 var rdd1 = sc.makeRD ...
- Unity异步加载场景loading条
using UnityEngine; using System.Collections; public class LoadingScene : MonoBehaviour { public UISl ...
- COM中的HRESULT
- System.Net.Http.Formatting的nuget版本冲突问题
已经添加了nuget Microsoft.AspNet.WebApi.Client 调用System.Net.Http.HttpClient.PostAsJsonAsync的时候报如下的错误: C ...
- 如何做windows server 2008 R2 的磁盘清理
参考如下的链接: https://technet.microsoft.com/en-us/library/ff630161(v=ws.10).aspx 运行后可能没有啥反应,磁盘空间也没增大.那是因为 ...