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插件不错,它能支持 ...
随机推荐
- myql --- mysqldump使用方法
1.mysqldump的几种常用方法: (1)导出整个数据库(包括数据库中的数据) mysqldump -u username -p dbname > dbname.sql (2)导出数据库结构 ...
- Eclipse 搭建struts2 spring3 hibernate3环境实战 待完善
1.struts2 目前是2.3版本,下载地址http://struts.apache.org/download.cgi struts2包 struts2-core-2.3.16.3.jar stru ...
- 在mac上命令行里面如何打开文本编辑器?
在mac上命令行里面如何打开文本编辑器? 在linux命令行terminal上使用gedit直接就可以打开文本文件 那么在mac上面如何操作呢? 使用:open -a TextEdit setti ...
- 简明python教程 --C++程序员的视角(七):异常
当你的程序中出现某些 异常的 状况的时候,异常就发生了.例如,当你想要读某个文件的时候,而那个文件不存在.或者在程序运行的时候,你不小心把它删除了.上述这些情况可以使用异常来处理. 假如你的程序中有一 ...
- 学习笔记:AC自动机
话说AC自动机有什么用......我想要自动AC机 AC自动机简介: 首先简要介绍一下AC自动机:Aho-Corasick automation,该算法在1975年产生于贝尔实验室,是著名的多模匹配 ...
- go语言之进阶篇方法面向过程和对象函数的区别
1.方法 (method) 在面向对象编程中,一个对象其实也就是一个简单的值或者一个变量,在这个对象中会包含一些函数,这种带有接收者的函数,我们称为方法(method). 本质上,一个方法则是一个和特 ...
- HTML5 Canvas,WebGL,CSS Shaders,GLSL的暧昧关系 【转】
HTML5 Canvas,WebGL,CSS Shaders,GLSL的暧昧关系 这篇文章发布于 2011年10月10日,星期一,17:14,归类于 canvas相关. 阅读 58013 次, 今日 ...
- C#操作AD及Exchange Server总结(一)
这篇博客的目的:根据亲身项目经历,总结对AD及Exchange Server的操作,包括新建AD用户,设置密码,为AD用户创建邮箱等. 本文完全原创,转载请说明出处,希望对大家有用. 文档目录: 测试 ...
- java 切图 判断图片是否是纯色/彩色图片
首先上切图的代码 /** * 图片剪裁 * @param x 距离左上角的x轴距离 * @param y 距离左上角的y轴距离 * @param width 宽度 * @param height 高度 ...
- Godaddy ssl续费更新问题总结
之前客户在Godaddy 上购买的ssl证书过期了,但客户续费后打开https时却提示证书过期了 进行Godaddy 后台看到证书确实是过期的 但在账户里也确实看到ssl续费成功了 猜想可能是ssl续 ...