通过注解的方式对实体类和数据库进行绑定
实体类和mysql映射
java
@Entity
@Table(name = "t_hoxin_session") //对应数据库表
public class Session{
public static final int STATE_ACTIVE = 0;
public static final int STATE_APNS = 1;
public static final int STATE_INACTIVE = 2;
public static final String CHANNEL_IOS = "ios";
public static final String CHANNEL_ANDROID = "android";
public static final String CHANNEL_WINDOWS = "windows";
public static final String CHANNEL_MAC = "mac";
public static final String CHANNEL_WEB = "web";
/**
* 数据库主键ID
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)//主键生成策略
@Column(name = "id")
private Long id;
/**
* session绑定的用户账号
*/
@Column(name = "uid")
private String uid;
/**
* session在本台服务器上的ID
*/
@Column(name = "nid",length = 32,nullable = false)
private String nid;
/**
* 客户端ID (设备号码+应用包名),ios为deviceToken
*/
@Column(name = "device_id",length = 64,nullable = false)
private String deviceId;
/**
* 终端设备型号
*/
@Column(name = "device_name")
private String deviceName;
/**
* session绑定的服务器IP
*/
@Column(name = "host",length = 15,nullable = false)
private String host;
/**
* 终端设备类型
*/
@Column(name = "channel",length = 10,nullable = false)
private String channel;
/**
* 终端应用版本
*/
@Column(name = "app_version")
private String appVersion;
/**
* 终端系统版本
*/
@Column(name = "os_version")
private String osVersion;
/**
* 终端语言
*/
@Column(name = "language")
private String language;
/**
* 登录时间
*/
@Column(name = "bind_time")
private Long bindTime;
/**
* 经度
*/
@Column(name = "longitude")
private Double longitude;
/**
* 维度
*/
@Column(name = "latitude")
private Double latitude;
/**
* 位置
*/
@Column(name = "location")
private String location;
/**
* 状态
*/
private int state;
/**
get/set省略
*/
}
实体类和mongoDB数据库映射
java
@Document(collection = "accounts")
@JsonIgnoreProperties(ignoreUnknown = true) //忽略类中不存在的字段。
public class Account{
@Id
private String name;
private Date lastSeen;
@Valid
private List<Intem> icomes;
@Valid
private List<Intem> expenses;
@Valid
@NotNull
private Saving saving;
@Length(min = 0,max = 20_000)
private String note;
/**
get/set省略
*/
}
java
public class Item{
@NotNull
@Length(min = 1,max = 20)
private String title;
@NotNull
private BigDecimal amout;
/**
忽略set/get
*/
}
=============================================
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")格式
java
@EqualsAndHashCode(callSuper = true)
@Data
public class ActivityResponse extends BasicResponse {
private static final long serialVersionUID = 8446988225819243294L;
private Long id;
/**
* 活动名称
*/
private String activityName;
/**
* 活动主图
*/
private String activityImg;
/**
* 活动类型
*/
private Integer activityType;
/**
* 活动状态
*/
private Boolean state;
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
private LocalDateTime beginTime;
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
private LocalDateTime endTime;
}
========================================
java
@Data
public class BaseEntity<T> implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 租户id
*/
private Long parkId;
/**
* 创建者
*/
private String createBy;
/**
* 创建时间
* jackson-annotations-2.11.3.jar
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
/**
* 更新者
*/
private String updateBy;
/**
* 更新时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;
/**
* 搜索值
* persistence-api-1.0.jar
*/
@Transient
private String searchValue;
/**
* 开始日期
*/
@Transient
private String beginTime;
/**
* 结束日期
*/
@Transient
private String endTime;
/**
* 请求参数
*/
@Transient
private Map<String, Object> params;
public Map<String, Object> getParams() {
if (params == null) {
params = new HashMap<>();
}
return params;
}
}