網站首頁 編程語言 正文
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
- 上一篇:沒有了
- 下一篇:沒有了
相關推薦
- 2022-04-21 詳解前端到底可以用nginx做什么_nginx
- 2023-11-17 在python中按不同的條件在列表list、字典dict和集合set中篩選想要的數據(以實際案例進行
- 2022-07-22 Python動態屬性有什么用
- 2022-12-08 pycharm?無法加載文件activate.ps1的原因分析及解決方法_python
- 2022-03-30 Android中圖片占用內存的深入分析_Android
- 2022-10-31 Android數據緩存框架內置ORM功能使用教程_Android
- 2022-06-29 python人工智能tensorflow函數tf.nn.dropout使用方法_python
- 2022-08-14 深入了解Android?IO的底層原理_Android
- 欄目分類
-
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支