@Transient
– 映射忽略的字段,该字段不会保存到mongodb。
Same to mysql
Example
User.java
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "Users")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
private String email;
private String password;
@Transient
private Date loginTime;
}
UserRepository.java
@Repository
public interface UserRepository extends JpaRepository<User, Long> {
}
TestRepository.java
@SpringBootTest
class TestRepository {
@Autowired
UserRepository userRepository;
@Test
public void testTransient() {
User u = new User();
u.setEmail("test@fengcaoculture.com");
userRepository.save(u);
Assert.assertEquals(1, userRepository.findAll().size());
}
}