0

I want insert a Bean like below into mongodb,I use springboot 2.0.4.RELEASE,I want the a field have a default value such as 100.00,how to do it?

 public class Bean{
    String uid;
    double a;
}
candrwow
  • 511
  • 5
  • 21
  • https://stackoverflow.com/questions/41344173/is-there-any-spring-annotation-to-set-default-value-for-a-field-mongo – Upulie Han Jul 31 '22 at 09:06

1 Answers1

-4

you must annotate your Bean, it is preferred to have id in your collection

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

@Document(collection = "your_collection_name")
public class Bean {

    @Id
    private String id;

    private String uid;
    private double a = 100.00;

    //getter and setter methods
}
clevertension
  • 6,929
  • 3
  • 28
  • 33