我在jsp中显示数组列表时遇到了问题。它为每个人重复显示一行。 我有列的表格(电话号码,传真,PHONE2,电子邮件)Spring MVC正确显示JSP中的数组列表
这里是我的道功能:
@Override
public ArrayList<String> moyenCom(Authentication auth) {
String login=auth.getName();
List list;
List listres = null;
ArrayList<String> array1=new ArrayList<String>();
//ArrayList<ArrayList<String>> array=new ArrayList<ArrayList<String>>();
SessionFactory factory=new Configuration().configure().buildSessionFactory();
Session session=factory.openSession();
session.beginTransaction();
//Your operation
String sql1="select r.id_responsable from WEBCARE.PERSONNE p,WEBCARE.RESPONSABLE r,WBB_CLU.ABONNE_COMPTE ac,WBB_CLU.COMPTE_CLU c where p.id=r.id_responsable and r.id_abonne=ac.id_abonne and c.id_compte=ac.id_compte and c.login=:x";
SQLQuery query1 = session.createSQLQuery(sql1);
query1.setParameter("x",login);
query1.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
session.getTransaction().commit();
list=query1.list();
for(int i=0;i<list.size();i++){
String res =list.get(i).toString();
String[] parts = res.split("=");
String part2 = parts[1];
System.out.println("id du responsable est"+res);
System.out.println("id du responsable spliteeee est "+part2);
session.beginTransaction();
String sql="select mc.information from WEBCARE.MOYEN_COMMUNICATION mc,WEBCARE.PERSONNE p where p.id=mc.id_categorie and mc.id_categorie=:part2 and mc.categorie=1";
SQLQuery query = session.createSQLQuery(sql);
query.setParameter("part2",part2);
query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
session.getTransaction().commit();
listres=query.list();
for(int i1=0;i1<listres.size();i1++){
String resu =listres.get(i1).toString();
System.out.println("info "+resu);
array1.add(resu);
}
}
System.out.println(array1);
return array1;
}
我的控制器:
@RequestMapping("/fichets")
public String fichets(Model model,Authentication auth){
Authentication authen = SecurityContextHolder.getContext().getAuthentication();
String name = authen.getName(); //get logged in username
model.addAttribute("moycoms",metier.moyenCom(auth));
return "InfoAbonneTS";
}
和我的jsp页面:
<c:forEach items="${resps}" var="resp">
<tr>
<td id="date">${resp.nom} ${resp.prenom}</td>
<td>${resp.poste}</td>
<td>${resp.password}</td>
<c:forEach items="${moycoms}" var="moycom">
<td>${moycom}</td>
</c:forEach>
</tr>
</tbody>
</c:forEach>
该函数返回字段信息巫婆包含所有4通知应该在每一列中显示每一栏。返回 的ArrayList是:
{information=}, {information=01999999999}, {information=0199999333}, {[email protected]}, {information=00 }, {information=0622355114}, {information=0588888888}, {[email protected]}, {information=00 }, {information=0111111111}, {information=0666666666}, {[email protected]}
所以前四个信息应在每一列中显示的每个,第二四件同样的事情...在这个例子中,我有3人。 我无法正确显示此帮助?
resps is for displaying the first 3 columns
感谢@Anand Muley的回复,y ES RESP包含ID用于显示四列,但我没有得到如何可以在jsp中使用它来验证数组列表的显示,我尝试了与stat不工作的代码..我只是分开值按4排组排列列表显示每一行。 –
检查你在字符串转换查询结果的代码: ''''''''''' System.out.println(“info”+ resu); array1.add(resu);' 将其更改为: 'Map resu =(Map)listres.get(i1); array1.add(resu);' –
是的,我已经删除了查询中的行,希望将结果转换为映射,我现在不需要转换它。问题是显示在jsp @Anand Muley –