MSSQL 의 pivot table 을 리턴하는 프로시저를 실행하여 

해당 데이터를 화면에 뿌려주기 위한 작업.

 

dynamic 컬럼을 만드는 방법은 이전 포스팅에 있음

https://oyesji.tistory.com/60

 

Pivot 결과로 컬럼, 로우 총합 구하기

https://www.codeproject.com/Articles/232181/SQL-Pivot-with-Grand-Total-Column-and-Row SQL Dynamic Pivots Introduction Microsoft SQL Server has introduced the PIVOT and UNPIVOT commands as enhancemen..

oyesji.tistory.com

 

1. mybatis xml

resultType 주의!

<select id="selectTest" parameterType="int" resultType="java.util.LinkedHashMap">
	--selectTest
	EXEC dbo.TEST
		@IDX = #{idx}
</select>

 

2. service

dynamic 컬럼명을 별도로 추출해야함.

List< Map< String, Object > > rList = this.mapper.selectTest( idx );
Set<String> header = null;

LinkedList< Map< String, Object > > list = new LinkedList<>();
list.addAll( rList );

if ( list != null && list.size() > 0 ) {
	//컬럼명 추출
  for ( ListIterator< Map< String, Object > > it = (ListIterator< Map< String, Object > >) list.iterator(); it.hasNext(); ) {
    Map< String, Object > column = it.next();
    if( NumberUtils.toInt( Objects.toString( column.get( "SEQ" ) ) ) == 0 ) {
    	header = column.keySet();
    }
  }
}

 

3. view

<c:forEach items="${list}" var="item" varStatus="row" >
	<tr>
		<c:forEach items="${header}" var="h" varStatus="col">
			<c:set var="headerName" value="${h}"></c:set>
			${item[headerName]}
		</c:forEach>
	</tr>
 </c:forEach>

 

'Language > JAVA' 카테고리의 다른 글

Attribute로 XML Parse 하기 (htmlTag 포함)  (0) 2017.09.12

+ Recent posts