Map迭代的使用:
Map map = new HashMap() ;
Iterator it = map.entrySet().iterator() ;
while (it.hasNext())
{
Map.Entry entry = (Map.Entry) it.next() ;
Object key = entry.getKey() ;
Object value = entry.getValue() ;
}
Jsp页面
function exportWord(){
var data = setData();
jQuery.post("http://localhost:8080/expWord/GKBX29_word.jsp",data,function(data1){
var url = data1;
document.getElementById("wordUrl").value = url;
window.open(url);
});
}
function setData(){
var data = {};
data.author='zzz';
data.projectName = '<bean:write property="CommonMain/title"/>'; //项目名称
data.mainId = '<bean:write property="CommonMain/mainId"/>';
data.meetingSite = document.getElementById("meetingSite").value;
data.purchaseDep = document.getElementById("purchaseDep").value;
data.meetingPerson = document.getElementById("meetingPerson").value;
data.meetingContent = "其他";
data.meetingDate = document.getElementById("meetingDate").value;
data.manager = document.getElementById("manager").value;
data.purchaseState = document.getElementById("purchaseState").value;
data.purchaseContent = document.getElementById("purchaseContent").value;
data.purchasePriceContent = document.getElementById("purchasePriceContent").value;
data.purchaseProvider = document.getElementById("purchaseProvider").value;
return data;
}
GKBX29_word.jsp
<%@page import="java.util.List"%>
<%@page import="com.boco.eoms.bizlets.wfworksheet.util.SysoutLog"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.util.Map"%>
<%@page import="com.boco.eoms.word.client.word"%>
<%@page import="com.boco.eoms.worksheet.util.DBUtil"%>
<%
request.setCharacterEncoding("UTF-8");
String pakageAll="";
String mainId = request.getParameter("mainId");
if(mainId != null){
// 查询采购包和标段
String sql = "select * from WS_PREPARATORYSHEET_PROVIDER where main_id = "+mainId;
List list = DBUtil.getListResultBySQL(sql);
int i=0;
Iterator it = list.iterator() ;
while (it.hasNext())
{
i++;
Map map = (Map) it.next() ;
String id=(String)map.get("id");
String name=(String)map.get("name");
String pakage=(String)map.get("pakage");
String amount=(String)map.get("amount");
String price=(String)map.get("price");
String totalPrice=(String)map.get("totalPrice");
pakageAll +=i+"、" +pakage+"采购包由综合排名第一的"+name+"的公司负责供货(或提供**服务),采购价格为"+price+"";
}
}
word w = new word();
Map map = new HashMap();
map.put("pakageAll", pakageAll);
String url = w.replacWordByMap(map, "GKBX29Activity");
response.getWriter().write(url);
%>
DBUtil.java
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.primeton.bp.srm.ExprHelper;
/**
* @author Administrator
* @version 1.0
* @date 2011-11-29
* @class_displayName DBUtil
*/
public class DBUtil {
public static String[] getFieldValuesAsStringArray( String sql )
{
Connection conn = null;
Statement smt = null;
ResultSet rs = null;
try
{
conn = ExprHelper.getConnection();
smt=conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
rs = smt.executeQuery(sql);
rs.last();
String[] array = new String[rs.getRow()];
int i = 0;
rs.beforeFirst();
while(rs.next())
{
array[i++] = rs.getString(1);
}
return array;
}
catch( Exception e )
{
System.out.println(e.getMessage());
return null;
}
finally
{
try
{
if( rs != null )
rs.close();
}
catch( Exception e2 )
{
}
try
{
if( smt != null )
smt.close();
}
catch( Exception e2 )
{
}
try
{
if( conn != null )
conn.close();
}
catch( Exception e2 )
{
}
}
}
public static String getSingleResult(String GET_COLUMN,String SET_COLUMN,String SET_COLUMN_PARAM,String TABLENAME)
{
Connection conn = null;
Statement smt = null;
ResultSet rs = null;
try
{
conn = ExprHelper.getConnection();
smt=conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
String sql = "select "+GET_COLUMN+" from "+TABLENAME+" where "+SET_COLUMN+ "='"+SET_COLUMN_PARAM+"'";
rs = smt.executeQuery(sql);
String result="";
if(rs.next())
{
result = rs.getString(1);
}
return result;
}
catch( Exception e )
{
System.out.println(e.getMessage());
return null;
}
finally
{
try
{
if( rs != null )
rs.close();
}
catch( Exception e2 )
{
}
try
{
if( smt != null )
smt.close();
}
catch( Exception e2 )
{
}
try
{
if( conn != null )
conn.close();
}
catch( Exception e2 )
{
}
}
}
public static Map getResultBySQL(String sql)
{
Connection conn = null;
Statement smt = null;
ResultSet rs = null;
Map resultMap = new LinkedHashMap();
try
{
conn = ExprHelper.getConnection();
smt=conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
//int resultColumnCount = rs.getMetaData().getColumnCount();
rs = smt.executeQuery(sql);
while(rs.next())
{
resultMap.put(rs.getString(1),rs.getString(2));
}
return resultMap;
}
catch( Exception e )
{
System.out.println(e.getMessage());
return null;
}
finally
{
try
{
if( rs != null )
rs.close();
}
catch( Exception e2 )
{
}
try
{
if( smt != null )
smt.close();
}
catch( Exception e2 )
{
}
try
{
if( conn != null )
conn.close();
}
catch( Exception e2 )
{
}
}
}
public static List getListResultBySQL(String sql)
{
Connection conn = null;
Statement smt = null;
ResultSet rs = null;
List list = new ArrayList();
try
{
conn = ExprHelper.getConnection();
smt=conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
//int resultColumnCount = rs.getMetaData().getColumnCount();
rs = smt.executeQuery(sql);
while(rs.next())
{
Map resultMap = new LinkedHashMap();
resultMap.put("id",rs.getString(1));
resultMap.put("name",rs.getString(2));
resultMap.put("pakage",rs.getString(4));
resultMap.put("amount",rs.getString(19));
resultMap.put("price",rs.getString(20));
resultMap.put("totalPrice",rs.getString(23));
list.add(resultMap);
}
return list;
}
catch( Exception e )
{
System.out.println(e.getMessage());
return null;
}
finally
{
try
{
if( rs != null )
rs.close();
}
catch( Exception e2 )
{
}
try
{
if( smt != null )
smt.close();
}
catch( Exception e2 )
{
}
try
{
if( conn != null )
conn.close();
}
catch( Exception e2 )
{
}
}
}
}
输出效果:
1、33采购包由综合排名第一的null的公司负责供货(或提供**服务),采购价格为null
2、77采购包由综合排名第一的44的公司负责供货(或提供**服务),采购价格为44
3、888采购包由综合排名第一的null的公司负责供货(或提供**服务),采购价格为null
4、222采购包由综合排名第一的 ee的公司负责供货(或提供**服务),采购价格为4
5、4555采购包由综合排名第一的6的公司负责供货(或提供**服务),采购价格为6