Java to CSV with Smooks

落爺英雄遲暮 提交于 2019-12-12 05:14:23

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!