您当前的位置: 首页 >  mongodb

qq_34412985

暂无认证

  • 0浏览

    0关注

    1061博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

web项目整合MongoDb出现No converter found capable of converting from org.bson.types.ObjectId to type Long异常

qq_34412985 发布时间:2019-05-30 17:19:57 ,浏览量:0

Spring、SpringMVC、MyBatis框架整合 MongoDb ,启动web项目时出现异常,项目不能运行,查看原因是出现如下异常: 

with root cause org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type org.bson.types.ObjectId to type java.lang.Long

异常堆栈如下:

org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [springMvcDispatcherServlet] in context with path [/conference] threw exception [Request processing failed; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type org.bson.types.ObjectId to type java.lang.Long] with root cause  org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type org.bson.types.ObjectId to type java.lang.Long 解决方法:

Spring使用MongoDb帮助文档

在MongoDb里要求每个文档都需要有_id 字段,java类中有如下情况会被映射为_id字段

如果1个字段加上了 @Id (org.springframework.data.annotation.Id)注解,那么将bean保存到数据库时就会把该字段映射为文档中的_id字段 如果java对象中没有 @Id 注解,名字为id 的字段将会被映射为文档中的_id字段

 

mongo不止查询时会entity和mongo库中数据映射,插入也会映射项目中insert   list时entity的id为null报错,mongo中存入entity,即属性为_class字段为 com.tk.mer.entity.MerSku

关注
打赏
1653291990
查看更多评论
立即登录/注册

微信扫码登录

0.0469s