我的sql是select material,material_type from c_mat_womb where material_type in('CELL','LC','POLAR-UP')
我想通过setProperty 将material_type和对应的material压在一起,程式是这样的: while(rs.next())
{
tmpPro.setProperty("material_type",Tools.parseString(rs.getString("material_type")));
tmpPro.setProperty("material",Tools.parseString(rs.getString("material")));
tmpList.add(tmpPro);
}
结果我的tmpPro里只有第一个material_type(CELL)的结果,tmpList打印出来是[{material_type=cell,material=57.2},{material_type=cell,material=57.2},{material_type=cell,material=57.2}]我想要的结果是[{material_type=cell,material=57.2},{material_type=lc,material=57.6},{material_type=polor-up,material=57.9}]不知道正确的应该怎么写?
请高手指教!
我想通过setProperty 将material_type和对应的material压在一起,程式是这样的: while(rs.next())
{
tmpPro.setProperty("material_type",Tools.parseString(rs.getString("material_type")));
tmpPro.setProperty("material",Tools.parseString(rs.getString("material")));
tmpList.add(tmpPro);
}
结果我的tmpPro里只有第一个material_type(CELL)的结果,tmpList打印出来是[{material_type=cell,material=57.2},{material_type=cell,material=57.2},{material_type=cell,material=57.2}]我想要的结果是[{material_type=cell,material=57.2},{material_type=lc,material=57.6},{material_type=polor-up,material=57.9}]不知道正确的应该怎么写?
请高手指教!
{
tmpPro=new Property();//每次要创建新对象,否则会覆盖
tmpPro.setProperty("material_type",Tools.parseString(rs.getString("material_type")));
tmpPro.setProperty("material",Tools.parseString(rs.getString("material")));
tmpList.add(tmpPro);
}
for(int i=0;i<tmpList.size();i++)
{
pro=(Properties)tmpList.get(i);
pro.setProperty(tmpPro.getProperty("material_type"),tmpPro.getProperty("material",""));
}
我想要的结果是{cell=57.2,lc=57.6,polor-up=57.9}
但按照我的程式打印出来是
{cell=57.2,material=57.2,material_type=cell}
请大家帮忙解决一下啦!不胜感激!急!!!
这个key应该是一个固定的标志,你现在把一个变量放进来,取的时候应该会有问题的.