使用spring-data-rest针对实体类及Repository生成了restful接口。以便于实体类的增删改查。
实体类:
@NoArgsConstructor
@Data
@EqualsAndHashCode(of = "name")
@Document
public class Type {
@Id
private ObjectId id;
@NonNull
@Indexed(unique = true)
private String name;
private boolean online;
private int Length;
}
Repository:
@Repository
public interface TypeRepository extends MongoRepository<Type, ObjectId> {}
具体接口如下:
增 POST localhost:8080/data/types
查 GET localhost:8080/data/types
增删改查都是没问题的。但是我遇到的问题是:使用POST存储实体类的时候,前端传来的body中,是没有online这一条属性的。而我想让online的默认值是true,请问这个该用什么方式去实现?