【发布时间】:2021-12-27 13:41:56
【问题描述】:
我的第一个 Mongo DB 春季后端遇到了一些问题。我创建了一个具有一些属性的组件类。其中之一是零件号,该零件号应是唯一的。所以我设置了@Indexed (unique = true) 注释。
应用程序运行良好。但是,如果我使用邮递员测试端点,所有属性都将写入 Mongo 文档,但部件号除外。 PN 总是空的。我不明白为什么。如果有人可以帮助我解决他的问题,我会很高兴。
这是组件类
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
import lombok.Data;
@Data
@Document
public class Component {
@Id
private String id;
private String cType;
@Indexed(unique = true)
private String pN;
private String name;
private double diameter;
private double bendradius;
private double maxLenght;
private String modelPath;
private String description;
private String normOrStandard;
}
这是一个对路由 http://localhost:8080/components 的 post 请求示例
{
"PN":"13245"
}
结果:
{
"id": "61c9c23960435c3c0c4d5844",
"name": null,
"diameter": 0.0,
"bendradius": 0.0,
"maxLenght": 0.0,
"modelPath": null,
"description": null,
"normOrStandard": null,
"ctype": null,
"pn": null,
"_links": {
"self": {
"href": "http://localhost:8080/components/61c9c23960435c3c0c4d5844"
},
"components": {
"href": "http://localhost:8080/components"
}
}
}
如果所有字段都已填写,也会发生这种情况。
【问题讨论】: