使用ibatis在JSP中显示数据

时间:2013-06-10 08:26:57

标签: jsp spring-mvc el ibatis

您好我试图使用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>

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

三江源。但我错过了编写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页面只显示文本“Hello”

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

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

有人可以帮我显示数据吗?我已经被困在这3天了......

1 个答案:

答案 0 :(得分:0)

您将模型属性设置为:

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

在JSP页面中,您可以访问它们:

${condition}
${resultList}

要访问resultList的任何属性,您必须使用:

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

访问List的{​​{1}}:

result

您需要在List<ContentStatis> result = ContentStatisRepository.statis(maps);

中进行设置
ModelMap

然后您可以在JSP中检索它:

model.addAttribute("result", result);

由于它是${result} ,你必须遍历它并使用JSTL获取每个List<ContentStatis>对象:

ContentStatis