service层拼接XML
1.xml文件样式
<?xml version="1.0" encoding="UTF-8"?>
< rows> < userdata name = " totalnumber" > 21</ userdata> < row id = " 1" > < cell> 1</ cell> < cell> 案号</ cell> < cell> 案件名称</ cell> < cell> 承办部门</ cell> < cell> 承办人</ cell> </ row> < row id = " 2" > < cell> 2</ cell> < cell> 案号</ cell> < cell> 案件名称</ cell> < cell> 承办部门</ cell> < cell> 承办人</ cell> </ row> < row id = " 3" selected = " 1" > < cell> 3</ cell> < cell> 案号</ cell> < cell> 案件名称</ cell> < cell> 承办部门</ cell> < cell> 承办人</ cell> </ row> < row id = " 4" > < cell> 4</ cell> < cell> 案号</ cell> < cell> 案件名称</ cell> < cell> 承办部门</ cell> < cell> 承办人</ cell> </ row> < row id = " 5" > < cell> 5</ cell> < cell> 案号</ cell> < cell> 案件名称</ cell> < cell> 承办部门</ cell> < cell> 承办人</ cell> </ row> < row id = " 6" > < cell> 6</ cell> < cell> 案号</ cell> < cell> 案件名称</ cell> < cell> 承办部门</ cell> < cell> 承办人</ cell> </ row>
</ rows>
2.拼接xml(使用mybatis分页插件pageHelper)
public static String getUserXMl ( PageInfo< User> pageInfo) { List< User> list = pageInfo. getList ( ) ; int start = pageInfo. getStartRow ( ) ; long totalNumber = pageInfo. getTotal ( ) ; StringBuilder sb = new StringBuilder ( "<?xml version='1.0' encoding='UTF-8'?>" ) ; sb. append ( "<rows>" ) ; int xh = start + 1 ; sb. append ( "<userdata name=\"totalnumber\">" ) . append ( totalNumber) . append ( "</userdata>" ) ; for ( User user : list) { sb. append ( "<row id=\"" ) . append ( xh) . append ( "\">" ) . append ( "<cell>" ) . append ( xh++ ) . append ( "</cell>" ) . append ( "<cell>" ) . append ( user. getYhxm ( ) ) . append ( "</cell>" ) . append ( "<cell>" ) . append ( user. getYhid ( ) ) . append ( "</cell>" ) . append ( "<cell>" ) . append ( user. getYhbm ( ) ) . append ( "</cell>" ) . append ( "<cell>" ) . append ( user. getYhxb ( ) ) . append ( "</cell>" ) . append ( "<cell><![CDATA[" ) . append ( "<button class=\"tdh_btn\" οnclick=show(\"" ) . append ( user. getYhdm ( ) ) . append ( "\")><i class=\"tdh_icon icon_search\"></i>查看</button>" ) . append ( "]]></cell>" ) . append ( "<cell><![CDATA[" ) . append ( "<button class=\"tdh_btn\" οnclick=deleteUser(\"" ) . append ( user. getYhdm ( ) ) . append ( "\")><i class=\"tdh_icon icon_del\"></i>删除</button>" ) . append ( "]]></cell>" ) . append ( "<cell><![CDATA[" ) . append ( "<button class=\"tdh_btn\" οnclick=update(\"" ) . append ( user. getYhdm ( ) ) . append ( "\")><i class=\"tdh_icon icon_edit\"></i>修改</button>" ) . append ( "]]></cell>" ) . append ( "</row>" ) ; } sb. append ( "</rows>" ) ; return sb. toString ( ) ; }