0

您好我正在尝试使用 ibatis 在 JSP 中显示数据。以下是我的 contentstatisController.java 页面

    @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";
}

以下是我的 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);
}

以下是包含查询的所有字段的 xml 页面,可以正常工作。

<!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>

同样,上面是我想要在 JSP 页面中显示的字段名称的 xml 页面。

谢谢你。但是我错过了编写 ContentStatis.java,我在其中声明了查询所需的所有属性。以下是 ContentStatis.java。包 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; 

现在,以下是 JSP 页面。

(注意我只想显示周和 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>

但是由于某种原因,JSP 页面只显示文本“你好”

它们都没有出现在 JSP 中。concole 中也没有错误消息。

但是,colsole 仍然显示我在 xml 页面中编写的整个查询。

谁能帮我显示数据?我已经被困了3天了...

4

1 回答 1

0

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>
于 2013-06-10T08:35:45.343 回答