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

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配置中加入就好了

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

报告相同问题?

悬赏问题

  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗