亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我應該如何糾正批量更新方法

我應該如何糾正批量更新方法

紫衣仙女 2023-09-27 16:26:11
我想批量更新mysql數據以確保性能,這是我的代碼:public void updateCustomCategory(List<ItemDto> itemDtoList) {if (CollectionUtils.isNotEmpty(itemDtoList)) {  jdbcTemplate.batchUpdate("update ItemDto item set item.l1CustomCatId = ?, item.l2CustomCatId = ? where itemId = ?",          new BatchPreparedStatementSetter() {            @Override            public void setValues(PreparedStatement ps, int i) throws SQLException {              ps.setLong(1, itemDtoList.get(i).getL1CustomCatId());              ps.setLong(2, itemDtoList.get(i).getL2CustomCatId());              ps.setLong(3, itemDtoList.get(i).getItemId());            }            @Override            public int getBatchSize() {              return itemDtoList.size();            }          });}}但是當我運行這個方法時,總是出現NPE,異常如下:2019-10-07 11:50:19.998 ERROR 125538 --- [nio-9092-exec-5] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root causejava.lang.NullPointerException: null    at com.shopee.data.bizcore.brandseller.dao.item.ItemDaoImpl.updateCustomCategory(ItemDaoImpl.java:92) ~[brand-seller-bizcore-0.0.1-SNAPSHOT.jar!/:na]    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181]    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343) ~[spring-aop-5.1.2.RELEASE.jar!/:5.1.2.RELEASE]    at org.springframework.aop.framework.Reflection我不知道根本原因,我應該如何修改它?謝謝
查看完整描述

1 回答

?
海綿寶寶撒

TA貢獻1809條經驗 獲得超8個贊

忘記了私有 JdbcTemplate jdbcTemplate 的 @@Autowired 注釋,這使得 jdbcTemplate 為 null



查看完整回答
反對 回復 2023-09-27
  • 1 回答
  • 0 關注
  • 92 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號