Transient
In Java, the @Transient annotation is used to indicate that a field should be ignored when an object is serialized or deserialized. This means that the field will not be written to a file or database, and will not be included in any network communication.
The @Transient annotation is often used with the Java Persistence API (JPA) to mark a field as non-persistent. This means that the field will not be saved to the database when the object is persisted, and will not be loaded from the database when the object is retrieved.
Here's an example of using @Transient with JPA:
@Entity
public class Person {
@Id
private Long id;
private String firstName;
private String lastName;
@Transient
private String fullName;
// getters and setters omitted
}
In this example, the fullName field is marked as transient, which means it will not be persisted to the database. Instead, the firstName and lastName fields will be used to construct the full name when needed.
Note that the @Transient annotation can also be used with other serialization frameworks, such as Jackson or Gson, to ignore fields during serialization and deserialization.
原文地址: http://www.cveoy.top/t/topic/GGH 著作权归作者所有。请勿转载和采集!