package zkseasar.dto;
public class RainfallAvgDto {
public Integer year;
public Double average;
}
DTOのプロパティ名とSQLのカラム名を統一するだけでSQLを実行した結果がDTOへ自動的にマッピングされるようです。
...
public ListselectRainfallAvg(){
return jdbcManager.selectBySql(RainfallAvgDto.class,
" select year, avg(rainfall) as average" +
" from rain_stats " +
" group by year " +
" order by year ")
.getResultList();
}
...
EclipseのメニューからRun>Debug As>JUnit Testで実行できます。
public class RainStatsServiceTest extends S2TestCase {
private JdbcManager jdbcManager;
protected void setUp() throws Exception {
include("app.dicon");
}
public void testSelectRainfallAvg() throws Exception {
RainStatsService rainStatsService =
SingletonS2Container.getComponent("rainStatsService");
Listresults =
rainStatsService.selectRainfallAvg();
for (RainfallAvgDto dto : results) {
System.out.println(dto.year + ":"+ dto.average);
}
}
}
0 件のコメント:
コメントを投稿