如何使用spring-data-mongodb不将bean属性值保存到mongodb中

时间:2018-02-05 15:23:39

标签: java spring mongodb spring-data-mongodb

我有一个带有getter和setter以及一些属性的简单bean,我想不使用spring-data-mongodb将属性值保存到MongoDB中

示例请求正文:

  class Person
  {
   public Person(){}
   public Person(String a , String b)
   {
    this.accountId = a;
    this.creditCardNo = b; //This should not be saved
    }
      private String accountId;
      @Transient //Spring-data transient
      private transient String creditCardNo; //This should not be saved into db
      /* Getter and Setter methods go here */
     }
       /* After some validations */
     Person p = new Person("xxx","yyy");
       mongoTemplate.save(p); //Saves xxx and yyy BUT xxx must have been saved and yyy is transient should NOT BE SAVED.

班级人员:

{{1}}

0 个答案:

没有答案