feat(修改): 导入Excel不成功
Signed-off-by: bunny <1319900154@qq.com>
This commit is contained in:
parent
d45eac0623
commit
b950c186fa
|
@ -38,7 +38,7 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
|||
protected void addInterceptors(InterceptorRegistry registry) {
|
||||
log.info("WebMvcConfiguration===>开始注册自定义拦截器...");
|
||||
// 需要拦截的
|
||||
registry.addInterceptor(loginAuthInterceptor).addPathPatterns("/admin")
|
||||
registry.addInterceptor(loginAuthInterceptor).addPathPatterns("/admin/**")
|
||||
.excludePathPatterns(interceptorsProperties.getNoAuthUrls());
|
||||
}
|
||||
}
|
|
@ -19,7 +19,8 @@ public class CategoryExcelListener<T> extends AnalysisEventListener<T> {
|
|||
private static final int BATCH_COUNT = 100;
|
||||
// 缓存的数据
|
||||
private final List<CategoryExcelVo> cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
|
||||
private CategoryMapper categoryMapper;
|
||||
// 获取mapper对象
|
||||
private final CategoryMapper categoryMapper;
|
||||
|
||||
@Override
|
||||
public void invoke(T t, AnalysisContext analysisContext) {
|
||||
|
|
|
@ -2,7 +2,7 @@ package com.atguigu.spzx.manger.service.impl;
|
|||
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.atguigu.exception.BunnyException;
|
||||
import com.atguigu.spzx.manger.excel.ExcelListener;
|
||||
import com.atguigu.spzx.manger.excel.CategoryExcelListener;
|
||||
import com.atguigu.spzx.manger.mapper.CategoryMapper;
|
||||
import com.atguigu.spzx.manger.service.CategoryService;
|
||||
import com.atguigu.spzx.model.entity.product.Category;
|
||||
|
@ -88,7 +88,7 @@ public class CategoryServiceImpl implements CategoryService {
|
|||
@Override
|
||||
public void importData(MultipartFile file) {
|
||||
// 创建监听器对象,传递mapper对象
|
||||
ExcelListener<CategoryExcelVo> listener = new ExcelListener<>();
|
||||
CategoryExcelListener<CategoryExcelVo> listener = new CategoryExcelListener<>(categoryMapper);
|
||||
// 调用read方法读取excel数据
|
||||
try {
|
||||
EasyExcel.read(file.getInputStream(), CategoryExcelVo.class, listener).sheet().doRead();
|
||||
|
|
|
@ -13,9 +13,8 @@
|
|||
insert into category (id, name, image_url, parent_id, status, order_num, create_time, update_time, is_deleted)
|
||||
values
|
||||
<foreach collection="cachedDataList" item="item" separator=",">
|
||||
(#{item.id}, #{item.name}, #{item.image_url}, #{item.parent_id}, #{item.status}, #{item.order_num},
|
||||
#{item.create_time}, #{item.update_time},
|
||||
#{item.is_deleted})
|
||||
( #{item.id}, #{item.name}, #{item.imageUrl}, #{item.parentId}, #{item.status}, #{item.orderNum}, now(),
|
||||
now(), 0)
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
|
|
Loading…
Reference in New Issue