定制弹簧批次项目平面作家

时间:2015-05-05 02:38:52

标签: spring-batch

我有一个可以创建平面文件的弹簧批处理程序,但我希望能够将标签放到我的字段中。

这是我的Pojo示例学生

public class Student{

private String studentName;
private double gpa;


public String getStudentName() {
    return studentName;
}

public void setStudentName(String studentName) {
    this.studentName = studentName;
}

public double getGpa() {
    return dob;
}

public void setGpa(double gpa) {
    this.gpa= gpa;
}

这是我的rowmapper

public class StudentRowMapper implements RowMapper<Student>{

@Override
public Student mapRow(ResultSet rs, int rowNum) throws SQLException {

    Student student= new Student();
    student.setStudentName(rs.getString("student_name"));
    student.setGpa(rs.getDouble("gpa"));

    return student;
} 

}

以下是我的XML文件的摘录:

    

    <property name="lineAggregator">

        <!-- An Aggregator which converts an object into delimited list of strings -->
        <bean
            class="org.springframework.batch.item.file.transform.DelimitedLineAggregator">

            <property name="delimiter" value="|" />

            <property name="fieldExtractor">


                <bean
                    class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
                    <property name="names" value="studentName, gpa" />
                </bean>
            </property>
        </bean>
    </property>
</bean>

它产生以下输出

Rita Paul|3.8|
Han Yanagata|3.0|

我希望能够为每个字段添加coustme前缀,我希望能够编写一个说明

的平面文件
name=Rita Paul|gpa=3.8|
name=Han Yanagata|gpa=3.0|

1 个答案:

答案 0 :(得分:0)

在您的行映射器中,您可以通过

进行自定义
public class StudentRowMapper implements RowMapper<Student>{

@Override
public Student mapRow(ResultSet rs, int rowNum) throws SQLException {

    Student student= new Student();
    student.setStudentName("name="+rs.getString("student_name"));
    student.setGpa("gpa="+rs.getDouble("gpa"));

    return student;
}