1.pom
<!-- jwt -->
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>${jwt.version}</version>
</dependency>
<dependency>
<groupId>net.sourceforge.jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>2.6.12</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel-core</artifactId>
<version>3.2.1</version>
<exclusions>
<exclusion>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.3</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.2.3</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>4.1.2</version>
</dependency>
2. 导入数据代码
@ApiOperation(value = "网页名称地址字典导入", httpMethod = "POST")
@PostMapping("/importWebUrl")
@MustAuth(mustLogin = false)
@LogDiy(title = "网页名称地址字典导入")
public void importWebUrl(String excelFilePath) {
try (FileInputStream inputStream = new FileInputStream(new File(excelFilePath));
Workbook workbook = new XSSFWorkbook(inputStream)) {
Sheet sheet = workbook.getSheetAt(0); // 读取第一个工作表
for (Row row : sheet) { // 迭代每一行
if (row.getRowNum() != 0) {
String stringCellValue = row.getCell(0).getStringCellValue();
String stringCellValue1 = row.getCell(1).getStringCellValue();
JSONObject jsonObject = JSONObject.parseObject(stringCellValue);
String webName = jsonObject.get("website_name").toString();
WebDomainDictionaryTable webDomain = new WebDomainDictionaryTable();
String domain = "";
if (stringCellValue1.startsWith("http")) {
URL url = new URL(stringCellValue1);
domain = url.getHost();
} else {
domain = stringCellValue1;
}
webDomain.setInsertTime(new Date());
webDomain.setUrl(domain);
webDomain.setWebsiteName(webName);
service.save(webDomain);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}