最近刚开始接触hibernate+spring+mvc+Easyui框架,也是刚开通了博客,希望能记录一下自己实践出来的东西,让其他人少走弯路。

转让正题,以个人浅薄的认识hibernate对于开发人员的作用主要是节省了写sql连接数据库的时间,而grid++report内部提供的类来看,却是通过ajax直接连接数据库,还是需要写sql。感觉把grid++report用到这个框架里来的话,给人的感觉就是一匹快马,拉了一辆旧车,虽然速度上影响不了多少,但是审美感觉上很不爽。作为一个完美主义的程序员来说,这是不允许的。然后我就贱贱的尝试着怎么改掉它。关于hibernate+spring+mvc+Easyui框架的东西我就不说了,我只说一下grid++report的使用。

  

  

  1、打开grid++report客户端,连接数据库并绘制报表。

2.绘制完成后使用记事本打开.grf文件,把里面的数据库连接给清掉。

3.添加mvc的三个文件在html中载入.grf文件这个不细说,grid++的demo里多的是。

4.修改载入的数据源url

 ReportViewer.Stop();
ReportViewer.DataURL = "user/load";
// var BeginDate = document.getElementById("txtBeginDate").value;
// var EndDate = document.getElementById("txtEndDate").value;
// var DataURL = encodeURI("xmlSummary.aspx?BeginDate=" + BeginDate + "&EndDate=" + EndDate);
// ReportViewer.DataURL = DataURL; //更新查询参数更新报表付标题,设置对应静态框的“Text”属性
//ReportViewer.Report.ControlByName("SubTitle").AsStaticBox.Text = "日期范围:" + BeginDate + "至" + EndDate; ReportViewer.Start();

5.在control中编写load方法获取数据源,由于框架中使用hibernate获得的数据源格式为IList<T>格式,而grid++中接收的是xml格式。所以需要方法把这给转换一下。

度娘告诉我是这样转

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml; namespace Common.ToolsHelper
{
public class XMLHelperToList<T> where T : new()
{
#region 实体类转成Xml
/// <summary>
/// 对象实例转成xml
/// </summary>
/// <param name="item">对象实例</param>
/// <returns></returns>
public static string EntityToXml(T item)
{
IList<T> items = new List<T>();
items.Add(item);
return EntityToXml(items);
} /// <summary>
/// 对象实例集转成xml
/// </summary>
/// <param name="items">对象实例集</param>
/// <returns></returns>
public static string EntityToXml(IList<T> items)
{
//创建XmlDocument文档
XmlDocument doc = new XmlDocument();
//创建根元素
XmlElement root = doc.CreateElement(typeof(T).Name + "s");
//添加根元素的子元素集
foreach (T item in items)
{
EntityToXml(doc, root, item);
}
//向XmlDocument文档添加根元素
doc.AppendChild(root); return doc.InnerXml;
} private static void EntityToXml(XmlDocument doc, XmlElement root, T item)
{
//创建元素
XmlElement xmlItem = doc.CreateElement(typeof(T).Name);
//对象的属性集
System.Reflection.PropertyInfo[] propertyInfo = typeof(T).GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance); foreach (System.Reflection.PropertyInfo pinfo in propertyInfo)
{
if (pinfo != null)
{
//对象属性名称
string name = pinfo.Name;
//对象属性值
string value = String.Empty; if (pinfo.GetValue(item, null) != null)
value = pinfo.GetValue(item, null).ToString();//获取对象属性值
//设置元素的属性值
xmlItem.SetAttribute(name, value);
}
}
//向根添加子元素
root.AppendChild(xmlItem);
} #endregion #region Xml转成实体类 /// <summary>
/// Xml转成对象实例
/// </summary>
/// <param name="xml">xml</param>
/// <returns></returns>
public static T XmlToEntity(string xml)
{
IList<T> items = XmlToEntityList(xml);
if (items != null && items.Count > )
return items[];
else return default(T);
} /// <summary>
/// Xml转成对象实例集
/// </summary>
/// <param name="xml">xml</param>
/// <returns></returns>
public static IList<T> XmlToEntityList(string xml)
{
XmlDocument doc = new XmlDocument();
try
{
doc.LoadXml(xml);
}
catch
{
return null;
}
if (doc.ChildNodes.Count != )
return null;
if (doc.ChildNodes[].Name.ToLower() != typeof(T).Name.ToLower() + "s")
return null; XmlNode node = doc.ChildNodes[]; IList<T> items = new List<T>(); foreach (XmlNode child in node.ChildNodes)
{
if (child.Name.ToLower() == typeof(T).Name.ToLower())
items.Add(XmlNodeToEntity(child));
} return items;
} private static T XmlNodeToEntity(XmlNode node)
{
T item = new T(); if (node.NodeType == XmlNodeType.Element)
{
XmlElement element = (XmlElement)node; System.Reflection.PropertyInfo[] propertyInfo = typeof(T).GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance); foreach (XmlAttribute attr in element.Attributes)
{
string attrName = attr.Name.ToLower();
string attrValue = attr.Value.ToString();
foreach (System.Reflection.PropertyInfo pinfo in propertyInfo)
{
if (pinfo != null)
{
string name = pinfo.Name.ToLower();
Type dbType = pinfo.PropertyType;
if (name == attrName)
{
if (String.IsNullOrEmpty(attrValue))
continue;
switch (dbType.ToString())
{
case "System.Int32":
pinfo.SetValue(item, Convert.ToInt32(attrValue), null);
break;
case "System.Boolean":
pinfo.SetValue(item, Convert.ToBoolean(attrValue), null);
break;
case "System.DateTime":
pinfo.SetValue(item, Convert.ToDateTime(attrValue), null);
break;
case "System.Decimal":
pinfo.SetValue(item, Convert.ToDecimal(attrValue), null);
break;
case "System.Double":
pinfo.SetValue(item, Convert.ToDouble(attrValue), null);
break;
default:
pinfo.SetValue(item, attrValue, null);
break;
}
continue;
}
}
}
}
}
return item;
}
#endregion
}
}

然后自己获取数据并Response到页面上

方法如下。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;
using CLGL.Web.Controllers;
using System.Text;
using Wat.Common;
using Domain;
using System.IO.Compression;
using Newtonsoft.Json;
using System.Globalization;
using Common.ToolsHelper; namespace CLGL.Web.Areas.GrfDemo.Controllers
{
public class UserController : Controller
{
//
// GET: /GrfDemo/User/
Service.IUserManager userManage { get; set; }
//User user = new User();
public ActionResult Index()
{
return View();
} public ActionResult Load()
{
IList<User> list = userManage.LoadAll();
string str = XMLHelperToList<User>.EntityToXml(list);
Response.Write(str);
Response.End();
return View();
}
}
}

运行后,结果:

hibernate+spring+mvc+Easyui框架模式下使用grid++report的总结的更多相关文章

  1. 对Spring.Net+NHibenate+Asp.Net Mvc+Easyui框架的个人认识

    对Spring.Net+NHibenate+Asp.Net Mvc+Easyui框架的个人认识   初次接触Spring.Net+NHibenate+Asp.Net Mvc+Easyui框架,查阅了相 ...

  2. Spring.Net+NHibenate+Asp.Net Mvc+Easyui框架

    Spring.Net+NHibenate+Asp.Net Mvc+Easyui框架 初次接触Spring.Net+NHibenate+Asp.Net Mvc+Easyui框架,查阅了相关资料,了解了框 ...

  3. Spring MVC + jpa框架搭建,及全面分析

    一,hibernate与jpa的关系 首先明确一点jpa是什么?以前我就搞不清楚jpa和hibernate的关系. 1,JPA(Java Persistence API)是Sun官方提出的Java持久 ...

  4. Spring MVC 学习总结(十)——Spring+Spring MVC+MyBatis框架集成(IntelliJ IDEA SSM集成)

    与SSH(Struts/Spring/Hibernate/)一样,Spring+SpringMVC+MyBatis也有一个简称SSM,Spring实现业务对象管理,Spring MVC负责请求的转发和 ...

  5. [读后感]spring Mvc 教程框架实例以及系统演示下载

    [读后感]spring Mvc 教程框架实例以及系统演示下载 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致&qu ...

  6. Spring MVC测试框架

    原文链接:http://jinnianshilongnian.iteye.com/blog/2004660 Spring MVC测试框架详解——服务端测试 博客分类: springmvc杂谈 spri ...

  7. Spring MVC测试框架详解——服务端测试

    随着RESTful Web Service的流行,测试对外的Service是否满足期望也变的必要的.从Spring 3.2开始Spring了Spring Web测试框架,如果版本低于3.2,请使用sp ...

  8. Spring MVC的异步模式

    高性能的关键:Spring MVC的异步模式   我承认有些标题党了,不过话说这样其实也没错,关于“异步”处理的文章已经不少,代码例子也能找到很多,但我还是打算发表这篇我写了好长一段时间,却一直没发表 ...

  9. IntelliJ IDEA 13.x 下使用Hibernate + Spring MVC + JBoss 7.1.1

    从2004年开始做.NET到现在.直到最近要做一些JAVA的项目,如果说100个人写一篇关于.NET的文章,估计这10个人写的内容都是一样.但是如果说10个人写Java的文章,那真的是10个人10种写 ...

随机推荐

  1. jQuery插件autoComplete使用

    安装/需要引入的文件 <script type="text/javascript" src="../js/jquery-1.8.3.min.js.js"& ...

  2. ssm+jsp+自定义标签实现分页,可以通用(前端实现)

    近期做了一些分页方面的开发,大致梳理一下 1 jsp页面上关于分页的代码 <tr> <td colspan="9"> <ule1:pagination ...

  3. Microsoft.Practices.Unity 给不同的对象注入不同的Logger

    场景:我们做项目的时候常常会引用第三方日志框架来帮助我们记录日志,日志组件的用途主要是审计.跟踪.和调试.就说我最常用的日志组件log4net吧,这个在.NET同行当中应该算是用得非常多的一个日志组件 ...

  4. dom4j解析xml字符串

    import java.util.Iterator; import java.util.List; import org.dom4j.Document; import org.dom4j.Docume ...

  5. JSP(二)

    一.pageContext对象    1>代表当前JSP页面的运行环境, [作用域仅仅局限于当前JSP页面中,出了该JSP页面, 原PageContext域对象被销毁]    2>封装了对 ...

  6. 自定义Window进入和退出效果(转)

    看了android的源代码和资源文件,终于明白如何去修改设置Dialog和Activity的进入和退出效果了. 设置Dialog首先通过getWindow()方法获取它的窗口, 然后通过getAttr ...

  7. PSAM读卡芯片TDA8007BHL开发

    WWT:Work Waiting Time ATR:Answer To Reset,复位应答 etu =F/Df 1.     PSAM概述和应用 PSAM(PurchaseSecure Access ...

  8. windows下查看端口占用情况

    最近在用ICE做分布式应用 https://doc.zeroc.com/pages/viewpage.action?pageId=5048454 写了一个client 和server.server监听 ...

  9. SOSP 文档 - Windows Azure 存储:具有强一致性的高可用性云存储服务

    之前,我们在第 23 届 ACM操作系统原理研讨会 (SOSP)上发布了一篇文章,其中介绍了 Windows Azure存储的内部详细信息. 您可以在此处找到该文章.此次大会还发布了一段视频讲话( ...

  10. C#实现目录复制

     摘自:http://www.cnblogs.com/zxjay/archive/2008/10/29/1322517.html FCL提供了文件移动.文件复制.目录移动的方法,但没提供目录复制的 ...