我有300多个表要导出到CSV文件。但是我看到乱码。
我发送表名并使用jdbctemplate检索数据,我可以看到数据,但是当我导出时,我看到的是乱码
sr1org.springframework.util.LinkedCaseInsensitiveMapiEkMÑ= f $ LcaseInsensitiveKeystLjava / util / HashMap
sr1org.springframework.util.LinkedCaseInsensitiveMapiEkMÑ= f $ LcaseInsensitiveKeystLjava / util / HashMap
q〜q〜q〜q〜xq〜sq〜?@ wq〜sq〜q〜trivera92q〜
下面是代码:
exportData.java
public List getTableData(String tableName){
return jdbcTemplate.queryForList("select * FROM " + tableName + " LIMIT 10");
}
创建csv文件
@Autowired
ExportData exportData;
public void CreateCsvData(){
String tableName = "user_details";
String folderPath = "/tmp/Data/";
List data = this.exportData.getTableData(tableName);
try {
FileOutputStream fis = new FileOutputStream(folderPath + tableName + ".csv",true);
ObjectOutputStream os = new ObjectOutputStream(fis);
for (int i = 0; i < data.size(); i++) {
os.writeObject(data.get(i));
os.close();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
这是pom.xml
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-jdbc -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<version>2.0.4.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.4.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.12</version>
</dependency>
<dependencies>
我看到了许多resultsetextractor
和RowMapper
的示例,但是很难为300个表编写模型。
对不起,我不好。我遍历了忘记将其粘贴到此处的对象;