我是如何使用MybatisGenerator的

编程

2. 原生不足

1. 没有分页

2.数据查询不能指定返回的列只能全部返回(select *)

3. 没有非空判断,andXXXEquals(xxx)当xxx为null时运行报空指针判断,这里我想xxx为null时自动跳过,条件不生效

4. 多次生成文件重合  1.3.7版好像解决了

5. 不能包含或者排除返回列 类似2

6. 不能分组

7. 单表操作稍复杂SQL不好组装

3. 如何解决

1. 没有分页

PageHelper太重不考虑,定义BaseExampe类并给予分页属性,重新定义XXXMapper.xml文件生成逻辑,selectByExampe后添加 limit参数

2.数据查询不能指定返回的列只能全部返回(select *)

和1同理,在BaseExample添加列集合,将列集合传到XXXMapper.xml生成逻辑

3. 没有非空判断,andXXXEquals(xxx)当xxx为null时运行报空指针判断,这里我想xxx为null时自动跳过,条件不生效

重新定义Example的生产逻辑,添加createCriteriaInternal(boolean skillNull) 方法,当skillNull为true值为null时 addCondition 跳过

4. 多次生成文件重合  1.3.7版好像解决了

使用1.3.7以上版本

5. 不能包含或者排除返回列 类似2

BaseExample添加setIncludeColumns(String... columns)或者setExcludeColumns(String... columns)方法

6. 不能分组

BaseExample定义分组信息

7. 单表操作稍复杂SQL不好组装

修改XXXExample生成逻辑,添加addCriterion(String condition)方法

4. 其他问题

1. 为什么不使用PageHelper分页

PageHelper太全、想的太多以致于太重,一个分页功能不至于。PageHelper主要还是屏蔽了查询count的操作,开发人员只用查list就行,count自动带入。

让开发者无感知获取count其实不用大费周章。只需将查询list时自动查询count逻辑带入即可

    /**

* 分页查询

*

* @param baseExample 查询Example

* @param baseMapper 查询Mapper

* @param <Model> 返回实体

* @param <Example> 查询实体

*/

public static <PK, Model extends BaseModel<PK>, Example extends BaseExample> Page<Model> selectByPage(Example baseExample, BaseMapper<Model, Example, PK> baseMapper) {

checkCurrentPageAndPageSize(baseExample);

BiFunction<Example, BaseMapper<Model, Example, PK>, Page<Model>> biFunction = (example, mapper) -> {

Long count = mapper.countByExampleSelective(example);

if (count == 0) {

return emptyPage(example);

}

List<Model> list;

list = mapper.selectByExampleSelective(example);

Page<Model> page = new Page<>();

page.setCurrentPage(example.getCurrentPage());

page.setPageSize(example.getPageSize());

page.setData(list);

page.setTotalRow(count);

return page;

};

return biFunction.apply(baseExample, baseMapper);

}

2. 如何定制Example、Mapper、XMl生成逻辑

网上教程很多,这里不做详细讲解。这里贴出实例DEMO源码以供参考

  1. BaseExample

@Data

public abstract class BaseExample {

/**

* 当前页

*/

private int currentPage;

/**

* 分页大小

*/

private int pageSize;

/**

* 分页起始位置

*/

private Integer start;

/**

* 查询返回列

*/

private List<String> columns;

/**

* 分组列

*/

private List<String> groups;

/**

* 分组条件

*/

private String having;

/**

* 计算分页起始位置

*/

private void configStart() {

if (currentPage == 0 || pageSize == 0) {

return;

}

int result = currentPage - 1 > 0 ? currentPage - 1 : 0;

this.start = result * pageSize;

}

public abstract List<String> getColumnList();

public void setIncludeColumns(String... columns) {

if (Objects.nonNull(columns)) {

List<String> collect = Arrays.stream(columns).filter(this::isNotEmpty).collect(Collectors.toList());

setColumns(collect);

}

}

public void setOrderByClause(String orderByClause) {

}

private boolean equalsDate(String field) {

if (StringUtils.equals(ModelConst.CREATE_DATE, field)) {

return true;

}

return StringUtils.equals(ModelConst.EDIT_DATE, field);

}

private boolean equalsId(String field) {

return StringUtils.equals(ModelConst.ID, field);

}

private boolean equalsIdAndDate(String field) {

if (StringUtils.equals(ModelConst.CREATE_DATE, field)) {

return true;

}

if (StringUtils.equals(ModelConst.EDIT_DATE, field)) {

return true;

}

return StringUtils.equals(ModelConst.ID, field);

}

public void setExcludeColumns(String... excludeCols) {

List<String> columnList = getColumnList();

CollectionUtils.remove(columnList, excludeCols);

setColumns(columnList);

}

public void excludeDateColumn() {

excludeDateColumn(new String[]{});

}

public void excludeDateColumn(String... excludeCols) {

List<String> columnList = getColumnList();

List<String> collect = columnList.stream().filter(item -> !equalsDate(item)).collect(Collectors.toList());

CollectionUtils.remove(collect, excludeCols);

setColumns(collect);

}

public void excludeIdColumn() {

excludeIdColumn(new String[]{});

}

public void excludeIdColumn(String... excludeCols) {

List<String> columnList = getColumnList();

List<String> collect = columnList.stream().filter(item -> !equalsId(item)).collect(Collectors.toList());

CollectionUtils.remove(collect, excludeCols);

setColumns(collect);

}

public void excludeIdAndDateColumn() {

excludeIdAndDateColumn(new String[]{});

}

public void excludeIdAndDateColumn(String... excludeCols) {

List<String> columnList = getColumnList();

List<String> collect = columnList.stream().filter(item -> !equalsIdAndDate(item)).collect(Collectors.toList());

CollectionUtils.remove(collect, excludeCols);

setColumns(collect);

}

public void setGroups(String... groups) {

if (Objects.nonNull(groups)) {

List<String> collect = Arrays.stream(groups).collect(Collectors.toList());

setGroups(collect);

}

}

/**

* 获取时候计算起始位置

*/

public Integer getStart() {

configStart();

return start;

}

public List<String> getColumns() {

return columns;

}

public void setColumns(List<String> columns) {

this.columns = columns;

}

public List<String> getGroups() {

return groups;

}

public void setGroups(List<String> groups) {

this.groups = groups;

}

private boolean isNotEmpty(String string) {

if (Objects.isNull(string)) {

return false;

}

return string.length() > 0;

}

  1. BaseMapper.java

public interface BaseMapper<Model extends BaseModel<T>, ModelExample extends BaseExample, T> {

/**

* 根据Example查询总共条数

*

* @param example Example

* @return 总条数

*/

long countByExampleSelective(ModelExample example);

/**

* 根据Example删除记录

*

* @param example Example

* @return 被删除的记录条数

*/

int deleteByExample(ModelExample example);

/**

* 根据主键删除记录

*

* @param id 主键

* @return 被删除的记录条数

*/

int deleteByPrimaryKey(T id);

/**

* 添加实体

*

* @param record 实体

* @return 被添加的记录条数

*/

int insert(Model record);

/**

* 添加实体(排除控制)

*

* @param record 实体

* @return 被添加的记录条数

*/

int insertSelective(Model record);

/**

* 根据Example查询

*

* @param example Example

* @return 符合条件的实体集合

*/

List<Model> selectByExampleSelective(ModelExample example);

/**

* 根据主键返回记录

*

* @param id 主键

* @param columns 实体列

* @return 实体

*/

Model selectByPrimaryKey(@Param("id") T id, @Param("columns") List<String> columns);

/**

* 根据Example修改实体(排除空)

*

* @param record 实体

* @param example Example

* @return 被修改的记录条数

*/

int updateByExampleSelective(@Param("record") Model record, @Param("example") ModelExample example);

/**

* 根据Example修改实体

*

* @param record 实体

* @param example Example

* @return 被修改的记录条数

*/

int updateByExample(@Param("record") Model record, @Param("example") ModelExample example);

/**

* 根据实体主键修改(排除空)

*

* @param record 实体

* @return 被修改的记录条数

*/

int updateByPrimaryKeySelective(Model record);

/**

* 根据实体主键修改

*

* @param record 实体

* @return 被修改的记录条数

*/

int updateByPrimaryKey(Model record);

/**

* 批量插入(排除空)

*

* @param records 实体集合

* @return 被添加的记录数

*/

int insertBatchSelective(List<Model> records);

/**

* 批量修改(排除空)

*

* @param records 实体集合

* @return 被修改的记录数

*/

int updateBatchByPrimaryKeySelective(List<Model> records);

}

  1. XXXMapper.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.xxx.mapper.UserMapper">

<resultMap id="BaseResultMap" type="com.xxx.dal.model.User">

<id column="id" jdbcType="INTEGER" property="id"/>

<result column="user_name" jdbcType="VARCHAR" property="userName"/>

<result column="user_type" jdbcType="INTEGER" property="userType"/>

<result column="user_code" jdbcType="VARCHAR" property="userCode"/>

<result column="gmt_create" jdbcType="TIMESTAMP" property="gmtCreate"/>

<result column="gmt_modified" jdbcType="TIMESTAMP" property="gmtModified"/>

<result column="creator" jdbcType="VARCHAR" property="creator"/>

<result column="editor" jdbcType="VARCHAR" property="editor"/>

<result column="gs_id" jdbcType="INTEGER" property="gsId"/>

<result column="nick_name" jdbcType="VARCHAR" property="nickName"/>

<result column="status" jdbcType="INTEGER" property="status"/>

<result column="sca_id" jdbcType="INTEGER" property="scaId"/>

<result column="sca_name" jdbcType="VARCHAR" property="scaName"/>

<result column="job_number_type" jdbcType="INTEGER" property="jobNumberType"/>

<result column="settle_object_id" jdbcType="BIGINT" property="settleObjectId"/>

<result column="settle_object_name" jdbcType="VARCHAR" property="settleObjectName"/>

<result column="open_account_flag" jdbcType="INTEGER" property="openAccountFlag"/>

<result column="ic_flag" jdbcType="INTEGER" property="icFlag"/>

<result column="payment_mode_id" jdbcType="INTEGER" property="paymentModeId"/>

<result column="payment_cycle_id" jdbcType="INTEGER" property="paymentCycleId"/>

</resultMap>

<sql id="Example_Where_Clause">

<where>

<foreach collection="oredCriteria" item="criteria" separator="or">

<if test="criteria.valid">

<trim prefix="(" prefixOverrides="and" suffix=")">

<foreach collection="criteria.criteria" item="criterion">

<choose>

<when test="criterion.noValue">

and ${criterion.condition}

</when>

<when test="criterion.singleValue">

and ${criterion.condition} #{criterion.value}

</when>

<when test="criterion.betweenValue">

and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}

</when>

<when test="criterion.listValue">

and ${criterion.condition}

<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">

#{listItem}

</foreach>

</when>

</choose>

</foreach>

</trim>

</if>

</foreach>

</where>

</sql>

<sql id="Update_By_Example_Where_Clause">

<where>

<foreach collection="example.oredCriteria" item="criteria" separator="or">

<if test="criteria.valid">

<trim prefix="(" prefixOverrides="and" suffix=")">

<foreach collection="criteria.criteria" item="criterion">

<choose>

<when test="criterion.noValue">

and ${criterion.condition}

</when>

<when test="criterion.singleValue">

and ${criterion.condition} #{criterion.value}

</when>

<when test="criterion.betweenValue">

and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}

</when>

<when test="criterion.listValue">

and ${criterion.condition}

<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">

#{listItem}

</foreach>

</when>

</choose>

</foreach>

</trim>

</if>

</foreach>

</where>

</sql>

<sql id="Base_Column_List">

id, user_name, user_type, user_code, gmt_create, gmt_modified, creator, editor, gs_id,

nick_name, status, sca_id, sca_name, job_number_type, settle_object_id, settle_object_name,

open_account_flag, ic_flag, payment_mode_id, payment_cycle_id

</sql>

<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">

delete from yh_user

where id = #{id,jdbcType=INTEGER}

</delete>

<delete id="deleteByExample" parameterType="com.xxx.example.UserExample">

delete from yh_user

<if test="_parameter != null">

<include refid="Example_Where_Clause" />

</if>

</delete>

<insert id="insert" parameterType="com.xxx.dal.model.User">

insert into yh_user (id, user_name, user_type,

user_code, gmt_create, gmt_modified,

creator, editor, gs_id,

nick_name, status, sca_id,

sca_name, job_number_type, settle_object_id,

settle_object_name, open_account_flag, ic_flag,

payment_mode_id, payment_cycle_id)

values (#{id,jdbcType=INTEGER}, #{userName,jdbcType=VARCHAR}, #{userType,jdbcType=INTEGER},

#{userCode,jdbcType=VARCHAR}, #{gmtCreate,jdbcType=TIMESTAMP}, #{gmtModified,jdbcType=TIMESTAMP},

#{creator,jdbcType=VARCHAR}, #{editor,jdbcType=VARCHAR}, #{gsId,jdbcType=INTEGER},

#{nickName,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, #{scaId,jdbcType=INTEGER},

#{scaName,jdbcType=VARCHAR}, #{jobNumberType,jdbcType=INTEGER}, #{settleObjectId,jdbcType=BIGINT},

#{settleObjectName,jdbcType=VARCHAR}, #{openAccountFlag,jdbcType=INTEGER}, #{icFlag,jdbcType=INTEGER},

#{paymentModeId,jdbcType=INTEGER}, #{paymentCycleId,jdbcType=INTEGER})

</insert>

<insert id="insertSelective" parameterType="com.xxx.dal.model.User">

insert into yh_user

<trim prefix="(" suffix=")" suffixOverrides=",">

<if test="id != null">

id,

</if>

<if test="userName != null">

user_name,

</if>

<if test="userType != null">

user_type,

</if>

<if test="userCode != null">

user_code,

</if>

<if test="gmtCreate != null">

gmt_create,

</if>

<if test="gmtModified != null">

gmt_modified,

</if>

<if test="creator != null">

creator,

</if>

<if test="editor != null">

editor,

</if>

<if test="gsId != null">

gs_id,

</if>

<if test="nickName != null">

nick_name,

</if>

<if test="status != null">

status,

</if>

<if test="scaId != null">

sca_id,

</if>

<if test="scaName != null">

sca_name,

</if>

<if test="jobNumberType != null">

job_number_type,

</if>

<if test="settleObjectId != null">

settle_object_id,

</if>

<if test="settleObjectName != null">

settle_object_name,

</if>

<if test="openAccountFlag != null">

open_account_flag,

</if>

<if test="icFlag != null">

ic_flag,

</if>

<if test="paymentModeId != null">

payment_mode_id,

</if>

<if test="paymentCycleId != null">

payment_cycle_id,

</if>

</trim>

<trim prefix="values (" suffix=")" suffixOverrides=",">

<if test="id != null">

#{id,jdbcType=INTEGER},

</if>

<if test="userName != null">

#{userName,jdbcType=VARCHAR},

</if>

<if test="userType != null">

#{userType,jdbcType=INTEGER},

</if>

<if test="userCode != null">

#{userCode,jdbcType=VARCHAR},

</if>

<if test="gmtCreate != null">

#{gmtCreate,jdbcType=TIMESTAMP},

</if>

<if test="gmtModified != null">

#{gmtModified,jdbcType=TIMESTAMP},

</if>

<if test="creator != null">

#{creator,jdbcType=VARCHAR},

</if>

<if test="editor != null">

#{editor,jdbcType=VARCHAR},

</if>

<if test="gsId != null">

#{gsId,jdbcType=INTEGER},

</if>

<if test="nickName != null">

#{nickName,jdbcType=VARCHAR},

</if>

<if test="status != null">

#{status,jdbcType=INTEGER},

</if>

<if test="scaId != null">

#{scaId,jdbcType=INTEGER},

</if>

<if test="scaName != null">

#{scaName,jdbcType=VARCHAR},

</if>

<if test="jobNumberType != null">

#{jobNumberType,jdbcType=INTEGER},

</if>

<if test="settleObjectId != null">

#{settleObjectId,jdbcType=BIGINT},

</if>

<if test="settleObjectName != null">

#{settleObjectName,jdbcType=VARCHAR},

</if>

<if test="openAccountFlag != null">

#{openAccountFlag,jdbcType=INTEGER},

</if>

<if test="icFlag != null">

#{icFlag,jdbcType=INTEGER},

</if>

<if test="paymentModeId != null">

#{paymentModeId,jdbcType=INTEGER},

</if>

<if test="paymentCycleId != null">

#{paymentCycleId,jdbcType=INTEGER},

</if>

</trim>

</insert>

<update id="updateByExampleSelective" parameterType="map">

update yh_user

<set>

<if test="record.id != null">

id = #{record.id,jdbcType=INTEGER},

</if>

<if test="record.userName != null">

user_name = #{record.userName,jdbcType=VARCHAR},

</if>

<if test="record.userType != null">

user_type = #{record.userType,jdbcType=INTEGER},

</if>

<if test="record.userCode != null">

user_code = #{record.userCode,jdbcType=VARCHAR},

</if>

<if test="record.gmtCreate != null">

gmt_create = #{record.gmtCreate,jdbcType=TIMESTAMP},

</if>

<if test="record.gmtModified != null">

gmt_modified = #{record.gmtModified,jdbcType=TIMESTAMP},

</if>

<if test="record.creator != null">

creator = #{record.creator,jdbcType=VARCHAR},

</if>

<if test="record.editor != null">

editor = #{record.editor,jdbcType=VARCHAR},

</if>

<if test="record.gsId != null">

gs_id = #{record.gsId,jdbcType=INTEGER},

</if>

<if test="record.nickName != null">

nick_name = #{record.nickName,jdbcType=VARCHAR},

</if>

<if test="record.status != null">

status = #{record.status,jdbcType=INTEGER},

</if>

<if test="record.scaId != null">

sca_id = #{record.scaId,jdbcType=INTEGER},

</if>

<if test="record.scaName != null">

sca_name = #{record.scaName,jdbcType=VARCHAR},

</if>

<if test="record.jobNumberType != null">

job_number_type = #{record.jobNumberType,jdbcType=INTEGER},

</if>

<if test="record.settleObjectId != null">

settle_object_id = #{record.settleObjectId,jdbcType=BIGINT},

</if>

<if test="record.settleObjectName != null">

settle_object_name = #{record.settleObjectName,jdbcType=VARCHAR},

</if>

<if test="record.openAccountFlag != null">

open_account_flag = #{record.openAccountFlag,jdbcType=INTEGER},

</if>

<if test="record.icFlag != null">

ic_flag = #{record.icFlag,jdbcType=INTEGER},

</if>

<if test="record.paymentModeId != null">

payment_mode_id = #{record.paymentModeId,jdbcType=INTEGER},

</if>

<if test="record.paymentCycleId != null">

payment_cycle_id = #{record.paymentCycleId,jdbcType=INTEGER},

</if>

</set>

<if test="_parameter != null">

<include refid="Update_By_Example_Where_Clause" />

</if>

</update>

<update id="updateByExample" parameterType="map">

update yh_user

set id = #{record.id,jdbcType=INTEGER},

user_name = #{record.userName,jdbcType=VARCHAR},

user_type = #{record.userType,jdbcType=INTEGER},

user_code = #{record.userCode,jdbcType=VARCHAR},

gmt_create = #{record.gmtCreate,jdbcType=TIMESTAMP},

gmt_modified = #{record.gmtModified,jdbcType=TIMESTAMP},

creator = #{record.creator,jdbcType=VARCHAR},

editor = #{record.editor,jdbcType=VARCHAR},

gs_id = #{record.gsId,jdbcType=INTEGER},

nick_name = #{record.nickName,jdbcType=VARCHAR},

status = #{record.status,jdbcType=INTEGER},

sca_id = #{record.scaId,jdbcType=INTEGER},

sca_name = #{record.scaName,jdbcType=VARCHAR},

job_number_type = #{record.jobNumberType,jdbcType=INTEGER},

settle_object_id = #{record.settleObjectId,jdbcType=BIGINT},

settle_object_name = #{record.settleObjectName,jdbcType=VARCHAR},

open_account_flag = #{record.openAccountFlag,jdbcType=INTEGER},

ic_flag = #{record.icFlag,jdbcType=INTEGER},

payment_mode_id = #{record.paymentModeId,jdbcType=INTEGER},

payment_cycle_id = #{record.paymentCycleId,jdbcType=INTEGER}

<if test="_parameter != null">

<include refid="Update_By_Example_Where_Clause" />

</if>

</update>

<update id="updateByPrimaryKeySelective" parameterType="com.xxx.dal.model.User">

update yh_user

<set>

<if test="userName != null">

user_name = #{userName,jdbcType=VARCHAR},

</if>

<if test="userType != null">

user_type = #{userType,jdbcType=INTEGER},

</if>

<if test="userCode != null">

user_code = #{userCode,jdbcType=VARCHAR},

</if>

<if test="gmtCreate != null">

gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},

</if>

<if test="gmtModified != null">

gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},

</if>

<if test="creator != null">

creator = #{creator,jdbcType=VARCHAR},

</if>

<if test="editor != null">

editor = #{editor,jdbcType=VARCHAR},

</if>

<if test="gsId != null">

gs_id = #{gsId,jdbcType=INTEGER},

</if>

<if test="nickName != null">

nick_name = #{nickName,jdbcType=VARCHAR},

</if>

<if test="status != null">

status = #{status,jdbcType=INTEGER},

</if>

<if test="scaId != null">

sca_id = #{scaId,jdbcType=INTEGER},

</if>

<if test="scaName != null">

sca_name = #{scaName,jdbcType=VARCHAR},

</if>

<if test="jobNumberType != null">

job_number_type = #{jobNumberType,jdbcType=INTEGER},

</if>

<if test="settleObjectId != null">

settle_object_id = #{settleObjectId,jdbcType=BIGINT},

</if>

<if test="settleObjectName != null">

settle_object_name = #{settleObjectName,jdbcType=VARCHAR},

</if>

<if test="openAccountFlag != null">

open_account_flag = #{openAccountFlag,jdbcType=INTEGER},

</if>

<if test="icFlag != null">

ic_flag = #{icFlag,jdbcType=INTEGER},

</if>

<if test="paymentModeId != null">

payment_mode_id = #{paymentModeId,jdbcType=INTEGER},

</if>

<if test="paymentCycleId != null">

payment_cycle_id = #{paymentCycleId,jdbcType=INTEGER},

</if>

</set>

where id = #{id,jdbcType=INTEGER}

</update>

<update id="updateByPrimaryKey" parameterType="com.xxx.dal.model.User">

update yh_user

set user_name = #{userName,jdbcType=VARCHAR},

user_type = #{userType,jdbcType=INTEGER},

user_code = #{userCode,jdbcType=VARCHAR},

gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},

gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},

creator = #{creator,jdbcType=VARCHAR},

editor = #{editor,jdbcType=VARCHAR},

gs_id = #{gsId,jdbcType=INTEGER},

nick_name = #{nickName,jdbcType=VARCHAR},

status = #{status,jdbcType=INTEGER},

sca_id = #{scaId,jdbcType=INTEGER},

sca_name = #{scaName,jdbcType=VARCHAR},

job_number_type = #{jobNumberType,jdbcType=INTEGER},

settle_object_id = #{settleObjectId,jdbcType=BIGINT},

settle_object_name = #{settleObjectName,jdbcType=VARCHAR},

open_account_flag = #{openAccountFlag,jdbcType=INTEGER},

ic_flag = #{icFlag,jdbcType=INTEGER},

payment_mode_id = #{paymentModeId,jdbcType=INTEGER},

payment_cycle_id = #{paymentCycleId,jdbcType=INTEGER}

where id = #{id,jdbcType=INTEGER}

</update>

<select id="selectByExampleSelective" parameterType="com.xxx.example.UserExample"

resultMap="BaseResultMap">

select

<choose>

<when test="columns==null or columns.size()==0">

<include refid="Base_Column_List"/>

</when>

<otherwise>

<foreach collection="columns" item="column" separator=",">

${column}

</foreach>

</otherwise>

</choose>

from yh_user

<if test="_parameter != null">

<include refid="Example_Where_Clause"/>

</if>

<if test="groups !=null and groups.size()>0">

group by

<foreach collection="groups" index="index" item="item" separator=",">

${item}

</foreach>

<if test="having != null">

having ${having}

</if>

</if>

<if test="orderByClause != null">

order by ${orderByClause}

</if>

<if test="start != null and start > -1">

limit ${start},${pageSize}

</if>

</select>

<select id="countByExampleSelective" parameterType="com.xxx.example.UserExample"

resultType="java.lang.Long">

select count(*) from ( select

<choose>

<when test="columns==null or columns.size()==0">

<include refid="Base_Column_List"/>

</when>

<otherwise>

<foreach collection="columns" item="column" separator=",">

${column}

</foreach>

</otherwise>

</choose>

from yh_user

<if test="_parameter != null">

<include refid="Example_Where_Clause"/>

</if>

<if test="groups !=null and groups.size()>0">

group by

<foreach collection="groups" index="index" item="item" separator=",">

${item}

</foreach>

<if test="having != null">

having ${having}

</if>

</if>

) Temp

</select>

<insert id="insertBatchSelective" parameterType="java.util.List">

insert into yh_user

<trim prefix="(" suffix=")" suffixOverrides=",">

<if test="list[0].id!=null">

id,

</if>

<if test="list[0].userName!=null">

user_name,

</if>

<if test="list[0].userType!=null">

user_type,

</if>

<if test="list[0].userCode!=null">

user_code,

</if>

<if test="list[0].gmtCreate!=null">

gmt_create,

</if>

<if test="list[0].gmtModified!=null">

gmt_modified,

</if>

<if test="list[0].creator!=null">

creator,

</if>

<if test="list[0].editor!=null">

editor,

</if>

<if test="list[0].gsId!=null">

gs_id,

</if>

<if test="list[0].nickName!=null">

nick_name,

</if>

<if test="list[0].status!=null">

status,

</if>

<if test="list[0].scaId!=null">

sca_id,

</if>

<if test="list[0].scaName!=null">

sca_name,

</if>

<if test="list[0].jobNumberType!=null">

job_number_type,

</if>

<if test="list[0].settleObjectId!=null">

settle_object_id,

</if>

<if test="list[0].settleObjectName!=null">

settle_object_name,

</if>

<if test="list[0].openAccountFlag!=null">

open_account_flag,

</if>

<if test="list[0].icFlag!=null">

ic_flag,

</if>

<if test="list[0].paymentModeId!=null">

payment_mode_id,

</if>

<if test="list[0].paymentCycleId!=null">

payment_cycle_id,

</if>

</trim>

values

<foreach collection="list" index="index" item="item" separator=",">

<trim prefix=" (" suffix=")" suffixOverrides=",">

<if test="item.id!=null">

#{item.id,jdbcType=INTEGER},

</if>

<if test="item.userName!=null">

#{item.userName,jdbcType=VARCHAR},

</if>

<if test="item.userType!=null">

#{item.userType,jdbcType=INTEGER},

</if>

<if test="item.userCode!=null">

#{item.userCode,jdbcType=VARCHAR},

</if>

<if test="item.gmtCreate!=null">

#{item.gmtCreate,jdbcType=TIMESTAMP},

</if>

<if test="item.gmtModified!=null">

#{item.gmtModified,jdbcType=TIMESTAMP},

</if>

<if test="item.creator!=null">

#{item.creator,jdbcType=VARCHAR},

</if>

<if test="item.editor!=null">

#{item.editor,jdbcType=VARCHAR},

</if>

<if test="item.gsId!=null">

#{item.gsId,jdbcType=INTEGER},

</if>

<if test="item.nickName!=null">

#{item.nickName,jdbcType=VARCHAR},

</if>

<if test="item.status!=null">

#{item.status,jdbcType=INTEGER},

</if>

<if test="item.scaId!=null">

#{item.scaId,jdbcType=INTEGER},

</if>

<if test="item.scaName!=null">

#{item.scaName,jdbcType=VARCHAR},

</if>

<if test="item.jobNumberType!=null">

#{item.jobNumberType,jdbcType=INTEGER},

</if>

<if test="item.settleObjectId!=null">

#{item.settleObjectId,jdbcType=BIGINT},

</if>

<if test="item.settleObjectName!=null">

#{item.settleObjectName,jdbcType=VARCHAR},

</if>

<if test="item.openAccountFlag!=null">

#{item.openAccountFlag,jdbcType=INTEGER},

</if>

<if test="item.icFlag!=null">

#{item.icFlag,jdbcType=INTEGER},

</if>

<if test="item.paymentModeId!=null">

#{item.paymentModeId,jdbcType=INTEGER},

</if>

<if test="item.paymentCycleId!=null">

#{item.paymentCycleId,jdbcType=INTEGER},

</if>

</trim>

</foreach>

</insert>

<update id="updateBatchByPrimaryKeySelective" parameterType="java.util.List">

<foreach collection="list" index="index" item="item" separator=";">

update yh_user

<set>

<if test="item.userName!=null">

user_name=#{item.userName,jdbcType=VARCHAR},

</if>

<if test="item.userType!=null">

user_type=#{item.userType,jdbcType=INTEGER},

</if>

<if test="item.userCode!=null">

user_code=#{item.userCode,jdbcType=VARCHAR},

</if>

<if test="item.gmtCreate!=null">

gmt_create=#{item.gmtCreate,jdbcType=TIMESTAMP},

</if>

<if test="item.gmtModified!=null">

gmt_modified=#{item.gmtModified,jdbcType=TIMESTAMP},

</if>

<if test="item.creator!=null">

creator=#{item.creator,jdbcType=VARCHAR},

</if>

<if test="item.editor!=null">

editor=#{item.editor,jdbcType=VARCHAR},

</if>

<if test="item.gsId!=null">

gs_id=#{item.gsId,jdbcType=INTEGER},

</if>

<if test="item.nickName!=null">

nick_name=#{item.nickName,jdbcType=VARCHAR},

</if>

<if test="item.status!=null">

status=#{item.status,jdbcType=INTEGER},

</if>

<if test="item.scaId!=null">

sca_id=#{item.scaId,jdbcType=INTEGER},

</if>

<if test="item.scaName!=null">

sca_name=#{item.scaName,jdbcType=VARCHAR},

</if>

<if test="item.jobNumberType!=null">

job_number_type=#{item.jobNumberType,jdbcType=INTEGER},

</if>

<if test="item.settleObjectId!=null">

settle_object_id=#{item.settleObjectId,jdbcType=BIGINT},

</if>

<if test="item.settleObjectName!=null">

settle_object_name=#{item.settleObjectName,jdbcType=VARCHAR},

</if>

<if test="item.openAccountFlag!=null">

open_account_flag=#{item.openAccountFlag,jdbcType=INTEGER},

</if>

<if test="item.icFlag!=null">

ic_flag=#{item.icFlag,jdbcType=INTEGER},

</if>

<if test="item.paymentModeId!=null">

payment_mode_id=#{item.paymentModeId,jdbcType=INTEGER},

</if>

<if test="item.paymentCycleId!=null">

payment_cycle_id=#{item.paymentCycleId,jdbcType=INTEGER},

</if>

</set>

where

id = #{item.id,jdbcType=INTEGER}

</foreach>

</update>

<select id="selectByPrimaryKey" parameterType="java.util.Map" resultMap="BaseResultMap">

select

<choose>

<when test="columns==null or columns.size()==0">

<include refid="Base_Column_List"/>

</when>

<otherwise>

<foreach collection="columns" item="column" separator=",">

${column}

</foreach>

</otherwise>

</choose>

from yh_user

where id = #{id,jdbcType=INTEGER}

</select>

</mapper>

  1. 下次讲解如何定制生成逻辑以及开发IDEA插件集成MBG

  2. 有用可赏饭

以上是 我是如何使用MybatisGenerator的 的全部内容, 来源链接: utcz.com/z/515336.html

回到顶部