springboot踩坑笔记二:springboot+mybatis踩坑小结

为什么使用springboot+mybatis?
这个问题感觉没什么提问价值,但是关于“spring的坑”这个话题向来比较沉重,所以咱们先闲谈一下这个问题以缓解气氛。
springboot相比spring的先进之处有很多,比如对第三方插件的强大支持,内嵌式web服务器(tomcat,jetty),提供注解式sql语句简化dao层编码以及自动配置等等一大堆。想想当初的SSM框架要写mybatis-config.xml+springContext.xml+一大坨糟心的mapper.xml,springboot简直就是贴心小棉袄了啊。既然如此为什么还有springboot+mybatis这种东西的存在呢:mapper.xml文件可以通过标签(set where if等)实现动态sql语句,当springboot离开了mybatis的mapper文件就失去了这个便利性(纯属个人杜撰)。闲谈至此,如果你在实际项目中没有动态sql语句的需求,可以跳过以下内容,直接选择springboot框架。
言归正传,下面记录一下我在使用这个框架过程中遇到的几个问题以及解决方案。

一、 在service层使用@Autowired注入dao层bean时,报错找不到我们想要在dao层返回的entity类:
org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method ‘sqlSessionFactory’ threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: ‘file [D:\intellij_workspace\springbootTest\target\classes\mapper\userInfoMapper.xml]’; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is ‘file [D:\intellij_workspace\springbootTest\target\classes\mapper\userInfoMapper.xml]’. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias ‘UserInfo’. Cause: java.lang.ClassNotFoundException: Cannot find class: UserInfo

可能原因:mapper文件中方法返回值即resultType的值配错了
解决方案
1.这里需要正确地写出entity类的全路径,注意是全路径!像这样:

<select id="getUserInfo" parameterType="java.util.Map" resultType="com.mjj.springboot.bean.UserInfo">

2.如果全路径很长,你又不想逐个

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值