4.2)ibatorConfig.xml文件
xml version = "1.0" encoding = "UTF-8" ?>
>
< ibatorConfiguration >
< classPathEntry
location = "D:/Eclipse/workspace/helios-3.6/test/lib/mysql_connector_java_5.jar" />
< ibatorContext id = "context1" targetRuntime = "Ibatis2Java5" >
< commentGenerator >
< property name = "suppressDate" value = "true" />
commentGenerator >
< jdbcConnection driverClass = "com.mysql.jdbc.Driver"
connectionURL = "jdbc:mysql://127.0.0.1:3306/test" userId = "root"
password = "root" >
jdbcConnection >
< javaModelGenerator targetPackage = "cn.zlj.ibatis.entity"
targetProject = "test" />
< sqlMapGenerator targetPackage = "cn.zlj.ibatis.sqlmap"
targetProject = "test" />
< daoGenerator targetPackage = "cn.zlj.ibatis.dao"
targetProject = "test" implementationPackage = "cn.zlj.ibatis.dao.impl"
type = "spring" />
< table tableName = "brand" >
table >
< table tableName = "employee" >
table >
ibatorContext >
ibatorConfiguration >
4.3)ibator生成文件
package cn.zlj.ibatis.entity;
public class Brand {
private String code;
private String logopath;
private String name;
private Boolean visible;
public String getCode() {
return code;
}
public void setCode(String code) {
this .code = code;
}
public String getLogopath() {
return logopath;
}
public void setLogopath(String logopath) {
this .logopath = logopath;
}
public String getName() {
return name;
}
public void setName(String name) {
this .name = name;
}
public Boolean getVisible() {
return visible;
}
public void setVisible(Boolean visible) {
this .visible = visible;
}
}
package cn.zlj.ibatis.entity;
public class Brand {
/**
* 代码
*/
private String code;
/**
* logo路径
*/
private String logopath;
/**
* 名字
*/
private String name;
/**
* 是否可见
*/
private Boolean visible;
/**
* 获取 代码
*
* @return
*/
public String getCode() {
return code;
}
/**
* 设置 代码
*
* @param code
*/
public void setCode(String code) {
this.code = code;
}
/**
* 获取 logo路径
*
* @return
*/
public String getLogopath() {
return logopath;
}
/**
* 设置 logo路径
*
* @param logopath
*/
public void setLogopath(String logopath) {
this.logopath = logopath;
}
/**
* 获取 名字
*
* @return
*/
public String getName() {
return name;
}
/**
* 设置 名字
*
* @param name
*/
public void setName(String name) {
this.name = name;
}
/**
* 获取 是否可见
*
* @return
*/
public Boolean getVisible() {
return visible;
}
/**
* 设置 是否可见
*
* @param visible
*/
public void setVisible(Boolean visible) {
this.visible = visible;
}
}
package cn.zlj.ibatis.entity;
public class Employee {
/**
* 用户名
*/
private String username;
/**
* 等级
*/
private String degree;
/**
* 电子邮箱
*/
private String email;
/**
* 性别
*/
private String gender;
/**
* 图片名字
*/
private String imagename;
/**
* 密码
*/
private String password;
/**
* 电话
*/
private String phone;
/**
* 真实姓名
*/
private String realname;
/**
* 学校
*/
private String school;
/**
* 是否可见
*/
private Boolean visible;
/**
* 部门ID
*/
private Integer departmentId;
/**
* 身份证
*/
private Integer cardId;
/**
* 获取 用户名
*
* @return
*/
public String getUsername() {
return username;
}
/**
* 设置 用户名
*
* @param username
*/
public void setUsername(String username) {
this.username = username;
}
/**
* 获取 等级
*
* @return
*/
public String getDegree() {
return degree;
}
/**
* 设置 等级
*
* @param degree
*/
public void setDegree(String degree) {
this.degree = degree;
}
/**
* 获取 电子邮箱
*
* @return
*/
public String getEmail() {
return email;
}
/**
* 设置 电子邮箱
*
* @param email
*/
public void setEmail(String email) {
this.email = email;
}
/**
* 获取 性别
*
* @return
*/
public String getGender() {
return gender;
}
/**
* 设置 性别
*
* @param gender
*/
public void setGender(String gender) {
this.gender = gender;
}
/**
* 获取 图片名字
*
* @return
*/
public String getImagename() {
return imagename;
}
/**
* 设置 图片名字
*
* @param imagename
*/
public void setImagename(String imagename) {
this.imagename = imagename;
}
/**
* 获取 密码
*
* @return
*/
public String getPassword() {
return password;
}
/**
* 设置 密码
*
* @param password
*/
public void setPassword(String password) {
this.password = password;
}
/**
* 获取 电话
*
* @return
*/
public String getPhone() {
return phone;
}
/**
* 设置 电话
*
* @param phone
*/
public void setPhone(String phone) {
this.phone = phone;
}
/**
* 获取 真实姓名
*
* @return
*/
public String getRealname() {
return realname;
}
/**
* 设置 真实姓名
*
* @param realname
*/
public void setRealname(String realname) {
this.realname = realname;
}
/**
* 获取 学校
*
* @return
*/
public String getSchool() {
return school;
}
/**
* 设置 学校
*
* @param school
*/
public void setSchool(String school) {
this.school = school;
}
/**
* 获取 是否可见
*
* @return
*/
public Boolean getVisible() {
return visible;
}
/**
* 设置 是否可见
*
* @param visible
*/
public void setVisible(Boolean visible) {
this.visible = visible;
}
/**
* 获取 部门ID
*
* @return
*/
public Integer getDepartmentId() {
return departmentId;
}
/**
* 设置 部门ID
*
* @param departmentId
*/
public void setDepartmentId(Integer departmentId) {
this.departmentId = departmentId;
}
/**
* 获取 身份证
*
* @return
*/
public Integer getCardId() {
return cardId;
}
/**
* 设置 身份证
*
* @param cardId
*/
public void setCardId(Integer cardId) {
this.cardId = cardId;
}
}
xml version = "1.0" encoding = "UTF-8" ?>
>
< sqlMap namespace = "brand" >
< resultMap id = "BaseResultMap" class = "cn.zlj.ibatis.entity.Brand" >
< result column = "code" property = "code" jdbcType = "VARCHAR" />
< result column = "logopath" property = "logopath" jdbcType = "VARCHAR" />
< result column = "name" property = "name" jdbcType = "VARCHAR" />
< result column = "visible" property = "visible" jdbcType = "BIT" />
resultMap >
< sql id = "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 >
< sql id = "Base_Column_List" >
code, logopath, name, visible
sql >
< select id = "selectByExample" resultMap = "BaseResultMap" parameterClass = "cn.zlj.ibatis.entity.BrandExample" >
select
< isParameterPresent >
< isEqual property = "distinct" compareValue = "true" >
distinct
isEqual >
isParameterPresent >
< include refid = "brand.Base_Column_List" />
from brand
< isParameterPresent >
< include refid = "brand.Example_Where_Clause" />
< isNotNull property = "orderByClause" >
order by $orderByClause$
isNotNull >
isParameterPresent >
select >
< select id = "selectByPrimaryKey" resultMap = "BaseResultMap" parameterClass = "cn.zlj.ibatis.entity.Brand" >
select
< include refid = "brand.Base_Column_List" />
from brand
where code = #code:VARCHAR#
select >
< delete id = "deleteByPrimaryKey" parameterClass = "cn.zlj.ibatis.entity.Brand" >
delete from brand
where code = #code:VARCHAR#
delete >
< delete id = "deleteByExample" parameterClass = "cn.zlj.ibatis.entity.BrandExample" >
delete from brand
< include refid = "brand.Example_Where_Clause" />
delete >
< insert id = "insert" parameterClass = "cn.zlj.ibatis.entity.Brand" >
insert into brand (code, logopath, name, visible)
values (#code:VARCHAR#, #logopath:VARCHAR#, #name:VARCHAR#, #visible:BIT#)
insert >
< insert id = "insertSelective" parameterClass = "cn.zlj.ibatis.entity.Brand" >
insert into brand
< dynamic prepend = "(" >
< isNotNull prepend = "," property = "code" >
code
isNotNull >
< isNotNull prepend = "," property = "logopath" >
logopath
isNotNull >
< isNotNull prepend = "," property = "name" >
name
isNotNull >
< isNotNull prepend = "," property = "visible" >
visible
isNotNull >
)
dynamic >
values
< dynamic prepend = "(" >
< isNotNull prepend = "," property = "code" >
#code:VARCHAR#
isNotNull >
< isNotNull prepend = "," property = "logopath" >
#logopath:VARCHAR#
isNotNull >
< isNotNull prepend = "," property = "name" >
#name:VARCHAR#
isNotNull >
< isNotNull prepend = "," property = "visible" >
#visible:BIT#
isNotNull >
)
dynamic >
insert >
< select id = "countByExample" parameterClass = "cn.zlj.ibatis.entity.BrandExample" resultClass = "java.lang.Integer" >
select count(*) from brand
< include refid = "brand.Example_Where_Clause" />
select >
< update id = "updateByExampleSelective" >
update brand
< dynamic prepend = "set" >
< isNotNull prepend = "," property = "record.code" >
code = #record.code:VARCHAR#
isNotNull >
< isNotNull prepend = "," property = "record.logopath" >
logopath = #record.logopath:VARCHAR#
isNotNull >
< isNotNull prepend = "," property = "record.name" >
name = #record.name:VARCHAR#
isNotNull >
< isNotNull prepend = "," property = "record.visible" >
visible = #record.visible:BIT#
isNotNull >
dynamic >
< isParameterPresent >
< include refid = "brand.Example_Where_Clause" />
isParameterPresent >
update >
< update id = "updateByExample" >
update brand
set code = #record.code:VARCHAR#,
logopath = #record.logopath:VARCHAR#,
name = #record.name:VARCHAR#,
visible = #record.visible:BIT#
< isParameterPresent >
< include refid = "brand.Example_Where_Clause" />
isParameterPresent >
update >
< update id = "updateByPrimaryKeySelective" parameterClass = "cn.zlj.ibatis.entity.Brand" >
update brand
< dynamic prepend = "set" >
< isNotNull prepend = "," property = "logopath" >
logopath = #logopath:VARCHAR#
isNotNull >
< isNotNull prepend = "," property = "name" >
name = #name:VARCHAR#
isNotNull >
< isNotNull prepend = "," property = "visible" >
visible = #visible:BIT#
isNotNull >
dynamic >
where code = #code:VARCHAR#
update >
< update id = "updateByPrimaryKey" parameterClass = "cn.zlj.ibatis.entity.Brand" >
update brand
set logopath = #logopath:VARCHAR#,
name = #name:VARCHAR#,
visible = #visible:BIT#
where code = #code:VARCHAR#
update >
sqlMap >
(
$oredCriteria[].criteriaWithoutValue[]$
$oredCriteria[].criteriaWithSingleValue[].condition$ #oredCriteria[].criteriaWithSingleValue[].value#
$oredCriteria[].criteriaWithListValue[].condition$
#oredCriteria[].criteriaWithListValue[].values[]#
$oredCriteria[].criteriaWithBetweenValue[].condition$
#oredCriteria[].criteriaWithBetweenValue[].values[0]# and
#oredCriteria[].criteriaWithBetweenValue[].values[1]#
)
code, logopath, name, visible
select
distinct
from brand
order by $orderByClause$
select
from brand
where code = #code:VARCHAR#
delete from brand
where code = #code:VARCHAR#
delete from brand
insert into brand (code, logopath, name, visible)
values (#code:VARCHAR#, #logopath:VARCHAR#, #name:VARCHAR#, #visible:BIT#)
insert into brand
code
logopath
name
visible
)
values
#code:VARCHAR#
#logopath:VARCHAR#
#name:VARCHAR#
#visible:BIT#
)
select count(*) from brand
update brand
code = #record.code:VARCHAR#
logopath = #record.logopath:VARCHAR#
name = #record.name:VARCHAR#
visible = #record.visible:BIT#
update brand
set code = #record.code:VARCHAR#,
logopath = #record.logopath:VARCHAR#,
name = #record.name:VARCHAR#,
visible = #record.visible:BIT#
update brand
logopath = #logopath:VARCHAR#
name = #name:VARCHAR#
visible = #visible:BIT#
where code = #code:VARCHAR#
update brand
set logopath = #logopath:VARCHAR#,
name = #name:VARCHAR#,
visible = #visible:BIT#
where code = #code:VARCHAR#
package cn.zlj.ibatis.dao;
import cn.zlj.ibatis.entity.Brand;
import cn.zlj.ibatis.entity.BrandExample;
import java.util.List;
public interface BrandDAO {
int countByExample(BrandExample example);
int deleteByExample(BrandExample example);
int deleteByPrimaryKey(String code);
void insert(Brand record);
void insertSelective(Brand record);
List selectByExample(BrandExample example);
Brand selectByPrimaryKey(String code);
int updateByExampleSelective(Brand record, BrandExample example);
int updateByExample(Brand record, BrandExample example);
int updateByPrimaryKeySelective(Brand record);
int updateByPrimaryKey(Brand record);
}
package cn.zlj.ibatis.dao;
import cn.zlj.ibatis.entity.Brand;
import cn.zlj.ibatis.entity.BrandExample;
import java.util.List;
public interface BrandDAO {
/**
* brand countByExample
*/
int countByExample(BrandExample example);
/**
* brand deleteByExample
*/
int deleteByExample(BrandExample example);
/**
* brand deleteByPrimaryKey
*/
int deleteByPrimaryKey(String code);
/**
* brand insert
*/
void insert(Brand record);
/**
* brand insertSelective
*/
void insertSelective(Brand record);
/**
* brand selectByExample
*/
List selectByExample(BrandExample example);
/**
* brand selectByPrimaryKey
*/
Brand selectByPrimaryKey(String code);
/**
* brand updateByExampleSelective
*/
int updateByExampleSelective(Brand record, BrandExample example);
/**
* brand updateByExample
*/
int updateByExample(Brand record, BrandExample example);
/**
* brand updateByPrimaryKeySelective
*/
int updateByPrimaryKeySelective(Brand record);
/**
* brand updateByPrimaryKey
*/
int updateByPrimaryKey(Brand record);
}
package cn.zlj.ibatis.dao.impl;
import cn.zlj.ibatis.dao.BrandDAO;
import cn.zlj.ibatis.entity.Brand;
import cn.zlj.ibatis.entity.BrandExample;
import java.util.List;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
public class BrandDAOImpl extends SqlMapClientDaoSupport implements BrandDAO {
public BrandDAOImpl() {
super ();
}
public int countByExample(BrandExample example) {
Integer count = (Integer) getSqlMapClientTemplate().queryForObject( "brand.countByExample" , example);
return count;
}
public int deleteByExample(BrandExample example) {
int rows = getSqlMapClientTemplate().delete( "brand.deleteByExample" , example);
return rows;
}
public int deleteByPrimaryKey(String code) {
Brand _key = new Brand();
_key.setCode(code);
int rows = getSqlMapClientTemplate().delete( "brand.deleteByPrimaryKey" , _key);
return rows;
}
public void insert(Brand record) {
getSqlMapClientTemplate().insert( "brand.insert" , record);
}
public void insertSelective(Brand record) {
getSqlMapClientTemplate().insert( "brand.insertSelective" , record);
}
@SuppressWarnings ( "unchecked" )
public List selectByExample(BrandExample example) {
List list = getSqlMapClientTemplate().queryForList( "brand.selectByExample" , example);
return list;
}
public Brand selectByPrimaryKey(String code) {
Brand _key = new Brand();
_key.setCode(code);
Brand record = (Brand) getSqlMapClientTemplate().queryForObject( "brand.selectByPrimaryKey" , _key);
return record;
}
public int updateByExampleSelective(Brand record, BrandExample example) {
UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
int rows = getSqlMapClientTemplate().update( "brand.updateByExampleSelective" , parms);
return rows;
}
public int updateByExample(Brand record, BrandExample example) {
UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
int rows = getSqlMapClientTemplate().update( "brand.updateByExample" , parms);
return rows;
}
public int updateByPrimaryKeySelective(Brand record) {
int rows = getSqlMapClientTemplate().update( "brand.updateByPrimaryKeySelective" , record);
return rows;
}
public int updateByPrimaryKey(Brand record) {
int rows = getSqlMapClientTemplate().update( "brand.updateByPrimaryKey" , record);
return rows;
}
protected static class UpdateByExampleParms extends BrandExample {
private Object record;
public UpdateByExampleParms(Object record, BrandExample example) {
super (example);
this .record = record;
}
public Object getRecord() {
return record;
}
}
}
package cn.zlj.ibatis.dao.impl;
import cn.zlj.ibatis.dao.BrandDAO;
import cn.zlj.ibatis.entity.Brand;
import cn.zlj.ibatis.entity.BrandExample;
import java.util.List;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
public class BrandDAOImpl extends SqlMapClientDaoSupport implements BrandDAO {
/**
* brand BrandDAOImpl
*/
public BrandDAOImpl() {
super();
}
/**
* brand countByExample
*/
public int countByExample(BrandExample example) {
Integer count = (Integer) getSqlMapClientTemplate().queryForObject("brand.countByExample", example);
return count;
}
/**
* brand deleteByExample
*/
public int deleteByExample(BrandExample example) {
int rows = getSqlMapClientTemplate().delete("brand.deleteByExample", example);
return rows;
}
/**
* brand deleteByPrimaryKey
*/
public int deleteByPrimaryKey(String code) {
Brand _key = new Brand();
_key.setCode(code);
int rows = getSqlMapClientTemplate().delete("brand.deleteByPrimaryKey", _key);
return rows;
}
/**
* brand insert
*/
public void insert(Brand record) {
getSqlMapClientTemplate().insert("brand.insert", record);
}
/**
* brand insertSelective
*/
public void insertSelective(Brand record) {
getSqlMapClientTemplate().insert("brand.insertSelective", record);
}
/**
* brand selectByExample
*/
@SuppressWarnings("unchecked")
public List selectByExample(BrandExample example) {
List list = getSqlMapClientTemplate().queryForList("brand.selectByExample", example);
return list;
}
/**
* brand selectByPrimaryKey
*/
public Brand selectByPrimaryKey(String code) {
Brand _key = new Brand();
_key.setCode(code);
Brand record = (Brand) getSqlMapClientTemplate().queryForObject("brand.selectByPrimaryKey", _key);
return record;
}
/**
* brand updateByExampleSelective
*/
public int updateByExampleSelective(Brand record, BrandExample example) {
UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
int rows = getSqlMapClientTemplate().update("brand.updateByExampleSelective", parms);
return rows;
}
/**
* brand updateByExample
*/
public int updateByExample(Brand record, BrandExample example) {
UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
int rows = getSqlMapClientTemplate().update("brand.updateByExample", parms);
return rows;
}
/**
* brand updateByPrimaryKeySelective
*/
public int updateByPrimaryKeySelective(Brand record) {
int rows = getSqlMapClientTemplate().update("brand.updateByPrimaryKeySelective", record);
return rows;
}
/**
* brand updateByPrimaryKey
*/
public int updateByPrimaryKey(Brand record) {
int rows = getSqlMapClientTemplate().update("brand.updateByPrimaryKey", record);
return rows;
}
/**
* brand
*/
protected static class UpdateByExampleParms extends BrandExample {
private Object record;
public UpdateByExampleParms(Object record, BrandExample example) {
super(example);
this.record = record;
}
public Object getRecord() {
return record;
}
}
}
OK,修改完成,去掉了很多原来自动生成的注释。
可以自己写实现org.apache.ibatis.ibator.api.CommentGenerato
或者重写org.apache.ibatis.ibator.internal.DefaultCommentGenerator这个类的
public void addClassComment(InnerClass innerClass,
IntrospectedTable introspectedTable)
public void addEnumComment(InnerEnum innerEnum,
IntrospectedTable introspectedTable)
public void addFieldComment(Field field,
IntrospectedTable introspectedTable,
IntrospectedColumn introspectedColumn)
public void addFieldComment(Field field, IntrospectedTable introspectedTable);
public void addGeneralMethodComment(Method method,
IntrospectedTable introspectedTable) ;
public void addGetterComment(Method method,
IntrospectedTable introspectedTable,
IntrospectedColumn introspectedColumn) ;
public void addSetterComment(Method method,
IntrospectedTable introspectedTable,
IntrospectedColumn introspectedColumn) ;
public void addClassComment(InnerClass innerClass,
IntrospectedTable introspectedTable, boolean markAsDoNotDelete) ;
public void addClassComment(InnerClass innerClass,
IntrospectedTable introspectedTable)
public void addEnumComment(InnerEnum innerEnum,
IntrospectedTable introspectedTable)
public void addFieldComment(Field field,
IntrospectedTable introspectedTable,
IntrospectedColumn introspectedColumn)
public void addFieldComment(Field field, IntrospectedTable introspectedTable);
public void addGeneralMethodComment(Method method,
IntrospectedTable introspectedTable) ;
public void addGetterComment(Method method,
IntrospectedTable introspectedTable,
IntrospectedColumn introspectedColumn) ;
public void addSetterComment(Method method,
IntrospectedTable introspectedTable,
IntrospectedColumn introspectedColumn) ;
public void addClassComment(InnerClass innerClass,
IntrospectedTable introspectedTable, boolean markAsDoNotDelete) ;
ibator1.2.2与以前的版本的主要改变就是以上这几个方法,原来的这种
addFieldComment(Field field, FullyQualifiedTable table, String columnName)方法,
在下一版本中就会被去掉了。
public void addFieldComment(Field field, FullyQualifiedTable table, String columnName) {
。。。。。
}