Py学习  »  MongoDB

如何使用Springboot设置MongoDB的默认值?

candrwow • 4 年前 • 275 次点击  

我想在MongoDB中插入一个类似于下面的bean,我使用了Springboot2.0.4.release,我想a字段有一个默认值,比如100.00,怎么做?

 public class Bean{
    String uid;
    double a;
}
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/37881
 
275 次点击  
文章 [ 1 ]  |  最新文章 4 年前
clevertension
Reply   •   1 楼
clevertension    5 年前

您必须对bean进行注释,最好在集合中包含id。

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
}