最近刚开始接触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. windows下adb+flash_image刷机

    刷机是常事,总要把刷机包放在卡上,然后关机三键一起按到recovery再刷,觉得不爽,麻烦,所以研究出了adb调用flash_image刷system分区,全部脚本windows脚本执行,点点鼠标就o ...

  2. 基于异步的MVC webAPI控制器

    MVC – Task-based Asynchronous Pattern (TAP) – Async Controller and SessionLess Controller Leave a re ...

  3. universal image loader在listview/gridview中滚动时重复加载图片的问题及解决方法

    在listview/gridview中使用UIL来display每个item的图片,当图片数量较多需要滑动滚动时会出现卡顿,而且加载过的图片再次上翻后依然会重复加载(显示设置好的加载中图片) 最近在使 ...

  4. Activity被回收导致fragment的getActivity为null的解决办法

    这两天一直被这个问题困扰,假如app长时间在后台运行,再点击进入会crash,而且fragment页面有重叠现象,让我十分不爽.研究了一天,终于明白其中的原理并加以解决.解决办法如下: 如果系统内存不 ...

  5. Ushare应用

    Ushare应用 Openwrt 系统功能强大,主要优势在于其开放性和可扩展性,Openwrt 安装ushare后,可将路由器变身为一个功能强大的家庭upnp流媒体服务器! 打开网上邻居,会显示发现u ...

  6. cv:显示Linux命令运行进度

    cv: 显示 cp.mv 等命令的进度 2014-07-14 By toy Posted in Apps Edit on GitHub 在 Linux 系统中 , 大多数命令从来都是信奉 “ 沉默是金 ...

  7. cf445B DZY Loves Chemistry

    B. DZY Loves Chemistry time limit per test 1 second memory limit per test 256 megabytes input standa ...

  8. Go语言中的管道(Channel)总结

    管道(Channel)是Go语言中比较重要的部分,经常在Go中的并发中使用.今天尝试对Go语言的管道来做以下总结.总结的形式采用问答式的方法,让答案更有目的性. Q1.管道是什么? 管道是Go语言在语 ...

  9. [原创作品] Express 4.x 接收表单数据

    好久没有写博客,从现在开始,将介绍用nodejs进行web开发的介绍.欢迎加群讨论:164858883. 之前的express版本在接收表单数据时,可以统一用res.params['参数名'],但在4 ...

  10. 并发情况下synchronized死锁

    存在缺陷的代码: public class DataPropertyIdAndNameRepositoryImpl{ /** 发布标志 */ private volatile boolean publ ...