直接上代码
@PostMapping("/update")
public Object update(@RequestBody URLDTO urldto) throws Exception{
urldto.setName("update");
Query query = new Query();
query.addCriteria(Criteria.where("uid").is(urldto.getUid()));
BasicUpdate update = new BasicUpdate(
JSON.toJSONString(urldto)
);
return mongoTemplate.updateFirst(query, update, GlobalCollectionName.Collection_URL);
}
@PostMapping("/updateSelect")
public Object updateSelect(@RequestBody URLDTO urldto) throws Exception{
urldto.setName("update");
Query query = new Query();
query.addCriteria(Criteria.where("uid").is(urldto.getUid()));
String data=JSON.toJSONString(urldto);
BasicUpdate update = new BasicUpdate(
"{"+"'$set':"+data+"}"
);
return mongoTemplate.updateFirst(query, update, GlobalCollectionName.Collection_URL);
}