Question

Hi Im trying to display datas in JSP using ibatis. Following is my contentstatisController.java page

    @RequestMapping(value="/contentStatis")
public String contentStatis(
        HttpServletResponse response,
        ModelMap model,
        Condition condition,
        @RequestParam Map<String, Object> maps) throws Exception { 

    if(!PotSessionUtils.isAdminLogin()) {
        PotSessionUtils.goAdminMainPage(response);
    } else {


logger.debug("=======================================================>");
        logger.debug("파라메타 확인(maps) ========> " + maps);

logger.debug("=======================================================>");

List<ContentStatis> result = ContentStatisRepository.statis(maps);
Pagination<ContentStatis> resultList = PaginationUtil.getPaginationList(result,         
condition, (long)result.size(), Order.DESC);

model.addAttribute("condition", condition);
model.addAttribute("resultList", resultList);

    }
    return "admin/statisMng/contentStatis";
}

Following is my ContentStatisRepository.java

package com.ebsm.pot.repository;

import groove.spring.data.sqlmap.ibatis.SqlmapRepository;
import groove.spring.data.sqlmap.ibatis.StatementNamespace;
import groove.spring.data.sqlmap.ibatis.statement.Statement;

import java.util.List;
import java.util.Map;

import org.springframework.transaction.annotation.Transactional;

import com.ebsm.pot.domain.ContentStatis;

@StatementNamespace("ContentStatis")
@Transactional(readOnly=true)
public interface ContentStatisRepository   extends SqlmapRepository<ContentStatis,    
String> {

@Statement(id="ContentStatis.statis")
public List<ContentStatis> statis(Map<String, Object> maps);
}

Following is xml page that contains all the fields for the query, which works fine.

<!DOCTYPE sqlMap
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="ContentStatis">

<typeAlias alias="content"                   
type="com.ebsm.pot.domain.ContentStatis"/>

<resultMap id="ContentStatis"           class="content">
    <result property="day"          column="DAY"/>


<result property="week"     column="WEEK"/> 
<result property="mnotCnt"      column="MNOT_CNT"/> 
<result property="movie500kCnt" column="MOVIE_500K_CNT"/> 
<result property="movie1mCnt"   column="MOVIE_1M_CNT"/> 
<result property="movieCnt"     column="MOVIE_CNT"/> 
<result property="examCnt"          column="EXAM_CNT"/> 
<result property="webCnt"           column="WEB_CNT"/> 
<result property="imgCnt"       column="IMG_CNT"/> 
<result property="interractiveCnt"  column="INTERRACTIVE_CNT"/> 
<result property="docCnt"           column="DOC_CNT"/> 
<result property="totCnt"           column="TOT_CNT"/>


</resultMap>
<select> query comes here </select>
</sqlmap>

Again, above is my xml page with field names I want to display in JSP page.

Thankyou. But I have missed to write the ContentStatis.java, where I declare all the properties I need for the query. Following is the ContentStatis.java. package com.ebsm.pot.domain;

import java.io.Serializable;

import com.ebsm.pot.util.pagination.Sequence;

public class ContentStatis implements Serializable, Sequence {

private static final long serialVersionUID = -6406006154387239376L;



private int listSeqNo;


public int getListSeqNo() {
    return listSeqNo;
}





public void setListSeqNo(int listSeqNo) {
    this.listSeqNo = listSeqNo;
}










public String getWeek() {
    return week;
}





public void setWeek(String week) {
    this.week = week;
}





public int getMnotCnt() {
    return mnotCnt;
}





public void setMnotCnt(int mnotCnt) {
    this.mnotCnt = mnotCnt;
}





public int getMovie500kCnt() {
    return movie500kCnt;
}





public void setMovie500kCnt(int movie500kCnt) {
    this.movie500kCnt = movie500kCnt;
}





public int getMovie1mCnt() {
    return movie1mCnt;
}





public void setMovie1mCnt(int movie1mCnt) {
    this.movie1mCnt = movie1mCnt;
}





public int getMovieCnt() {
    return movieCnt;
}





public void setMovieCnt(int movieCnt) {
    this.movieCnt = movieCnt;
}





public int getExamCnt() {
    return examCnt;
}





public void setExamCnt(int examCnt) {
    this.examCnt = examCnt;
}





public int getWebCnt() {
    return webCnt;
}





public void setWebCnt(int webCnt) {
    this.webCnt = webCnt;
}





public int getImgCnt() {
    return imgCnt;
}





public void setImgCnt(int imgCnt) {
    this.imgCnt = imgCnt;
}





public int getInterractiveCnt() {
    return interractiveCnt;
}





public void setInterractiveCnt(int interractiveCnt) {
    this.interractiveCnt = interractiveCnt;
}





public int getDocCnt() {
    return docCnt;
}





public void setDocCnt(int docCnt) {
    this.docCnt = docCnt;
}





public int getTotCnt() {
    return totCnt;
}





public void setTotCnt(int totCnt) {
    this.totCnt = totCnt;
}


public String getDay() {
    return day;
}





public void setDay(String day) {
    this.day = day;
}




private String day;


private String week;


private int mnotCnt;


private int movie500kCnt;


private int movie1mCnt;


private int movieCnt;


private int examCnt;


private int webCnt;


private int imgCnt;


private int interractiveCnt;


private int docCnt; 


private int totCnt; 

Now, following is the JSP page.

(Notice that I just want to display week and webCnt)

<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/include/base.jsp"%>

<form id="downfrm" name="downfrm"></form>
<div id="contentBody">
    <jsp:include page="/WEB-INF/views/adminNavi.jsp" />

<div class="boxA_A">
    <div class="boxA_B">

        Hello

        <c:out value="${result.week}" />

        <c:out value="${result.webCnt}" />

    </div>
</div>
</div>

But for some reason, JSP page only displays the text 'Hello'

Neither of them appear in the JSP. No error message in concole either.

However, the colsole still displays the whole query I wrote in xml page.

Can anyone help me displaying the datas? I've been stuck in this for 3 days now...

Was it helpful?

Solution

You are setting the model attributes as :

model.addAttribute("condition", condition);
model.addAttribute("resultList", resultList);

In your JSP page , you can access them as :

${condition}
${resultList}

To access any of the properties of resultList , you have to use :

${resultList.property}  // property is a bean-style attribute of class whose object is resultList.

To access the List of result :

List<ContentStatis> result = ContentStatisRepository.statis(maps);

You need to set it in ModelMap.

model.addAttribute("result", result);

Then you can retrieve it in JSP as :

${result}

Since it is a List<ContentStatis> , you have to iterate through it and get each ContentStatis object using JSTL :

<c:forEach var="contentStatis" items="${result}" varStatus="i">
  Week: ${contentStatis.week} <!-- if contentStatis has week property  -->
  <br>webCnt: ${contentStatis.webCnt} <!-- if contentStatis has webCntproperty  -->
</c:forEach>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top