Java tutorial
/******************************************************************************* * Copyright (c) 2005, 2014 springside.github.io * * Licensed under the Apache License, Version 2.0 (the "License"); *******************************************************************************/ package com.school.exam.entity; import java.util.Date; import java.util.List; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; import javax.persistence.Transient; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.builder.ToStringBuilder; import org.hibernate.validator.constraints.NotBlank; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonIgnore; import com.google.common.collect.ImmutableList; @Entity @Table(name = "ss_user") public class User extends IdEntity { private String loginName; private String name; private String plainPassword; private String password; private String salt; private String roles; private Date registerDate; private SSClassVO ssClass; // JPA class_id @ManyToOne(fetch = FetchType.EAGER, targetEntity = SSClassVO.class) @JoinColumn(name = "class_id", referencedColumnName = "id") public SSClassVO getSsClass() { return ssClass; } public void setSsClass(SSClassVO ssClass) { this.ssClass = ssClass; } public User() { } public User(Long id) { this.id = id; } @NotBlank public String getLoginName() { return loginName; } public void setLoginName(String loginName) { this.loginName = loginName; } @NotBlank public String getName() { return name; } public void setName(String name) { this.name = name; } // ????Restful?. @Transient @JsonIgnore public String getPlainPassword() { return plainPassword; } public void setPlainPassword(String plainPassword) { this.plainPassword = plainPassword; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getSalt() { return salt; } public void setSalt(String salt) { this.salt = salt; } public String getRoles() { return roles; } public void setRoles(String roles) { this.roles = roles; } @Transient @JsonIgnore public List<String> getRoleList() { // ???List. return ImmutableList.copyOf(StringUtils.split(roles, ",")); } // JSON?? @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00") public Date getRegisterDate() { return registerDate; } public void setRegisterDate(Date registerDate) { this.registerDate = registerDate; } @Override public String toString() { return ToStringBuilder.reflectionToString(this); } }