通过注释【@Id】设置主键,如果不设置主键,mongoDB会自动生成主键。
import org.springframework.data.annotation.Id;
public static class OrderComsumeDTO{
@Id
private String orderNo;
private String JnlNo;
private String dateTime;
public String getOrderNo() {
return orderNo;
}
public void setOrderNo(String orderNo) {
this.orderNo = orderNo;
}
public String getJnlNo() {
return JnlNo;
}
public void setJnlNo(String jnlNo) {
JnlNo = jnlNo;
}
public String getDateTime() {
return dateTime;
}
public void setDateTime(String dateTime) {
this.dateTime = dateTime;
}
}
增/删/查
@Override
public void insert(OrderComsumeDTO obj) {
this.save(obj);
}
@Override
public OrderComsumeDTO selectByPrimaryKey(String id) {
OrderComsumeDTO dto = this.findById(id);
return dto;
}
@Override
public int deleteByPrimaryKey(String id) {
return this.deleteById(id);
}