wget https://github.com/goudai/gd-generator/archive/gd-generator-2.0.3.zip
unzip gd-generator-2.0.3.zip
cd gd-generator-2.0.3
mvn clean install
<dependency>
<groupId>io.goudai</groupId>
<artifactId>gd-generator-api</artifactId>
<version>2.0.3</version>
</dependency>
<dependency>
<groupId>io.goudai</groupId>
<artifactId>gd-generator-default</artifactId>
<version>2.0.3</version>
</dependency>
/* JPA注解 需要解析的实体类必须加此注解*/
@Entity
@Table(name = "usr_user")
/*lombok提供注解*/
@Getter
@Setter
/*此注解表示是否生成查询对象*/
@QueryModel
/*此注解为预留注解 为以后生成页面以及生成excel*/
@Type(label = "用户")
@ViewObject(groups = {VO_LIST, VO_SIMPLE, VO_ADMIN, VO_ADMIN_SIMPLE, VO_ADMIN_FULL},
collectionViews = {
@CollectionView(name = "userUpgrades", elementGroup = UserUpgrade.VO_ADMIN, groups = VO_ADMIN_FULL),
@CollectionView(name = "teammates", elementGroup = VO_ADMIN_SIMPLE, groups = VO_ADMIN_FULL)
},
associationViews = {
@AssociationView(name = "portrait", associationGroup = Portrait.VO_ADMIN, groups = VO_ADMIN_FULL),
@AssociationView(name = "appearance", associationGroup = Appearance.VO_ADMIN, groups = VO_ADMIN_FULL)
}
)
public class User implements Serializable {
/*此处定义的为需要生成的VO的类名称*/
public static final String VO_LIST = "UserListVo";
public static final String VO_SIMPLE = "UserSimpleVo";
public static final String VO_ADMIN = "UserAdminVo";
public static final String VO_ADMIN_SIMPLE = "UserAdminSimpleVo";
public static final String VO_ADMIN_FULL = "UserAdminFullVo";
@Id
@Query(Predicate.IN)
@Field(label = "id")
@View
private Long id;
@Column(length = 11, unique = true)
@NotBlank
@Pattern(regexp = "^1[\\d]{10}$")
@Query(Predicate.EQ)
@Field(label = "手机号")
@View(groups = {VO_LIST, VO_ADMIN, VO_ADMIN_SIMPLE, VO_ADMIN_FULL})
private String phone;
@Column(length = 60)
@Field(label = "密码")
private String password;
@Column(length = 60)
@NotBlank
@Query(Predicate.LK)
@Length(max = 60)
@Field(label = "昵称")
@View
private String nickname;
@NotNull
@Query(Predicate.EQ)
@Field(label = "用户类型")
@View(groups = {VO_ADMIN, VO_ADMIN_SIMPLE, VO_ADMIN_FULL})
private UserType userType;
@NotNull
@Query(Predicate.EQ)
@Field(label = "用户等级")
@View(groups = {VO_LIST, VO_ADMIN, VO_ADMIN_SIMPLE, VO_ADMIN_FULL})
@View(name = "userRankLabel", type = String.class, groups = {VO_ADMIN, VO_ADMIN_SIMPLE, VO_ADMIN_FULL})
private UserRank userRank;
@Column(length = 11)
@Pattern(regexp = "^[\\d]{5,11}$")
@Field(label = "qq")
@View(groups = {VO_ADMIN, VO_ADMIN_FULL})
private String qq;
@NotBlank
@Field(label = "头像")
@View(name = "avatarThumbnail", type = String.class)
@Length(max = 250)
private String avatar;
@NotNull
@Query(Predicate.EQ)
@Field(label = "是否冻结")
@View(groups = {VO_ADMIN, VO_ADMIN_FULL})
private Boolean isFrozen;
@NotNull
@Temporal(TemporalType.TIMESTAMP)
@Query({Predicate.GTE, Predicate.LT})
@Field(label = "注册时间")
@View(groups = {VO_ADMIN, VO_ADMIN_FULL})
private Date registerTime;
@NotNull
@Field(label = "注册ip")
@View(groups = {VO_ADMIN, VO_ADMIN_FULL})
private String registerIp;
@Query({Predicate.EQ, Predicate.IN})
@Field(label = "邀请人id", description = "此用户不是最终上下级关系")
@AssociationView(name = "inviter", associationGroup = VO_ADMIN_SIMPLE, groups = {VO_ADMIN, VO_ADMIN_FULL})
private Long inviterId;
@Query({Predicate.EQ, Predicate.IN})
@Field(label = "上级id")
@AssociationView(name = "parent", associationGroup = VO_ADMIN_SIMPLE, groups = {VO_ADMIN, VO_ADMIN_FULL})
private Long parentId;
@Field(label = "remark")
@View(groups = {VO_ADMIN, VO_ADMIN_FULL})
private String remark;
@Temporal(TemporalType.DATE)
@Field(label = "vipExpiredDate")
private Date vipExpiredDate;
@Column(length = 60, unique = true)
@Field(label = "微信openId")
private String openId;
@Column(length = 60, unique = true)
@Field(label = "微信unionId")
private String unionId;
@Field(label = "上次升级时间")
private Date lastUpgradedTime;
}
<?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.zy.mapper.UserMapper" >
<resultMap id="baseResultMap" type="com.zy.entity.usr.User">
<id column="id" property="id" />
<result column="phone" property="phone" />
<result column="password" property="password" />
<result column="nickname" property="nickname" />
<result column="user_type" property="userType" typeHandler="org.apache.ibatis.type.EnumOrdinalTypeHandler" />
<result column="user_rank" property="userRank" typeHandler="org.apache.ibatis.type.EnumOrdinalTypeHandler" />
<result column="qq" property="qq" />
<result column="avatar" property="avatar" />
<result column="is_frozen" property="isFrozen" />
<result column="register_time" property="registerTime" />
<result column="register_ip" property="registerIp" />
<result column="inviter_id" property="inviterId" />
<result column="parent_id" property="parentId" />
<result column="remark" property="remark" />
<result column="vip_expired_date" property="vipExpiredDate" />
<result column="open_id" property="openId" />
<result column="union_id" property="unionId" />
<result column="last_upgraded_time" property="lastUpgradedTime" />
</resultMap>
<insert id="insert" parameterType="com.zy.entity.usr.User" useGeneratedKeys="true" keyProperty="id">
insert into `usr_user` (phone,password,nickname,user_type,user_rank,qq,avatar,is_frozen,register_time,register_ip,inviter_id,parent_id,remark,vip_expired_date,open_id,union_id,last_upgraded_time)
values (#{phone},#{password},#{nickname},#{userType,typeHandler=org.apache.ibatis.type.EnumOrdinalTypeHandler},#{userRank,typeHandler=org.apache.ibatis.type.EnumOrdinalTypeHandler},#{qq},#{avatar},#{isFrozen},#{registerTime},#{registerIp},#{inviterId},#{parentId},#{remark},#{vipExpiredDate},#{openId},#{unionId},#{lastUpgradedTime})
</insert>
<delete id="delete">
delete from `usr_user` where id = #{id}
</delete>
<update id="update" parameterType="com.zy.entity.usr.User">
update `usr_user`
<set>
phone = #{phone},
password = #{password},
nickname = #{nickname},
user_type = #{userType,typeHandler=org.apache.ibatis.type.EnumOrdinalTypeHandler},
user_rank = #{userRank,typeHandler=org.apache.ibatis.type.EnumOrdinalTypeHandler},
qq = #{qq},
avatar = #{avatar},
is_frozen = #{isFrozen},
register_time = #{registerTime},
register_ip = #{registerIp},
inviter_id = #{inviterId},
parent_id = #{parentId},
remark = #{remark},
vip_expired_date = #{vipExpiredDate},
open_id = #{openId},
union_id = #{unionId},
last_upgraded_time = #{lastUpgradedTime},
</set>
where id = #{id}
</update>
<update id="merge">
update `usr_user`
<set>
<foreach collection="fields" item="field">
<choose>
<when test="field == 'phone'">phone = #{user.phone},</when>
<when test="field == 'password'">password = #{user.password},</when>
<when test="field == 'nickname'">nickname = #{user.nickname},</when>
<when test="field == 'userType'">user_type = #{user.userType,typeHandler=org.apache.ibatis.type.EnumOrdinalTypeHandler,javaType=com.zy.entity.usr.User$UserType},</when>
<when test="field == 'userRank'">user_rank = #{user.userRank,typeHandler=org.apache.ibatis.type.EnumOrdinalTypeHandler,javaType=com.zy.entity.usr.User$UserRank},</when>
<when test="field == 'qq'">qq = #{user.qq},</when>
<when test="field == 'avatar'">avatar = #{user.avatar},</when>
<when test="field == 'isFrozen'">is_frozen = #{user.isFrozen},</when>
<when test="field == 'registerTime'">register_time = #{user.registerTime},</when>
<when test="field == 'registerIp'">register_ip = #{user.registerIp},</when>
<when test="field == 'inviterId'">inviter_id = #{user.inviterId},</when>
<when test="field == 'parentId'">parent_id = #{user.parentId},</when>
<when test="field == 'remark'">remark = #{user.remark},</when>
<when test="field == 'vipExpiredDate'">vip_expired_date = #{user.vipExpiredDate},</when>
<when test="field == 'openId'">open_id = #{user.openId},</when>
<when test="field == 'unionId'">union_id = #{user.unionId},</when>
<when test="field == 'lastUpgradedTime'">last_upgraded_time = #{user.lastUpgradedTime},</when>
</choose>
</foreach>
</set>
where id = #{user.id}
</update>
<select id="findOne" resultMap="baseResultMap" parameterType="long">
select
id,phone,password,nickname,user_type,user_rank,qq,avatar,is_frozen,register_time,register_ip,inviter_id,parent_id,remark,vip_expired_date,open_id,union_id,last_upgraded_time
from `usr_user`
where id = #{id}
</select>
<select id="findAll" resultMap="baseResultMap" parameterType="com.zy.model.query.UserQueryModel">
select
id,phone,password,nickname,user_type,user_rank,qq,avatar,is_frozen,register_time,register_ip,inviter_id,parent_id,remark,vip_expired_date,open_id,union_id,last_upgraded_time
from `usr_user`
<where>
<if test="userRankEQ != null">
and user_rank = #{userRankEQ,typeHandler=org.apache.ibatis.type.EnumOrdinalTypeHandler}
</if>
<if test="nicknameLK != null">
<bind name="nicknameLK" value="'%' + nicknameLK + '%'"/> and nickname like #{nicknameLK}
</if>
<if test="inviterIdEQ != null">
and inviter_id = #{inviterIdEQ}
</if>
<if test="parentIdIN != null">
<if test="parentIdIN.length != 0">
and parent_id in
<foreach collection="parentIdIN" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="parentIdIN.length == 0">
1 = 2
</if>
</if>
<if test="isFrozenEQ != null">
and is_frozen = #{isFrozenEQ}
</if>
<if test="idIN != null">
<if test="idIN.length != 0">
and id in
<foreach collection="idIN" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="idIN.length == 0">
and 1 = 2
</if>
</if>
<if test="userTypeEQ != null">
and user_type = #{userTypeEQ,typeHandler=org.apache.ibatis.type.EnumOrdinalTypeHandler}
</if>
<if test="registerTimeGTE != null">
and register_time >= #{registerTimeGTE}
</if>
<if test="registerTimeLT != null">
and register_time < #{registerTimeLT}
</if>
<if test="parentIdEQ != null">
and parent_id = #{parentIdEQ}
</if>
<if test="phoneEQ != null">
and phone = #{phoneEQ}
</if>
<if test="inviterIdIN != null">
<if test="inviterIdIN.length != 0">
and inviter_id in
<foreach collection="inviterIdIN" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="inviterIdIN.length == 0">
1 = 2
</if>
</if>
</where>
<choose>
<when test="orderByAndDirection != null">
order by ${orderByAndDirection}
</when>
<otherwise>
order by id desc
</otherwise>
</choose>
<if test="offset != null">
limit #{offset}, #{pageSize}
</if>
</select>
<select id="count" resultType="_long" parameterType="com.zy.model.query.UserQueryModel">
select count(*) from `usr_user`
<where>
<if test="userRankEQ != null">
and user_rank = #{userRankEQ,typeHandler=org.apache.ibatis.type.EnumOrdinalTypeHandler}
</if>
<if test="nicknameLK != null">
<bind name="nicknameLK" value="'%' + nicknameLK + '%'"/> and nickname like #{nicknameLK}
</if>
<if test="inviterIdEQ != null">
and inviter_id = #{inviterIdEQ}
</if>
<if test="parentIdIN != null">
<if test="parentIdIN.length != 0">
and parent_id in
<foreach collection="parentIdIN" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="parentIdIN.length == 0">
1 = 2
</if>
</if>
<if test="isFrozenEQ != null">
and is_frozen = #{isFrozenEQ}
</if>
<if test="idIN != null">
<if test="idIN.length != 0">
and id in
<foreach collection="idIN" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="idIN.length == 0">
1 = 2
</if>
</if>
<if test="userTypeEQ != null">
and user_type = #{userTypeEQ,typeHandler=org.apache.ibatis.type.EnumOrdinalTypeHandler}
</if>
<if test="registerTimeGTE != null">
and register_time >= #{registerTimeGTE}
</if>
<if test="registerTimeLT != null">
and register_time < #{registerTimeLT}
</if>
<if test="parentIdEQ != null">
and parent_id = #{parentIdEQ}
</if>
<if test="phoneEQ != null">
and phone = #{phoneEQ}
</if>
<if test="inviterIdIN != null">
<if test="inviterIdIN.length != 0">
and inviter_id in
<foreach collection="inviterIdIN" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="inviterIdIN.length == 0">
1 = 2
</if>
</if>
</where>
</select>
<select id="findByPhone" resultMap="baseResultMap">
select * from `usr_user` where phone = #{phone}
</select>
<select id="findByOpenId" resultMap="baseResultMap">
select * from `usr_user` where open_id = #{openId}
</select>
</mapper>