2016-10-08 4 views
0

コントローラでマップを生成しました。JSPページの年齢のマップを取得し、テーブルの2つの列にキーと値を表示する方法

Map<String, String> currentbatchitems = new HashMap<String, String>(); 

    for (int i = 0; i < currentbatchitem.size(); i++) { 
     currentbatchitems.put(currentbatchitem.get(i).getEmpCode(), currentbatchitem.get(i).getEmpName().toString()); 

    } 
    data.put("currentbatchitems", currentbatchitems); 

キーと値をJSPの別の列に表示するにはどうすればよいですか。次のようになります。This the table.The key of the map is employee code and value is employee name.How could I add the row on this table by getting the value from this map?

答えて

0

単純に名前ではなくEmployeeインスタンスを追加することで、マップを改善できます。

マップを反復して、値を書き込むためにJSP ELを使用することができますlibにJSTLのコアタグを使用して
Map<String, Employee> currentBatchitems = new HashMap<String, Employee>(); 

for (Employee employee : currentbatchitem) { 
    currentbatchitems.put(employee.getEmpCode(), employee); 

} 

data.put("currentbatchitems", currentbatchitems); 

​​
+0

はそんなにありがとう –

関連する問題