как я должен исправить метод массового обновления - PullRequest
0 голосов
/ 07 октября 2019

Я хочу массово обновить данные 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 cause

java.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 Ответ

0 голосов
/ 07 октября 2019

забыли @@ аннотацию с проводным подключением к частному jdbcTemplate jdbcTemplate, что сделало jdbcTemplate нулевым

...