英文:
How to convert string to object in MongoDB with Java
问题
我必须获取现有的 ID 以更新用户信息(例如电子邮件/姓名/密码)。我使用 POJO(普通Java对象)来映射对象 ID。我可以看到一个类似的帖子,但针对的是 .Net。
我该如何在将其传递给构造函数?(抱歉,我对 MongoDB 很新手)
String idString = request.getParameter("id"); // 出现错误:类型不匹配,无法从字符串转换为 ObjectId
ObjectId _id = new ObjectId(idString);
User user = new User(_id, email, fullName, password);
英文:
I have to get the existing id to update user information (e.g. email/name/password). I using POJOs to map the object id. I can see a similar post, but in .Net
How can I do that to pass it to the constructor? (Sorry, I'm very new to MongoDB)
ObjectId _id = request.getParameter("id"); // "erro with Type mismatch: cannot convert from String to ObjectId"
User user = new User(_id, email, fullName, password);
答案1
得分: 1
可以展示一下这个POJO(类),可能是由于您在模型中用于id的类型引起的...我无法告诉您问题是什么,但可以查看一下这个链接,可能会对您有所帮助:https://jira.mongodb.org/browse/JAVA-3677。
英文:
can you show the POJO(class) it might be caused by the type you have user in your model for the id...I'm not able to tell you what is the problem but have a look at this link it might help you <https://jira.mongodb.org/browse/JAVA-3677>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论