up2do 2017-05-17 06:29 采纳率: 100%
浏览 1648
已采纳

spring batch的乱码问题,求助

在用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>
  • 写回答

1条回答 默认 最新

  • up2do 2017-05-17 07:00
    关注

    在reader配置中加入就好了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?