Cannot resolve symbol异常产生原因及解决方案

01 异常发生场景

  • 当我使用xml文件配置springboot框架下的mybatis时
  • 出现了resultType无法匹配爆红的现象
  • 以下是代码部分
 <resultMap id="OrdersVoResult" type="OrdersVo">
        <!-- id配置的是主键,就是表的主键 -->
        <!-- property是实体类的属性名 -->
        <!-- cloumn是sql查询出来的字段名 -->
        <id property="orderId" column="order_id"></id>
        <!-- result是其他的字段 -->
        <result property="orderNum" column="order_num"></result>
        <result property="orderTime" column="order_time"></result>
        <association property="products" javaType="ordersDtlVo">
            <id property="orderDtlId" column="order_dtl_id"></id>
            <result property="productId" column="product_id"></result>
            <result property="productName" column="product_name"></result>
            <result property="productSellingPrice" column="product_selling_price"></result>
            <result property="num" column="num"></result>
            <result property="productPicture" column="product_picture"></result>
        </association>
    </resultMap>
<select id="selectOrders" resultType="OrdersVoResult">
SELECT
    orders.order_id,
    orders.order_num,
    orders.create_time,
    orders_dtl.order_dtl_id,
    orders_dtl.product_id,
    orders_dtl.product_name,
    orders_dtl.product_selling_price,
    orders_dtl.num,
    orders_dtl.product_picture
    FROM
    orders ,
    orders_dtl
    WHERE
    orders.order_id = orders_dtl.order_id AND
    orders.user_id = #{userId}
</select>

02 尝试解决问题的过程

1.yml配置问题

  • 我一开始认为是yml配置别名包有问题,毕竟系统报的错误是没有找到对应实体类
mybatis:
  # mapper配置文件
  mapper-locations: classpath:mapper/*.xml
  # resultType别名,没有这个配置resultType包名要写全,配置后只要写类名
  type-aliases-package: com.example.demo.com.mashang.dao
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
    map-underscore-to-camel-case: true
  • 但是反复确认后,确定resultType别名包无问题(事后想想也确实,resultMap是映射标签,怎么可能会和resultType别名包有关系)

2.缓存问题

  • 在面向百度编程后,认为问题出在缓存
  • 在target文件包的对应xml文件里也确实没有找到映射类
  • 在使用clean处理了缓存后依旧爆红

3 .lombok依赖冲突

  • lombok是我使用的用于自动生成get和set方法的模块化插件,过时的版本会在编译时失去作用
<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <scope>provided</scope>
    <version>1.18.28</version>
</dependency>
  • 在尝试添加依赖后依旧没有解决resultType标签爆红问题

  • 在我一筹莫展之时,请求了老师的帮助

03 问题的产生及其原因

  • 会出现爆红是因为我图方便让系统自动生成resultType标签
  • 爆红的原因是因为映射需要的结果集是resultMap标签,所以对应不上,自然就爆红了

04 解决方式

  • 将系统生成的resultType标签换成resultMap标签就可以解决Cannot resolve symbol 'XXXX’异常(标签查询不到异常)了
<select id="selectOrders" resultMap="OrdersVoResult">
SELECT
    orders.order_id,
    orders.order_num,
    orders.create_time,
    orders_dtl.order_dtl_id,
    orders_dtl.product_id,
    orders_dtl.product_name,
    orders_dtl.product_selling_price,
    orders_dtl.num,
    orders_dtl.product_picture
    FROM
    orders ,
    orders_dtl
    WHERE
    orders.order_id = orders_dtl.order_id AND
    orders.user_id = #{userId}
</select>
  • 18
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

宣布无人罪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值