直接偷懒使用阿里云的示例
大致方法总结如下:
引入基础库看示例中
model类的声明:
1. 先声明属性
2.初始化方法
3.在声明set/get方法
注意点: 在get方法中有注解符的修饰. 什么约定大于配置, 注意一下变量的大小写和方法中的大小写问题
package com.aliyun.cloudcallcenter.crm.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import com.aliyun.cloudcallcenter.crm.aliyun.TokenPackage;
@Entity
@Table(name = "user")
public class User {
/**
* 用户ID
*/
private Long id;
/**
* 用户名
*/
private String userName;
/**
* 用户密码,明文
*/
private String password;
/**
* 阿里云账户绑定标志
*/
private Boolean isAliyunBound;
/**
* 阿里云账户访问令牌
*/
private TokenPackage tokePackage;
public User() {
}
public User(String userName, String password) {
this.userName = userName;
this.password = password;
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Column(unique = true)
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Transient
public Boolean isAliyunBound() {
return isAliyunBound;
}
public void setAliyunBound(Boolean aliyunBound) {
isAliyunBound = aliyunBound;
}
@Transient
public TokenPackage getTokePackage() {
return tokePackage;
}
public void setTokePackage(TokenPackage tokePackage) {
this.tokePackage = tokePackage;
}
}
@Transient的解释
总结一句话就是被@Transient
修饰的变量将不会被自动序列化到磁盘中,被修饰的变量的生命周期仅限在内存中
网友评论