第一步 准备返回给视图的数据

package com.cwebs.samples;  

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map; import javax.portlet.ActionResponse;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.portlet.ModelAndView; import com.cwebs.common.CMySQL;
import com.cwebs.common.ConnectionInfo; @Controller
@RequestMapping("VIEW")
public class QueryBySQLViewController {
public ConnectionInfo ci = new ConnectionInfo(
"jdbc:mysql://localhost:3366/test", "root", "root"); @RequestMapping
public ModelAndView renderEditView(RenderRequest request,
RenderResponse response) throws Exception {
List<Map<String,String>> list=null;
try {
//step1:test open&close
CMySQL db = new CMySQL(ci.connStr, ci.usr, ci.pwd); //step2:test query with return
list=db.executeQuery("select * from babywatch");
db.testResult(list); }catch(Exception ex)
{
ex.printStackTrace();
} final Map<String, Object> model = new LinkedHashMap<String, Object>();
model.put("resultList", list);
model.put("title", "测试表格"); return new ModelAndView("SQLQueryResult", model);
}
}

  第二步 在视图中显示

<%@page contentType="text/html;charset=utf-8" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/jsp/include.jsp" %> <!-- View Mode --> <h2>${title}</h2> <c:choose>
<c:when test="${empty resultList}">
<p>没有记录</p>
</c:when>
<c:otherwise>
<table>
<tr>
<th>ID</th><th>名字</th><th>发布日期</th>
</tr>
<c:forEach var="result" items="${resultList}">
<tr>
<td>${result.BABYWATCH_ID}</td>
<td>${result.BABYWATCH_NAME}</td>
<td>${result.BABYWATCH_PUBLISHDATE}</td>
</tr>
</c:forEach>
</table>
</c:otherwise>
</c:choose> <h2>Portlet URLs</h2>
<ul>
<li><a href="<portlet:renderURL portletMode="view" />">View Mode</a>
<li><a href="<portlet:renderURL portletMode="edit" />">Edit Mode</a>
<li><a href="<portlet:renderURL portletMode="help" />">Help Mode</a>
<li><a href="<portlet:renderURL windowState="normal" />">Normal State</a>
<li><a href="<portlet:renderURL windowState="maximized" />">Maximized State</a>
<li><a href="<portlet:renderURL windowState="minimized" />">Minimized State</a>
</ul>

  上例在视图中显示了一个简单的表格。

Spring框架,如何返回数据给视图(jsp文件)的更多相关文章

  1. 创建一个视图JSP文件的helloWorld.jsp

    让我们创建下面的JSP文件的helloWorld.jsp,在WebContent文件夹在你的eclipse项目.要做到这一点,右键单击WebContent文件夹中的项目资源管理器,然后选择“新建”&g ...

  2. Spring 梳理-传递模型数据到视图

    传递model,返回string,不指定返回key package com.jt; import com.myOrg.DeptUserDomain; @Controller @RequestMappi ...

  3. 从csv文件里取数据作为请求参数,和把返回数据放到一个csv文件

    本来想把登陆后的token放到数组里,下一个参数用,但是貌似不支持数组,暂时先这样用了,并不麻烦,还很方便. 1.添加线程组等必要的东东后,添加csv配置器 2.进行设置 说明:csv文件设置不能读取 ...

  4. Spring框架总结

    Spring(由Rod Johnson创建的一个开源框架) Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Java 开发框架,由Rod Johnson创建.简单来说,Spr ...

  5. Spring笔记——Spring框架简介和初次框架配置

    Spring简介 Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Java 开发框架,由Rod Johnson 在其著作Expert One-On-One J2EE Deve ...

  6. Spring框架入门之Spring简介

    一.Spring简介(由Rod Johnson创建的一个开源框架)        Spring是一个开放源代码的设计层面框架,他解决的是业务逻辑层和其他各层的松耦合问题,因此它将面向接口的编程思想贯穿 ...

  7. Spring 框架基础(06):Mvc架构模式简介,执行流程详解

    本文源码:GitHub·点这里 || GitEE·点这里 一.SpringMvc框架简介 1.Mvc设计理念 MVC是一种软件设计典范,用一种业务逻辑.数据.界面显示分离的方法组织代码,将业务逻辑聚集 ...

  8. Spring系列(2):Spring框架

    一.Spring定义 Spring是一个开放源代码的设计层面框架,它解决的是业务逻辑层和其他各层的松耦合问题,因此它将面向接口的编程思想贯穿整个系统应用. Spring是于2003 年兴起的一个轻量级 ...

  9. Spring 框架学习—控制反转(IOC)

        Spring是一个开源框架,Spring是于2003 年兴起的一个轻量级的Java 开发框架,由Rod Johnson创建. 简单来说,Spring是一个分层的JavaSE/EEfull-st ...

随机推荐

  1. 【python游戏编程之旅】第二篇--pygame中的IO、数据

    本系列博客介绍以python+pygame库进行小游戏的开发.有写的不对之处还望各位海涵. 在上一篇中,我们介绍了pygame的入门操作http://www.cnblogs.com/msxh/p/49 ...

  2. Codeforces Round #192 (Div. 2) A. Cakeminator

    #include <iostream> #include <vector> using namespace std; int main(){ int r,c; cin > ...

  3. 【wikioi】1049 棋盘染色(迭代深搜)

    http://www.wikioi.com/problem/1049/ 这题我之前写没想到迭代加深,看了题解,然后学习了这种搜索(之前我写的某题也用过,,但是不懂专业名词 囧.) 迭代加深搜索就是限制 ...

  4. 如何获取checkboxlist的多个选中项

    string[] array = dt.Rows[0]["s_type"].ToString().Split('|');                foreach (ListI ...

  5. Js操作Select大全

    判断select选项中 是否存在Value="paraValue"的Item 向select选项中 加入一个Item 从select选项中 删除一个Item 删除select中选中 ...

  6. openstack-L版安装

    参照官方install document: http://docs.openstack.org/liberty/install-guide-rdo/ 实验环境:centos7.2 桥接: 192.16 ...

  7. 解决Eclipse Debug 的source not found问题

    最近在做Android 4.4系统的定制开发(RockIII)进行Debug时,并打上断点,运行到断点处时,Debug窗口出现source not found问题(没有自动关联程序编码): 解决办法: ...

  8. myBatis应用

    最近项目中使用myBatis(iBatis),所以目前对所遇的一些问题及有些模糊的地方在这里标注一下. 首先mybaits是一个“半自动化”的ORM框架. 需要使用的jar包:mybatis-3.0. ...

  9. snprintf/strncpy/strlcpy速度测试

    速度测试代码: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <un ...

  10. PHP 设计模式 笔记与总结(1)命名空间 与 类的自动载入

    ① PHP 面向对象高级特性 ② 11 种 PHP 设计模式 ③ PSR-0,Composer,Phar 等最流行的技术 目标是掌握 PHP 各类设计模式,以及具备设计纯面向对象框架和系统的能力 [命 ...