在用spring batch做批处理时,item reader从文件中读取的中文变成乱码,怎么处理?
具体来说,在本地maven工程中运行,不会乱码;用main方法测试会出现乱码,房子linux上运行web工程也是乱码。
下面是processor方法中,做各种尝试,打印出来的是乱码:
public class ChangelogProcessor implements
ItemProcessor {
public Changelog process(Changelog bill) throws Exception {
System.out.println(bill.getDescription().getBytes("GB2312"));
System.out.println(URLDecoder.decode(bill.getDescription(), "GB2312"));
System.out.println(new String(bill.getDescription().getBytes(), "GB2312"));
System.out.println(new String(bill.getDescription().getBytes("GB2312"), "GB2312"));
System.out.println(new String(bill.getDescription().getBytes("ISO8859_1"),"utf-8"));
return bill;
}
}
以下是spring配置信息:
<job id="ibatisWriteJob">
<step id="ibatisWriteStep">
<tasklet transaction-manager="transactionManager">
<chunk reader="csvItemReader" processor="creditBillProcessor"
writer="ibatisItemWriter" commit-interval="2"></chunk>
</tasklet>
</step>
</job>
<bean:bean id="creditBillProcessor" scope="step"
class="com.sinowel.youzan.changelog.ChangelogProcessor">
</bean:bean>