0
点赞
收藏
分享

微信扫一扫

MongoTemplate更新实体类的最优方法

ITWYY 2023-03-04 阅读 81


直接上代码

@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);
}


举报

相关推荐

0 条评论