实体类、Mapper接口、Mapper xml
- 分别生成 AppUser.java、SysUser.java,再抽取baseUser.java修改AppUserMapper.xml定义的方法
tips:代码文件附在文末
二、新增注解
@EqualsAndHashCode(callSuper = true)
@SuperBuilder(toBuilder = true)
注解于继承自某实体类的子类,代替子类的@Builder注解。其中@SuperBuilder注解在父类和子类中都需要,@EqualsAndHashCode注解只需要在子类
@JsonInclude(JsonInclude.Include.NON_NULL)
注解用于任意字段:属性为NUll时不返回到json数据中
@JsonIgnore
注解用于任意字段:忽略返回到json数据中,隐藏属性
@JsonFormat(pattern = “YYYY-MM-dd HH:mm:ss”, timezone = “GMT+8”)
注解用于Date类型的字段:时间格式化
@DateTimeFormat(pattern = “YYYY-MM-dd HH:mm:ss”)
注解用于处理web端提交参数时,时间格式转换的bug
三、注意事项- Mapper接口方法的int返回值,代表当前SQL操作成功的行数生成出来的Mapper接口类,默认没有加@Mapper注解,别忘记自行添加
select 接口
单个出入参采用基础数据类型(java.long.String、java.lang.Integer) 多个出入参采用实体类对象映射
insert update delete 接口
入参与select一样,出参均为 java.lang.Integer类型,其值为当前SQL操作成功的行数四、新增类
baseUser.java
package com.a2j.base;
@Data
@SuperBuilder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
public class baseUser {
private Integer id; // 用户ID
private String phone; // 手机号
private String username; // 用户名
private Integer enable; // 用户开关
// 忽略返回到json数据中,隐藏属性
@JsonIgnore
private String password; // 密码
@JsonIgnore
private String salt; // 盐值
@JsonInclude(JsonInclude.Include.NON_NULL)
private String realName; // 真实姓名
@JsonInclude(JsonInclude.Include.NON_NULL)
private Integer age; // 年龄
@JsonInclude(JsonInclude.Include.NON_NULL)
private Integer gender; // 性别
@JsonInclude(JsonInclude.Include.NON_NULL)
private String email; // 邮箱
@JsonInclude(JsonInclude.Include.NON_NULL)
private String idCard; // 身份证号码
@JsonInclude(JsonInclude.Include.NON_NULL)
private String idCardPic; // 身份证照片
@JsonInclude(JsonInclude.Include.NON_NULL)
private String portrait; // 头像
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonFormat(pattern = "YYYY-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createDate; // 创建时间
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonFormat(pattern = "YYYY-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date lastLoginTime; // 最后登录时间
}
AppUser.java
package com.a2j.beans.user;
@Data
@EqualsAndHashCode(callSuper = true)
@SuperBuilder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
public class AppUser extends baseUser {
@JsonInclude(JsonInclude.Include.NON_NULL)
private String nickName; // 昵称
@JsonInclude(JsonInclude.Include.NON_NULL)
private String qrCode; // 二维码
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonFormat(pattern = "YYYY-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date birthday; // 生日
@JsonInclude(JsonInclude.Include.NON_NULL)
private String androidPullToken; // Android推送token
@JsonInclude(JsonInclude.Include.NON_NULL)
private String iosPullToken; // ios推送token
private Integer state; // 认证状态
@JsonFormat(pattern = "YYYY-MM-dd HH:mm:ss", timezone = "GMT+8")
@JsonInclude(JsonInclude.Include.NON_NULL)
private Date authenticationTime; // 认证时间
@JsonInclude(JsonInclude.Include.NON_NULL)
private Integer authenticationSysId; // 系统用户ID
@JsonInclude(JsonInclude.Include.NON_NULL)
private String authenticationSysName; // 系统用户名称
@JsonInclude(JsonInclude.Include.NON_NULL)
private String registerProvince; // 注册省份
@JsonInclude(JsonInclude.Include.NON_NULL)
private String registerCity; // 注册市级
private Integer registerFrom; // 注册方式 (Android、ios、PC)
}
SysUser.java
package com.a2j.beans.user;
@Data
@EqualsAndHashCode(callSuper = true)
@SuperBuilder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
public class SysUser extends baseUser {
private Integer departmentId; // 所属部门ID
private Integer sysType; // 用户类型(管理、编辑、查看、演示)
// 属性为NUll时不返回到json数据中
@JsonInclude(JsonInclude.Include.NON_NULL)
private String remark; // 备注
@JsonInclude(JsonInclude.Include.NON_NULL)
private String ip; // IP地址
@JsonInclude(JsonInclude.Include.NON_NULL)
private String mac; // Mac地址
}
AppUserMapper.java
package com.a2j.mapper.user;
@Mapper
public interface AppUserMapper {
// 唯一约束(用户名 / 身份证号码):alter table app_user add unique(username / id_card);
// web端注册接口
int register(AppUser record);
// 移动端接口,4个入参3个必传
int register(@Param("map") Map params);
// 移动端登录接口
AppUser login(String username, String password);
// app、web端用户详情接口,同时用于修改密码逻辑查询
AppUser findUserById(Integer userId);
// app用户登录,app、web注册逻辑查询。(实名认证,还需要做身份证号码唯一校验 -> findUserByIdCard())
AppUser findUserByAccount(String account);
// web端用户列表接口
// List allAppUsers(UserRequest request);
// web端用户列表总数接口
// int selectCount(UserRequest request);
// app、web编辑用户接口
int updateUser(AppUser record);
}



