日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

Cannot resolve symbol異常產生原因及解決方案

作者:宣布無人罪 更新時間: 2023-12-19 編程語言

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>

原文鏈接:https://blog.csdn.net/2302_77182979/article/details/134431427

  • 上一篇:沒有了
  • 下一篇:沒有了
欄目分類
最近更新