问题
Is there a way Smooks could generate a CSV file based on a java instance?
I am looking for something like:
public static void main(String[] args){
Employee emp = new Employee();
emp.setName("abc");
emp.setSalary(12312);
/* set other emp fields */
smooks.filterSource(.....);
}
CSV Output: "abc","12312", .............
Thanks!
回答1:
Just take a look at Smooks documentation here, it is done by wrapping your bean with JavaSource
object - example can be found here
Then you can use FreeMarker
template to transform Java Object into desired format - look here
update Working example can be found here at github
来源:https://stackoverflow.com/questions/23630553/java-to-csv-with-smooks